Python SDK
Official smallpict-python SDK for Django, FastAPI, Flask, and data pipelines.
Python SDK (smallpict)
The official SmallPict Python package supports synchronous and asynchronous workflows with full type hints (PEP 484).
📦 Installation
pip install smallpict
# or
poetry add smallpict
🚀 Quickstart Example
import os
from smallpict import SmallPict
client = SmallPict(
api_key=os.environ["SMALLPICT_API_KEY"],
secret_key=os.environ["SMALLPICT_SECRET_KEY"],
max_retries=3
)
# 1. Optimize an image file
with open("banner.jpg", "rb") as f:
result = client.optimize(
source=f.read(),
format="avif",
quality=80,
strip_metadata=True
)
print(f"Optimized URL: {result.url}")
print(f"Savings: {result.savings_percentage}%")
# 2. Check quota
quota = client.get_quota()
print(f"Usage: {quota.bytes_used} bytes used")
