Skip to Content

Python

Official Python SDK for TemplateFox.

PyPI version GitHub Repository 

Installation

pip install templatefox

Or with poetry:

poetry add templatefox

Generate 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:

ClassMethodDescription
PDFApicreate_pdfGenerate a PDF from a template
TemplatesApilist_templatesList all templates in your team
TemplatesApiget_template_fieldsGet data fields for a template
AccountApiget_accountGet account info and credit balance
AccountApilist_transactionsList credit transaction history
IntegrationsApisave_s3_configConfigure S3 storage integration
IntegrationsApiget_s3_configGet current S3 configuration
IntegrationsApidelete_s3_configRemove S3 configuration
IntegrationsApitest_s3_connectionTest 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