Python SDK
+ Pictify
Official Python library for data science and backend applications.
About Integration
The Pictify Python SDK enables image generation from Python applications, notebooks, and scripts. Perfect for data science workflows, Django/Flask backends, and automation scripts.
Key Capabilities
Async support
Type hints
Pandas integration
Jupyter-friendly
Common Use Cases
Django/Flask backends
Data visualization exports
Jupyter notebooks
Batch scripts
Integration Guide
Prerequisites
- Python 3.8 or higher
- A Pictify account with an API key
- A template created in Pictify
Install the SDK
Install the Pictify package using pip.
# Using pip
pip install pictify
# Using poetry
poetry add pictify
# Using pipenv
pipenv install pictifyInitialize the Client
Create a Pictify client with your API key. Use environment variables to keep credentials secure.
import os
from pictify import Pictify
# Initialize with API key from environment
client = Pictify(api_key=os.environ.get('PICTIFY_API_KEY'))
# Or pass directly (not recommended for production)
client = Pictify(api_key='your-api-key')Set your API key with: export PICTIFY_API_KEY=your-key
Generate an Image
Use the render method to generate images from your templates.
result = client.render(
template_id='your-template-id',
variables={
'title': 'Hello from Python',
'subtitle': 'Generated with the Pictify SDK',
'accent_color': '#667eea'
},
format='png',
width=1200,
height=630
)
print(f"Image URL: {result.image_url}")
# https://cdn.pictify.io/renders/abc123.pngDownload Image Locally
Save the generated image to your local filesystem.
# Download as bytes
image_bytes = client.render(
template_id='your-template-id',
variables={'title': 'Download Test'},
download=True
)
# Save to file
with open('output.png', 'wb') as f:
f.write(image_bytes)
# Or use the convenience method
client.render_to_file(
template_id='your-template-id',
variables={'title': 'Save Test'},
output_path='my-image.png'
)Batch Processing with Pandas
Generate images from a DataFrame—perfect for data science workflows.
import pandas as pd
# Load your data
df = pd.read_csv('products.csv')
# Generate images for each row
results = client.render_batch(
template_id='product-card-template',
items=[
{
'variables': {
'name': row['product_name'],
'price': f"$" + "{row['price']:.2f}",
'image': row['image_url']
}
}
for _, row in df.iterrows()
]
)
# Add image URLs back to DataFrame
df['generated_image'] = [r.image_url for r in results]
df.to_csv('products_with_images.csv', index=False)For large datasets, process in chunks to avoid memory issues.
Async Support
Use async/await for non-blocking image generation in async applications.
import asyncio
from pictify import AsyncPictify
async def generate_images():
client = AsyncPictify(api_key=os.environ.get('PICTIFY_API_KEY'))
# Generate multiple images concurrently
tasks = [
client.render(
template_id='your-template-id',
variables={'title': f'Image {i}'}
)
for i in range(10)
]
results = await asyncio.gather(*tasks)
for i, result in enumerate(results):
print(f"Image {i}: {result.image_url}")
await client.close()
asyncio.run(generate_images())Always close the async client when done to release connections.
Display in Jupyter Notebook
Display generated images directly in Jupyter notebooks.
from IPython.display import Image, display
result = client.render(
template_id='your-template-id',
variables={'title': 'Notebook Demo'}
)
# Display from URL
display(Image(url=result.image_url))
# Or display from bytes
image_bytes = client.render(
template_id='your-template-id',
variables={'title': 'Direct Display'},
download=True
)
display(Image(data=image_bytes))Fast Install
Ready to build with Python SDK?
Get your API key in seconds and start generating images programmatically.