Offizielles Python SDK
Moderne Python-Bibliothek mit synchroner und asynchroner Schnittstelle (asyncio).
Kompatibel mit Python 3.9+, bietet synchrone Methoden für Skripte und Django sowie asynchrone Unterstützung (asyncio) für FastAPI und aiohttp.
Installation
Shell
pip install smallpict# oder mit poetrypoetry add smallpictVollständiges Codebeispiel
Python
import osfrom smallpict import SmallPictClient
client = SmallPictClient( api_key=os.environ.get("SMALLPICT_API_KEY"), secret_key=os.environ.get("SMALLPICT_SECRET_KEY"))
# 1. Lokales Bild optimierenwith open("banner.png", "rb") as f: result = client.optimize( file=f.read(), filename="banner.png", format="avif", quality=80 )
print(f"CDN URL: {result.url}")print(f"Ersparnis: {result.savings_percentage}%")
# 2. Kontingent abrufenquota = client.get_quota()print(f"Tarif: {quota.plan} - Verbleibend: {quota.remaining}")