Skip to main content

Python SDK

The official TurboDocx SDK for Python applications. Build document generation and digital signature workflows with async/await patterns and comprehensive error handling. Available on PyPI as turbodocx-sdk.

Installation

pip install turbodocx-sdk

Requirements

  • Python 3.8+
  • httpx (installed automatically)
  • pydantic (installed automatically)

Configuration

from turbodocx_sdk import TurboSign
import os

# Configure globally (recommended)
TurboSign.configure(
api_key=os.environ["TURBODOCX_API_KEY"], # Required: Your TurboDocx API key
org_id=os.environ["TURBODOCX_ORG_ID"], # Required: Your organization ID
# base_url="https://api.turbodocx.com" # Optional: Override base URL
)
Authentication

Authenticate using api_key. API keys are recommended for server-side applications.

Environment Variables

# .env
TURBODOCX_API_KEY=your_api_key_here
TURBODOCX_ORG_ID=your_org_id_here
API Credentials Required

Both api_key and org_id parameters are required for all API requests. To get your credentials, follow the Get Your Credentials steps from the SDKs main page.


Quick Start

Send a Document for Signature

import asyncio
from turbodocx_sdk import TurboSign
import os

TurboSign.configure(
api_key=os.environ["TURBODOCX_API_KEY"],
org_id=os.environ["TURBODOCX_ORG_ID"]
)

async def send_contract():
result = await TurboSign.send_signature(
recipients=[
{"name": "Alice Smith", "email": "alice@example.com", "signingOrder": 1},
{"name": "Bob Johnson", "email": "bob@example.com", "signingOrder": 2}
],
fields=[
# Alice's signature
{"type": "signature", "page": 1, "x": 100, "y": 650, "width": 200, "height": 50, "recipientEmail": "alice@example.com"},
{"type": "date", "page": 1, "x": 320, "y": 650, "width": 100, "height": 30, "recipientEmail": "alice@example.com"},
# Bob's signature
{"type": "signature", "page": 1, "x": 100, "y": 720, "width": 200, "height": 50, "recipientEmail": "bob@example.com"},
{"type": "date", "page": 1, "x": 320, "y": 720, "width": 100, "height": 30, "recipientEmail": "bob@example.com"}
],
file_link="https://example.com/contract.pdf",
document_name="Service Agreement",
sender_name="Acme Corp",
sender_email="contracts@acme.com",
)

print("Result:", json.dumps(result, indent=2))

asyncio.run(send_contract())

Using Template-Based Fields

result = await TurboSign.send_signature(
recipients=[{"name": "Alice Smith", "email": "alice@example.com", "signingOrder": 1}],
fields=[
{
"type": "signature",
"recipientEmail": "alice@example.com",
"template": {
"anchor": "{SIGNATURE_ALICE}",
"placement": "replace",
"size": {"width": 200, "height": 50},
},
},
{
"type": "date",
"recipientEmail": "alice@example.com",
"template": {
"anchor": "{DATE_ALICE}",
"placement": "replace",
"size": {"width": 100, "height": 30},
},
},
],
file_link="https://example.com/contract-with-placeholders.pdf",
)

print("Result:", json.dumps(result, indent=2))
Template Anchors Required

Important: The document file must contain the anchor text (e.g., {SIGNATURE_ALICE}, {DATE_ALICE}) that you reference in your fields. If the anchors don't exist in the document, the API will return an error.


File Input Methods

TurboSign supports four different ways to provide document files:

1. File Upload (bytes)

with open("./contract.pdf", "rb") as f:
pdf_buffer = f.read()

result = await TurboSign.send_signature(
file=pdf_buffer,
recipients=[
{"name": "John Doe", "email": "john@example.com", "signingOrder": 1},
],
fields=[
{
"type": "signature",
"page": 1,
"x": 100,
"y": 650,
"width": 200,
"height": 50,
"recipientEmail": "john@example.com",
},
],
)
result = await TurboSign.send_signature(
file_link="https://storage.example.com/contracts/agreement.pdf",
recipients=[
{"name": "John Doe", "email": "john@example.com", "signingOrder": 1},
],
fields=[
{
"type": "signature",
"page": 1,
"x": 100,
"y": 650,
"width": 200,
"height": 50,
"recipientEmail": "john@example.com",
},
],
)
When to use file_link

