Full-featured Python SDK with sync and async support, type hints, and automatic retries.
pip install butterflyapifrom butterflyapi import ButterflyAPI
client = ButterflyAPI(api_key="your_api_key_here")
# Cartoonify an image
result = client.cartoon(
image_url="https://your-bucket.s3.amazonaws.com/photo.jpg",
style="pixar"
)
print(f"Result: {result.output_url}")import asyncio
from butterflyapi import AsyncButterflyAPI
async def main():
client = AsyncButterflyAPI(api_key="your_api_key")
result = await client.cartoon(
image_url="https://your-bucket.s3.amazonaws.com/photo.jpg",
style="anime"
)
print(f"Result: {result.output_url}")
asyncio.run(main())client.cartoon() - Convert images to cartoon stylesclient.image_to_image() - Transform images with AIclient.background_remove() - Remove backgroundsclient.upscale() - Upscale imagesclient.enhance() - Enhance qualityclient.face_restore() - Restore facesclient.watermark() - Add watermarksclient.text_to_image() - Generate imagesclient.image_caption() - Generate captionsclient.video_generate() - Generate videosclient.cineflow_director() - Advanced video generationclient.html_to_pdf() - Convert HTML to PDFfrom butterflyapi import ButterflyAPI, ButterflyAPIError, InsufficientCreditsError
client = ButterflyAPI(api_key="your_api_key")
try:
result = client.cartoon(
image_url="https://your-bucket.s3.amazonaws.com/photo.jpg",
style="anime"
)
except InsufficientCreditsError:
print("Not enough credits")
except ButterflyAPIError as e:
print(f"API error: {e.message}")# replaced example.com with placeholder URLs
images = [
"https://your-bucket.s3.amazonaws.com/photo1.jpg",
"https://your-bucket.s3.amazonaws.com/photo2.jpg",
"https://your-bucket.s3.amazonaws.com/photo3.jpg"
]
results = client.batch_cartoon(
images=images,
style="pixar",
max_concurrent=3
)
for result in results:
print(f"Processed: {result.output_url}")# Submit video generation job
job = client.video_generate(
prompt="A cat playing piano",
duration="5s",
tier="standard"
)
# Wait for completion
result = client.wait_for_job(
job_id=job.job_id,
timeout=300, # 5 minutes
poll_interval=5 # Check every 5 seconds
)
print(f"Video ready: {result.output_url}")client = ButterflyAPI(
api_key="your_api_key",
base_url="https://butterflyapi.com/api/v1",
timeout=30,
max_retries=3,
webhook_url="https://yoursite.com/webhook"
)butterflyapi