Skip to main content

A Python client for the Templafy API using openapi-python-client.

Project description

Templafy API Client

A Python client for the Templafy API using openapi-python-client for type-safe, modern Python API access.

Overview

This package provides a Python client for the Templafy API, allowing you to programmatically access templates, documents, images, and other assets in your Templafy workspace.

Installation

pip install -e .

Quick Start

Basic Usage

from templafy import AuthenticatedClient
from templafy.api import spaces, documents

# Initialize client
client = AuthenticatedClient(
    base_url="https://your-tenant.api.templafy.com/v3",
    token="your-api-token"
)

# Use with context manager (recommended)
with client as client:
    # List all spaces
    all_spaces = spaces.get_spaces(client=client)
    print(f"Found {len(all_spaces)} spaces")
    
    # List documents  
    all_documents = documents.get_documents(client=client)
    print(f"Found {len(all_documents)} documents")

Available API Endpoints

The client provides access to the following Templafy API resources:

  • Spaces - Workspace/tenant management
  • Libraries - Library management across spaces
  • Documents - Document template operations and generation
  • Folders - Folder structure management
  • Images - Image asset management
  • Slides - PowerPoint slide management
  • Spreadsheets - Excel template operations
  • Links - Link asset management

Models

The client includes type-safe models for all API resources:

from templafy import Space, Document, Library, Image

# Models are automatically used when calling API methods
spaces = spaces.get_spaces(client=client)
for space in spaces:
    print(f"Space: {space.name} (ID: {space.id})")

API Structure

templafy/
├── client.py           # Base Client and AuthenticatedClient classes
├── models/             # Type-safe models for all schemas
│   ├── space.py        # Space-related models
│   ├── document.py     # Document-related models
│   ├── library.py      # Library-related models
│   └── ...
├── api/                # API endpoint modules by resource
│   ├── spaces.py       # Spaces API endpoints
│   ├── documents.py    # Documents API endpoints
│   ├── libraries.py    # Libraries API endpoints
│   └── ...
├── types.py            # Common type definitions
└── errors.py           # Error classes and exceptions

Error Handling

The client provides specific error classes for different types of API errors:

from templafy.errors import (
    AuthenticationError,
    AuthorizationError, 
    NotFoundError,
    ValidationError,
    RateLimitError,
    ServerError
)

try:
    documents = documents.get_documents(client=client)
except AuthenticationError:
    print("API token is invalid")
except AuthorizationError:
    print("Insufficient permissions")
except NotFoundError:
    print("Resource not found")
except RateLimitError:
    print("Rate limit exceeded")

Development

Dependencies

This project requires Python 3.12+ and the following dependencies:

  • httpx - HTTP client
  • pydantic - Data validation and settings management
  • typing-extensions - Additional typing features

Testing

python -m pytest tests/ -v

Code Quality

The project uses ruff for linting and formatting:

ruff check src/templafy --fix
ruff format src/templafy

Contributing

  1. Install development dependencies
  2. Make your changes
  3. Run tests and linting
  4. Submit a pull request

License

MIT License - see LICENSE file 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

templafy-1.0.0.tar.gz (205.1 kB view details)

Uploaded Source

Built Distribution

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

templafy-1.0.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file templafy-1.0.0.tar.gz.

File metadata

  • Download URL: templafy-1.0.0.tar.gz
  • Upload date:
  • Size: 205.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.3

File hashes

Hashes for templafy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8dcbcca0c0c70beae67fbf9a19fb86a5ca68be25e48ede9e40576b3bc43d6328
MD5 42ca133f0f277f034a00465e772896a3
BLAKE2b-256 7602c60bca58e1af73946650ec477e366a6381e530e8650e869dbec2cb713729

See more details on using hashes here.

File details

Details for the file templafy-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: templafy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.3

File hashes

Hashes for templafy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 718c2f5a0f28f4acfd26235dfa2234540855b40a515a82b191fd64502c6d9485
MD5 329b3ba84ebb86893f86fa27e57a3daa
BLAKE2b-256 56bb4b46d8e2ec21ffcd4ee8cdba348daffb3aecf4a6e4351311d0597c404403

See more details on using hashes here.

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