Skip to main content

Official TemplateFox Python SDK - Generate PDFs from HTML templates

Project description

TemplateFox Python SDK

Official Python SDK for TemplateFox - Generate PDFs from HTML templates via API.

PyPI version License: MIT

Installation

pip install templatefox

Or with poetry:

poetry add templatefox

Quick Start

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}')

Features

  • Template-based PDF generation - Create templates with dynamic variables, generate PDFs with your data
  • Multiple export options - Get a signed URL (default) or raw binary PDF
  • S3 integration - Upload generated PDFs directly to your own S3-compatible storage
  • Type hints - Full type annotations for IDE support

API Methods

PDF Generation

from templatefox.models import CreatePdfRequest

# Generate PDF and get URL
response = api.create_pdf(
    CreatePdfRequest(
        template_id='TEMPLATE_ID',
        data={'name': 'John Doe'},
        export_type='url',       # 'url' or 'binary'
        expiration=86400,        # URL expiration in seconds (default: 24h)
        filename='invoice-001'   # Custom filename
    )
)

Templates

from templatefox.api import TemplatesApi

templates_api = TemplatesApi(client)

# List all templates
templates = templates_api.list_templates()
for template in templates.templates:
    print(f'{template.id}: {template.name}')

# Get template fields
fields = templates_api.get_template_fields(template_id='TEMPLATE_ID')
for field in fields:
    print(f'{field.key}: {field.type} (required: {field.required})')

Account

from templatefox.api import AccountApi

account_api = AccountApi(client)

# Get account info
account = account_api.get_account()
print(f'Credits: {account.credits}')
print(f'Email: {account.email}')

# List transactions
transactions = account_api.list_transactions(limit=100, offset=0)
for tx in transactions.transactions:
    print(f'{tx.transaction_type}: {tx.credits} credits')

S3 Integration

from templatefox.api import IntegrationsApi
from templatefox.models import S3ConfigRequest

integrations_api = IntegrationsApi(client)

# Save S3 configuration
integrations_api.save_s3_config(
    S3ConfigRequest(
        endpoint_url='https://s3.amazonaws.com',
        access_key_id='AKIAIOSFODNN7EXAMPLE',
        secret_access_key='your-secret-key',
        bucket_name='my-pdf-bucket',
        default_prefix='generated/pdfs/'
    )
)

# Test connection
test = integrations_api.test_s3_connection()
print(f'Connection: {"OK" if test.success else "Failed"}')

Configuration

from templatefox import Configuration

config = Configuration(
    host='https://api.templatefox.com',  # Default API URL
)
config.api_key['ApiKeyAuth'] = 'your-api-key'

# Or use environment variable
import os
config.api_key['ApiKeyAuth'] = os.environ.get('TEMPLATEFOX_API_KEY')

Error Handling

from templatefox.exceptions import ApiException

try:
    response = api.create_pdf(CreatePdfRequest(...))
except ApiException as e:
    if e.status == 402:
        print('Insufficient credits')
    elif e.status == 403:
        print('Access denied - check your API key')
    elif e.status == 404:
        print('Template not found')
    else:
        print(f'Error: {e.reason}')

Async Support

import asyncio
from templatefox import ApiClient, Configuration
from templatefox.api import PDFApi
from templatefox.models import CreatePdfRequest

async def generate_pdfs():
    config = Configuration()
    config.api_key['ApiKeyAuth'] = 'your-api-key'

    async with ApiClient(config) as client:
        api = PDFApi(client)
        # Use async methods
        response = await api.create_pdf(
            CreatePdfRequest(template_id='...', data={...})
        )

asyncio.run(generate_pdfs())

Documentation

Support

License

MIT License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

templatefox-1.10.0.tar.gz (50.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

templatefox-1.10.0-py3-none-any.whl (91.3 kB view details)

Uploaded Python 3

File details

Details for the file templatefox-1.10.0.tar.gz.

File metadata

  • Download URL: templatefox-1.10.0.tar.gz
  • Upload date:
  • Size: 50.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for templatefox-1.10.0.tar.gz
Algorithm Hash digest
SHA256 1307c62a24ea1aafdd49d36383cd6e647c6791b5fcecc52843f676571c7c9f28
MD5 7cca02ddc2c7e19d4332829fd7bcb2f6
BLAKE2b-256 64ea40a771c860359280931ab632c9ce30b689b23f5cf4315f1f405d1675b692

See more details on using hashes here.

Provenance

The following attestation bundles were made for templatefox-1.10.0.tar.gz:

Publisher: publish.yml on TemplateFoxPDF/pythonsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file templatefox-1.10.0-py3-none-any.whl.

File metadata

  • Download URL: templatefox-1.10.0-py3-none-any.whl
  • Upload date:
  • Size: 91.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for templatefox-1.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 985ad1e455e663f2c537400504e2d5ffff2ed5df6796dc05c42e9681475e1162
MD5 4aa8d960a4d99531f8a5e8aeefd3efb1
BLAKE2b-256 19884e4b7fc20b99bae5033bd6cc6a14fbad76383c5a13f4dfefffbfafd83dda

See more details on using hashes here.

Provenance

The following attestation bundles were made for templatefox-1.10.0-py3-none-any.whl:

Publisher: publish.yml on TemplateFoxPDF/pythonsdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page