Python
Official Python SDK for TemplateFox.
Installation
pip install templatefoxOr with poetry:
poetry add templatefoxGenerate a PDF
from templatefox import ApiClient, Configuration
from templatefox.api import PDFApi
from templatefox.models import CreatePdfRequest
# Initialize the client
config = Configuration()
config.api_key['ApiKeyAuth'] = 'your-api-key'
with ApiClient(config) as client:
api = PDFApi(client)
# Generate a PDF
response = api.create_pdf(
CreatePdfRequest(
template_id='YOUR_TEMPLATE_ID',
data={
'name': 'John Doe',
'invoice_number': 'INV-001',
'total_amount': 150.00,
}
)
)
print(f'PDF URL: {response.url}')
print(f'Credits remaining: {response.credits_remaining}')Save PDF to File
import urllib.request
response = api.create_pdf(
CreatePdfRequest(
template_id='YOUR_TEMPLATE_ID',
data={'name': 'Jane Doe', 'invoice_number': 'INV-042'}
)
)
# Download and save locally
urllib.request.urlretrieve(response.url, 'invoice.pdf')Error Handling
from templatefox.exceptions import ApiException
try:
response = api.create_pdf(
CreatePdfRequest(template_id='INVALID_ID', data={})
)
except ApiException as e:
print(f'Status: {e.status}')
print(f'Message: {e.body}')Available Methods
The SDK covers all TemplateFox API endpoints through four service classes:
| Class | Method | Description |
|---|---|---|
PDFApi | create_pdf | Generate a PDF from a template |
TemplatesApi | list_templates | List all templates in your team |
TemplatesApi | get_template_fields | Get data fields for a template |
AccountApi | get_account | Get account info and credit balance |
AccountApi | list_transactions | List credit transaction history |
IntegrationsApi | save_s3_config | Configure S3 storage integration |
IntegrationsApi | get_s3_config | Get current S3 configuration |
IntegrationsApi | delete_s3_config | Remove S3 configuration |
IntegrationsApi | test_s3_connection | Test S3 bucket connectivity |
Configuration
import os
from templatefox import Configuration
config = Configuration()
config.api_key['ApiKeyAuth'] = os.environ.get('TEMPLATEFOX_API_KEY')Quick Testing
Want to test the API before integrating the SDK? Use our Postman collection to try all endpoints interactively.
Full SDK Reference
For the complete API coverage including templates, account, S3 integration, and error handling, see the GitHub repository README .
Last updated on