Skip to main content

Python SDK

The official TurboDocx Deliverable SDK for Python applications. Generate documents from templates with dynamic variable injection, download source files and PDFs, and manage deliverables programmatically 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 Deliverable
import os

# Configure globally (recommended)
Deliverable.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
)
No Sender Email Required

Unlike TurboSign, the Deliverable module only requires api_key and org_id — no sender email or name is needed.

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

Generate a document from a template

import asyncio
from turbodocx_sdk import Deliverable
import os

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

async def generate_report():
# Generate a document from a template with variables
result = await Deliverable.generate_deliverable(
name="Q1 Report",
template_id="your-template-id",
variables=[
{"placeholder": "{CompanyName}", "text": "Acme Corporation", "mimeType": "text"},
{"placeholder": "{Date}", "text": "2026-03-12", "mimeType": "text"},
],
description="Quarterly business report",
tags=["reports", "quarterly"],
)

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

asyncio.run(generate_report())

Download and manage deliverables

import asyncio
from turbodocx_sdk import Deliverable
import os

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

async def manage_deliverables():
# List deliverables with pagination
items = await Deliverable.list_deliverables(limit=10, show_tags=True)
print(f"Total: {items['totalRecords']}")

# Get deliverable details
details = await Deliverable.get_deliverable_details("deliverable-uuid")
print(f"Name: {details['name']}")

# Download source file (DOCX/PPTX)
source_bytes = await Deliverable.download_source_file("deliverable-uuid")
with open("report.docx", "wb") as f:
f.write(source_bytes)

# Download PDF
pdf_bytes = await Deliverable.download_pdf("deliverable-uuid")
with open("report.pdf", "wb") as f:
f.write(pdf_bytes)

# Update deliverable
await Deliverable.update_deliverable_info(
"deliverable-uuid",
name="Q1 Report - Final",
description="Final quarterly business report",
)

# Delete deliverable
await Deliverable.delete_deliverable("deliverable-uuid")

asyncio.run(manage_deliverables())

Variable Types

The Deliverable module supports four variable types for template injection:

1. Text Variables

Inject plain text values into template placeholders:

variables = [
{"placeholder": "{CompanyName}", "text": "Acme Corporation", "mimeType": "text"},
{"placeholder": "{Date}", "text": "2026-03-12", "mimeType": "text"},
]

2. HTML Variables

Inject rich HTML content with formatting:

variables = [
{
"placeholder": "{Summary}",
"text": "<p>This is a <strong>formatted</strong> summary with <em>rich text</em>.</p>",
"mimeType": "html",
},
]

3. Image Variables

Inject images by providing a URL or base64-encoded content:

variables = [
{
"placeholder": "{Logo}",
"text": "https://example.com/logo.png",
"mimeType": "image",
},
]

4. Markdown Variables

Inject markdown content that gets converted to formatted text:

variables = [
{
"placeholder": "{Notes}",
"text": "## Key Points\n- First item\n- Second item\n\n**Important:** Review before submission.",
"mimeType": "markdown",
},
]
Variable Stack

For repeating content (e.g., table rows), use variableStack instead of text to provide multiple values for the same placeholder. See the Types section for details.


API Reference

Configure

Configure the SDK with your API credentials and organization settings.

Deliverable.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
)
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.

Generate deliverable

Generate a new document from a template with variable substitution.

result = await Deliverable.generate_deliverable(
name="Q1 Report",
template_id="your-template-id",
variables=[
{"placeholder": "{CompanyName}", "text": "Acme Corp", "mimeType": "text"},
{"placeholder": "{Date}", "text": "2026-03-12", "mimeType": "text"},
],
description="Quarterly business report",
tags=["reports", "quarterly"],
)

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

List deliverables

List deliverables with pagination, search, and filtering.

items = await Deliverable.list_deliverables(
limit=10,
offset=0,
query="report",
show_tags=True,
)

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

Get deliverable details

Retrieve the full details of a single deliverable, including variables and fonts.