Use file_link when your documents are already hosted on cloud storage (S3, Google Cloud Storage, etc.). This is more efficient than downloading and re-uploading files.

3. TurboDocx Deliverable ID

# Use a previously generated TurboDocx document
result = await TurboSign.send_signature(
deliverable_id="deliverable-uuid-from-turbodocx",
recipients=[
{"name": "John Doe", "email": "john@example.com", "signingOrder": 1},
],
fields=[
{
"type": "signature",
"page": 1,
"x": 100,
"y": 650,
"width": 200,
"height": 50,
"recipientEmail": "john@example.com",
},
],
)
Integration with TurboDocx

deliverable_id references documents generated using TurboDocx's document generation API. This creates a seamless workflow: generate → sign.

4. TurboDocx Template ID

# Use a pre-configured TurboSign template
result = await TurboSign.send_signature(
template_id="template-uuid-from-turbodocx", # Template already contains anchors
recipients=[
{"name": "Alice Smith", "email": "alice@example.com", "signingOrder": 1},
],
fields=[
{
"type": "signature",
"recipientEmail": "alice@example.com",
"template": {
"anchor": "{SIGNATURE_ALICE}",
"placement": "replace",
"size": {"width": 200, "height": 50},
},
},
],
)
Integration with TurboDocx

template_id references pre-configured TurboSign templates created in the TurboDocx dashboard. These templates come with built-in anchors and field positioning, making it easy to reuse signature workflows across multiple documents.


API Reference

Configure

Configure the SDK with your API credentials and organization settings.

TurboSign.configure(
api_key: str, # Required: Your TurboDocx API key
org_id: str, # Required: Your organization ID
base_url: str = "https://api.turbodocx.com" # Optional: API base URL
)

Prepare for review

Upload a document for preview without sending signature request emails.

result = await TurboSign.create_signature_review_link(
recipients=[{"name": "John Doe", "email": "john@example.com", "signingOrder": 1}],
fields=[{"type": "signature", "page": 1, "x": 100, "y": 500, "width": 200, "height": 50, "recipientEmail": "john@example.com"}],
file_link="https://example.com/document.pdf",
document_name="Contract Draft",
)

print(result["documentId"])
print(result["previewUrl"])

Prepare for signing

Upload a document and immediately send signature requests to all recipients.

result = await TurboSign.send_signature(
recipients=[{"name": "Recipient Name", "email": "recipient@example.com", "signingOrder": 1}],
fields=[{"type": "signature", "page": 1, "x": 100, "y": 500, "width": 200, "height": 50, "recipientEmail": "recipient@example.com"}],
file_link="https://example.com/document.pdf",
document_name="Service Agreement",
sender_name="Your Company",
sender_email="sender@company.com",
)

print(result["documentId"])

Get status

Retrieve the current status of a document.

result = await TurboSign.get_status("document-uuid")

print("Result:", json.dumps(result, indent=2))

Download document

Download the completed signed document as PDF bytes.

pdf_bytes = await TurboSign.download("document-uuid")

# Save to file
with open("signed-contract.pdf", "wb") as f:
f.write(pdf_bytes)

Void

Cancel/void a signature request.

result = await TurboSign.void_document("document-uuid", reason="Contract terms changed")

Resend

Resend signature request emails to specific recipients.

result = await TurboSign.resend_email("document-uuid", recipient_ids=["recipient-uuid-1", "recipient-uuid-2"])

Get audit trail

Retrieve the complete audit trail for a document, including all events and actions.

result = await TurboSign.get_audit_trail("document-uuid")

print("Result:", json.dumps(result, indent=2))

Error Handling

The SDK provides typed error classes for different failure scenarios. All errors extend the base TurboDocxError class.

Error Classes

Error ClassStatus CodeDescription
TurboDocxErrorvariesBase error class for all SDK errors
AuthenticationError401Invalid or missing API credentials
ValidationError400Invalid request parameters
NotFoundError404Document or resource not found
RateLimitError429Too many requests
NetworkError-Network connectivity issues

