SDK officiel pour Python
Bibliothèque Python avec support synchrone et asynchrone (asyncio).
Compatible avec Python 3.9+, offrant une API synchrone simple ainsi qu'un client asynchrone (asyncio) pour FastAPI et aiohttp.
Installation
Shell
pip install smallpict# ou avec poetrypoetry add smallpictExemple complet d'utilisation
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. Optimisation d'un fichier localwith open("banner.png", "rb") as f: result = client.optimize( file=f.read(), filename="banner.png", format="avif", quality=80 )
print(f"URL CDN : {result.url}")print(f"Économie réalisée : {result.savings_percentage}%")
# 2. Consultation du quotaquota = client.get_quota()print(f"Forfait : {quota.plan} - Restant : {quota.remaining}")