Skip to main content

Official Python SDK for Bannerify API - Generate images and PDFs at scale

Project description

Bannerify Python SDK

Official Python SDK for Bannerify - Generate images and PDFs at scale via API.

PyPI version Python versions

Installation

pip install bannerify

Or with uv:

uv add bannerify

Quick Start

from bannerify import BannerifyClient

# Create client with your API key
client = BannerifyClient("your-api-key")

# Generate an image
result = client.create_image(
    "tpl_xxxxxxxxx",
    modifications=[
        {"name": "title", "text": "Hello World"},
        {"name": "subtitle", "text": "From Python SDK"}
    ]
)

if "result" in result:
    with open("output.png", "wb") as f:
        f.write(result["result"])
    print("Image created successfully!")
else:
    print(f"Error: {result['error']['message']}")

Features

  • 🚀 Simple, intuitive API
  • 🔒 Type-safe with full type hints
  • ⚡ Built on httpx for performance
  • 🎯 Result/Error pattern for explicit error handling
  • 📝 Comprehensive documentation
  • ✅ Well-tested

Usage

Creating Images

# Generate PNG
result = client.create_image(
    "tpl_xxxxxxxxx",
    modifications=[
        {"name": "title", "text": "My Title"},
        {"name": "image", "src": "https://example.com/image.jpg"}
    ]
)

# Generate SVG
result = client.create_image(
    "tpl_xxxxxxxxx",
    format="svg",
    modifications=[{"name": "title", "text": "My Title"}]
)

# Generate thumbnail
result = client.create_image("tpl_xxxxxxxxx", thumbnail=True)

Creating PDFs

result = client.create_pdf(
    "tpl_xxxxxxxxx",
    modifications=[{"name": "title", "text": "Invoice #123"}]
)

if "result" in result:
    with open("invoice.pdf", "wb") as f:
        f.write(result["result"])

Generating Signed URLs

signed_url = client.generate_image_signed_url(
    "tpl_xxxxxxxxx",
    modifications=[{"name": "title", "text": "Dynamic Title"}],
    format="png"
)

# Use in HTML
print(f"<img src='{signed_url}' alt='Generated Image' />")

Error Handling

result = client.create_image("tpl_xxxxxxxxx")

if "error" in result:
    error = result["error"]
    print(f"Error Code: {error['code']}")
    print(f"Message: {error['message']}")
    print(f"Docs: {error['docs']}")
else:
    # Process result
    image_data = result["result"]

Context Manager

with BannerifyClient("your-api-key") as client:
    result = client.create_image("tpl_xxxxxxxxx")
    # Client is automatically closed

API Reference

BannerifyClient

BannerifyClient(
    api_key: str,
    base_url: str = "https://api.bannerify.co/v1",
    timeout: float = 60.0
)

create_image

client.create_image(
    template_id: str,
    modifications: Optional[List[Dict[str, Any]]] = None,
    format: str = "png",
    thumbnail: bool = False
) -> Dict[str, Any]

create_pdf

client.create_pdf(
    template_id: str,
    modifications: Optional[List[Dict[str, Any]]] = None
) -> Dict[str, Any]

create_stored_image

client.create_stored_image(
    template_id: str,
    modifications: Optional[List[Dict[str, Any]]] = None,
    format: str = "png",
    thumbnail: bool = False
) -> Dict[str, Any]

generate_image_signed_url

client.generate_image_signed_url(
    template_id: str,
    modifications: Optional[List[Dict[str, Any]]] = None,
    format: str = "png",
    thumbnail: bool = False,
    nocache: bool = False
) -> str

Examples

Generate Multiple Images

products = [
    {"name": "Product A", "price": "$29.99"},
    {"name": "Product B", "price": "$39.99"},
]

for i, product in enumerate(products):
    result = client.create_image(
        "tpl_product_banner",
        modifications=[
            {"name": "product_name", "text": product["name"]},
            {"name": "price", "text": product["price"]}
        ]
    )
    
    if "result" in result:
        with open(f"banner_{i}.png", "wb") as f:
            f.write(result["result"])

Email Campaigns

for recipient in recipients:
    signed_url = client.generate_image_signed_url(
        "tpl_email_header",
        modifications=[{"name": "name", "text": f"Hi, {recipient['name']}!"}]
    )
    # Use signed_url in email HTML

Development

# Install dependencies
uv sync

# Run tests
uv run pytest

# Type checking
uv run mypy src/

# Format code
uv run ruff format src/

Documentation

Full documentation available at https://bannerify.co/docs/sdk/python/overview

Support

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

bannerify-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

bannerify-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file bannerify-0.1.0.tar.gz.

File metadata

  • Download URL: bannerify-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.23

File hashes

Hashes for bannerify-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2d7f63ecea7dce7082b6f661e3368e4766b1bac5feb95f32ef6af0da9758198a
MD5 26cac0404620461441748fe46dfebfa8
BLAKE2b-256 1f3a3eb3c558566a96889edb5f5dc6eb298c08f9e7561f7d555eef5ed9851310

See more details on using hashes here.

File details

Details for the file bannerify-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bannerify-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.23

File hashes

Hashes for bannerify-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5161f8dfbba83ae46b796c0f07f5cce68edcaf14bc4413489f10ae1aa63e165a
MD5 a768242f274b0e56e97d92884bb70240
BLAKE2b-256 d5500d70123c1ded342ebe82f53de029102e053c0ea2c401b96ba61b0dbdda48

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