Async image processing for FastAPI, Django, & Flask
Modern async Python client powered by httpx and Pillow fallbacks. Easily optimize media uploads in Django models, FastAPI endpoints, or background Celery / RQ workers.
Install
$ pip install smallpictImplementation example
# FastAPI / Async Python Example
from fastapi import FastAPI, UploadFile, File
from smallpict import AsyncSmallPictClient, ImageFormat
app = FastAPI()
client = AsyncSmallPictClient(api_key="sp_live_key_xxxxx")
@app.post("/api/upload")
async def upload_image(file: UploadFile = File(...)):
image_bytes = await file.read()
result = await client.optimize(
image_bytes,
format=ImageFormat.AVIF,
quality=80,
max_width=1400
)
return {
"cdn_url": result.cdn_url,
"savings": f"{result.savings_percentage}%",
"original_size": result.original_size,
"optimized_size": result.new_size
}Integration steps
pip install smallpict
Install the official package from PyPI.
Initialize client
Use SmallPictClient for sync apps or AsyncSmallPictClient for ASGI frameworks.
Plug into Upload Handlers
Wrap Django FileField or FastAPI file streams with client.optimize().
Key benefits
- Native asyncio support with httpx connection reuse
- Django model field integration (SmallPictImageField)
- Celery and RQ task decorators for batch queue execution
- Full typing support with Pydantic schemas
Need complete implementation guides & API specs?
Explore parameter references, authentication mechanisms, error codes, and local testing instructions in our official Python & Django package developer guide.
Read Python & Django package DocsSpeed Up Your Python & Django package Image Pipeline
Try AVIF and WebP image optimization in your application. No setup fee, and sandbox keys right away.