Basic Python Upload
# Simple file upload and transformation from filestack import Client
client = Client('YOUR_API_KEY')
# Upload a file
filelink = client.upload('/path/to/image.jpg')
print(f'Uploaded: {filelink.url}')
# Apply transformations
transformed = client.transform(
filelink.handle,
{'resize': {'width': 300, 'height': 300}}
)
print(f'Transformed: {transformed.url}')Built for Python Developers
Our Python SDK integrates seamlessly with your existing Python stack, providing Pythonic APIs and comprehensive framework support.
Pythonic API Design
Clean, intuitive APIs that follow Python conventions and PEP standards for a familiar development experience.
Framework Integration
Native support for popular Python web frameworks with comprehensive middleware and utilities for seamless integration.
Async/Await Support
Full asyncio support for modern Python applications with async upload, transformation, and processing capabilities.
Batch Processing
Efficiently process thousands of files with batch upload, transformation, and delivery operations optimized for high-volume workflows.
Type Hints & Validation
Complete type annotations, Pydantic model support, and runtime validation for safer, more maintainable code.
Webhook Integration
Built-in webhook handling with signature verification, automatic retries, and framework-specific middleware.
Trusted by innovative companies worldwide
Perfect for Server-Side Workflows
From simple file uploads to complex media processing pipelines, our Python SDK handles your most demanding server-side file management needs.
Build REST APIs with popular Python frameworks that handle file uploads, transformations, and delivery.
Create Celery tasks, RQ jobs, or asyncio workers for processing large volumes of files asynchronously.
Integrate with data processing libraries and workflow orchestration tools for comprehensive file transformation workflows.
Process training data, transform images for computer vision, or handle model artifacts with ease.
Django Integration Example
# Django integration example from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from filestack import Client import json client = Client('YOUR_API_KEY')
@csrf_exempt def upload_and_transform(request):
if request.method == 'POST':
uploaded_file = request.FILES['file']
# Upload to Filestack filelink = client.upload(uploaded_file)
# Apply transformations transforms = {
'resize': {'width': 800, 'height': 600},
'quality': 85,
'format': 'webp'
}
transformed = client.transform(
filelink.handle,
transforms
)
return JsonResponse({
'original': filelink.url,
'transformed': transformed.url,
'handle': filelink.handle
})
# FastAPI async example from fastapi import FastAPI, UploadFile from filestack.async_client import AsyncClient app = FastAPI()
async_client = AsyncClient('YOUR_API_KEY')
@app.post("/upload")
async def upload(file: UploadFile):
result = await async_client.upload(file.file)
return {"url": result.url, "handle": result.handle}
Quick Installation & Setup
Get started with our Python SDK using pip or your preferred package manager. Compatible with Python 3.7+ and all major frameworks.
Install Package
pip install filestack-pythonpoetry add filestack-pythonconda install -c conda-forge filestack-pythonBasic Usage
Import and initialize the client:
from filestack import Client client = Client('YOUR_API_KEY')
filelink = client.upload('/path/to/file.jpg')
Complete Python Implementation
# Complete working example import os from filestack import Client # Initialize client client = Client(os.getenv('FILESTACK_API_KEY'))
# Upload a file def upload(file_path):
try:
filelink = client.upload(file_path)
print(f'Upload successful: {filelink.url}')
return filelink except Exception as e:
print(f'Upload failed: {e}')
return None # Transform an image def create_thumbnail(handle):
transforms = {
'resize': {
'width': 200,
'height': 200,
'fit': 'crop'
},
'quality': 80,
'format': 'webp'
}
transformed = client.transform(handle, transforms)
return transformed.url # Batch processing def process_images(image_paths):
results = []
for path in image_paths:
filelink = upload(path)
if filelink:
thumbnail_url = create_thumbnail(filelink.handle)
results.append({
'original': filelink.url,
'thumbnail': thumbnail_url,
'filename': os.basename(path)
})
return results # Example usage if __name__ == '__main__':
images = ['photo1.jpg', 'photo2.png', 'photo3.gif']
processed = process_images(images)
print(f'Processed {len(processed)} images')
Start Building with Python
Join thousands of Python developers who trust Filestack for their server-side file management needs. From startups to enterprise, our Python SDK scales with your applications.