How to Sign PDFs with Python
To sign a PDF with Python: Install the TurboDocx SDK (pip install turbodocx-sdk), configure your API key, and call TurboSign.send_signature() with your document and recipient details.
This guide shows you how to integrate e-signatures into your Django, FastAPI, or Flask application in under 5 minutes.
5 min
Setup time
Python 3.8+
Type hints included
Async/Sync
Both supported
Installation
Install the TurboDocx SDK from PyPI. The package includes full type hints for IDE support.
pip install turbodocx-sdkRequirements: Python 3.8+. For async support, use TurboSign. For sync, use TurboSignSync.
Obtaining an API Key
Before you begin, you'll need your API credentials from the TurboDocx dashboard.
- Sign up for a free account at TurboDocx
- Navigate to Settings → API Keys
- Copy your API Key and Organization ID
TURBODOCX_API_KEY=your_api_key_here
TURBODOCX_ORG_ID=your_org_id_here
TURBODOCX_SENDER_EMAIL=you@company.com
TURBODOCX_SENDER_NAME=Your Company NameSending a Signing Request
Use the SDK to send a document for signature. The recipient will receive an email with a link to sign.
import asyncio
import os
from turbodocx_sdk import TurboSign
async def main():
# Configure with your API credentials
TurboSign.configure(
api_key=os.getenv("TURBODOCX_API_KEY"),
org_id=os.getenv("TURBODOCX_ORG_ID"),
sender_email=os.getenv("TURBODOCX_SENDER_EMAIL"), # REQUIRED
sender_name=os.getenv("TURBODOCX_SENDER_NAME") # Recommended
)
# Read PDF file
with open("contract.pdf", "rb") as f:
pdf_file = f.read()
# Send document for signature
result = await TurboSign.send_signature(
file=pdf_file,
document_name="Partnership Agreement",
recipients=[
{"name": "John Doe", "email": "john@example.com", "signingOrder": 1}
],
fields=[
{
"type": "signature",
"recipientEmail": "john@example.com",
"template": {
"anchor": "{signature1}",
"placement": "replace",
"size": {"width": 100, "height": 30}
}
}
]
)
print(f"Document ID: {result['documentId']}")
asyncio.run(main())Tip: For synchronous code, use TurboSignSync instead of TurboSign.
Processing Results with Webhooks
Configure webhooks to receive real-time notifications when documents are signed.
from fastapi import FastAPI, Request
from turbodocx_sdk import TurboSign
app = FastAPI()
@app.post("/webhooks/turbosign")
async def handle_webhook(request: Request):
payload = await request.json()
event_type = payload.get("event_type")
data = payload.get("data")
if event_type == "document.completed":
print(f"Document signed: {data['documentId']}")
# Download the signed PDF
signed_pdf = await TurboSign.download(data["documentId"])
# Save to your storage
with open(f"signed-{data['documentId']}.pdf", "wb") as f:
f.write(signed_pdf)
return {"received": True}Conclusion
You now have everything you need to integrate document signing into your Python application. The TurboDocx SDK handles authentication, document delivery, signature collection, and provides legally-binding audit trails.
What you can do next:
- Add multiple recipients with sequential signing order
- Use different field types: initials, dates, text, checkboxes
- Integrate with Django REST Framework or FastAPI
- Get audit trails and compliance certificates
Related Guides
Resources
Frequently Asked Questions
How do I sign a PDF with Python?
Install the TurboDocx SDK (pip install turbodocx-sdk), configure it with your API key, then use TurboSign.send_signature() to send the document for e-signature.
Does the Python SDK support async/await?
Yes, the TurboDocx Python SDK is fully async-native and works with asyncio, FastAPI, and other async frameworks.
What Python version is required?
The TurboDocx Python SDK requires Python 3.8 or higher.
Ready to Get Started?
Create a free account and get your API key. Start sending documents for signature in minutes.