Handling Errors

from turbodocx_sdk import (
TurboSign,
TurboDocxError,
AuthenticationError,
ValidationError,
NotFoundError,
RateLimitError,
NetworkError,
)

try:
result = await TurboSign.send_signature(
recipients=[{"name": "John Doe", "email": "john@example.com", "signingOrder": 1}],
fields=[{
"type": "signature",
"page": 1,
"x": 100,
"y": 650,
"width": 200,
"height": 50,
"recipientEmail": "john@example.com",
}],
file_link="https://example.com/contract.pdf",
)
except AuthenticationError as e:
print(f"Authentication failed: {e}")
# Check your API key and org ID
except ValidationError as e:
print(f"Validation error: {e}")
# Check request parameters
except NotFoundError as e:
print(f"Resource not found: {e}")
# Document or recipient doesn't exist
except RateLimitError as e:
print(f"Rate limited: {e}")
# Wait and retry
except NetworkError as e:
print(f"Network error: {e}")
# Check connectivity
except TurboDocxError as e:
print(f"SDK error: {e}, status_code={e.status_code}, code={e.code}")

Error Properties

All errors include these properties:

PropertyTypeDescription
messagestrHuman-readable error description (via str(error))
status_codeint \| NoneHTTP status code (if applicable)
codestr \| NoneMachine-readable error code

Python Types

The SDK uses Python type hints with Dict[str, Any] for flexible JSON-like structures.

Importing Types

from typing import Dict, List, Any, Optional

SignatureFieldType

String literal values for field types:

# Available field type values
field_types = [
"signature",
"initial",
"date",
"text",
"full_name",
"title",
"company",
"first_name",
"last_name",
"email",
"checkbox",
]

Recipient

Recipient configuration for signature requests:

PropertyTypeRequiredDescription
namestrYesRecipient's full name
emailstrYesRecipient's email address
signingOrderintYesSigning order (1-indexed)
recipient: Dict[str, Any] = {
"name": "John Doe",
"email": "john@example.com",
"signingOrder": 1
}

Field

Field configuration supporting both coordinate-based and template-based positioning:

PropertyTypeRequiredDescription
typestrYesField type (see SignatureFieldType)
recipientEmailstrYesWhich recipient fills this field
pageintNo*Page number (1-indexed)
xintNo*X coordinate in pixels
yintNo*Y coordinate in pixels
widthintNo*Field width in pixels
heightintNo*Field height in pixels
defaultValuestrNoDefault value (for checkbox: "true" or "false")
isMultilineboolNoEnable multiline text
isReadonlyboolNoMake field read-only (pre-filled)
requiredboolNoWhether field is required
backgroundColorstrNoBackground color (hex, rgb, or named)
templateDictNoTemplate anchor configuration

*Required when not using template anchors

Template Configuration:

PropertyTypeRequiredDescription
anchorstrYesText anchor pattern like {TagName}
placementstrYes"replace" | "before" | "after" | "above" | "below"
sizeDictYes{ "width": int, "height": int }
offsetDictNo{ "x": int, "y": int }
caseSensitiveboolNoCase sensitive search (default: False)
useRegexboolNoUse regex for anchor/searchText (default: False)
field: Dict[str, Any] = {
"type": "signature",
"page": 1,
"x": 100,
"y": 500,
"width": 200,
"height": 50,
"recipientEmail": "john@example.com"
}

Request Parameters

Request configuration for create_signature_review_link and send_signature methods:

ParameterTypeRequiredDescription
recipientsList[Dict]YesRecipients who will sign
fieldsList[Dict]YesSignature fields configuration
filebytesConditionalPDF file content as bytes
file_linkstrConditionalURL to document file
deliverable_idstrConditionalTurboDocx deliverable ID
template_idstrConditionalTurboDocx template ID
document_namestrNoDocument name
document_descriptionstrNoDocument description
sender_namestrNoSender name
sender_emailstrNoSender email
cc_emailsList[str]NoArray of CC email addresses
File Source (Conditional)

Exactly one file source is required: file, file_link, deliverable_id, or template_id.


Additional Documentation

For detailed information about advanced configuration and API concepts, see:

Core API References


Resources