Python SDK
Python SDK for imgfast image management.
download
Installation
pip install imgfast
# or with poetry
poetry add imgfastsettings
Configuration
import os
from imgfast import Imgfast
client = Imgfast(
public_key=os.environ.get('IMGFAST_PUBLIC_KEY'),
secret_key=os.environ.get('IMGFAST_SECRET_KEY'),
signing_secret=os.environ.get('IMGFAST_SIGNING_SECRET'), # optional
)upload
Upload Images
From File
# Upload from file path
result = client.upload(
file_path='./photo.jpg',
filename='products/sneaker-01.jpg',
)
print(result['cdn_url'])
# https://cdn.imgfast.io/pk_xxx/products/sneaker-01.jpgFrom Bytes
# Upload from bytes (e.g., from Flask request)
result = client.upload(
file_bytes=request.files['image'].read(),
filename='products/sneaker-01.jpg',
content_type='image/jpeg',
)link
Generate URLs
# Basic URL
url = client.url('products/sneaker-01.jpg')
# With transformations
transformed_url = client.url('products/sneaker-01.jpg',
width=400,
height=300,
format='webp',
quality=80,
fit='cover',
)
# Remote URL proxy
proxy_url = client.proxy_url('https://example.com/image.jpg',
width=800,
format='auto',
)
# Signed URL
signed_url = client.signed_url('products/sneaker-01.jpg',
width=400,
expires_in=3600, # 1 hour
)web
Django Integration
Settings
settings.py
IMGFAST = {
'PUBLIC_KEY': os.environ.get('IMGFAST_PUBLIC_KEY'),
'SECRET_KEY': os.environ.get('IMGFAST_SECRET_KEY'),
'CDN_URL': 'https://cdn.imgfast.io',
}Template Tag
{% load imgfast %}
<!-- Basic usage -->
<img src="{% imgfast_url 'products/sneaker.jpg' width=400 %}" alt="Product">
<!-- With multiple transforms -->
<img src="{% imgfast_url image.path width=800 height=600 format='webp' %}" alt="{{ image.alt }}">