details = await Deliverable.get_deliverable_details("deliverable-uuid", show_tags=True)

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

Update deliverable info

Update a deliverable's name, description, or tags.

result = await Deliverable.update_deliverable_info(
"deliverable-uuid",
name="Q1 Report - Final",
description="Final quarterly business report",
tags=["reports", "final"],
)

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

Delete deliverable

Soft-delete a deliverable.

result = await Deliverable.delete_deliverable("deliverable-uuid")

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

Download source file

Download the original source file (DOCX or PPTX).

source_bytes = await Deliverable.download_source_file("deliverable-uuid")

# Save to file
with open("report.docx", "wb") as f:
f.write(source_bytes)

Download PDF

Download the PDF version of a deliverable.

pdf_bytes = await Deliverable.download_pdf("deliverable-uuid")

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

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
NotFoundError404Deliverable or template not found
RateLimitError429Too many requests
NetworkError-Network connectivity issues

Handling Errors

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

try:
result = await Deliverable.generate_deliverable(
name="Q1 Report",
template_id="your-template-id",
variables=[
{"placeholder": "{CompanyName}", "text": "Acme Corp", "mimeType": "text"},
],
)
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}")
# Template or deliverable 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

DeliverableVariable

Variable configuration for template injection:

PropertyTypeRequiredDescription
placeholderstrYesTemplate placeholder (e.g., {CompanyName})
textstrNo*Value to inject
mimeTypestrYes"text", "html", "image", or "markdown"
isDisabledboolNoSkip this variable during generation
subvariableslist[dict]NoNested sub-variables for HTML content
variableStackdict \| listNoMultiple instances for repeating content
aiPromptstrNoAI prompt for content generation (max 16,000 chars)

*Required unless variableStack is provided or isDisabled is true.

CreateDeliverableRequest

Request configuration for generate_deliverable:

PropertyTypeRequiredDescription
namestrYesDeliverable name (3-255 characters)
template_idstrYesTemplate ID to generate from
variableslist[dict]YesVariables for template substitution
descriptionstrNoDescription (up to 65,535 characters)
tagslist[str]NoTag strings to associate

UpdateDeliverableRequest

Request configuration for update_deliverable_info:

PropertyTypeRequiredDescription
namestrNoUpdated name (3-255 characters)
descriptionstrNoUpdated description
tagslist[str]NoReplace all tags (empty list to remove)

ListDeliverablesOptions

Options for list_deliverables:

PropertyTypeRequiredDescription
limitintNoResults per page (1-100, default 6)
offsetintNoResults to skip (default 0)
querystrNoSearch query to filter by name
show_tagsboolNoInclude tags in the response

DeliverableRecord

The deliverable object returned by list_deliverables:

PropertyTypeDescription
idstrUnique deliverable ID (UUID)
namestrDeliverable name
descriptionstrDescription text
templateIdstrSource template ID
createdBystrUser ID of the creator
emailstrCreator's email address
fileSizeintFile size in bytes
fileTypestrMIME type of the generated file
defaultFontstrDefault font used
fontslistFonts used in the document
isActiveboolWhether the deliverable is active
createdOnstrISO 8601 creation timestamp
updatedOnstrISO 8601 last update timestamp
tagslistAssociated tags (when show_tags=True)

DeliverableDetailRecord

The deliverable object returned by get_deliverable_details. Includes all fields from DeliverableRecord except fileSize, plus:

PropertyTypeDescription
templateNamestrSource template name
templateNotDeletedboolWhether the source template still exists
variableslist[dict]Parsed variable objects with values

Tag

Tag object included when show_tags is enabled. Each tag is a dict with:

KeyTypeDescription
idstrTag unique identifier (UUID)
labelstrTag display name
isActiveboolWhether the tag is active
updatedOnstrISO 8601 last update timestamp
createdOnstrISO 8601 creation timestamp
createdBystrUser ID of the tag creator
orgIdstrOrganization ID

Additional Documentation

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

Core API References


Resources