Python + Transloadit
Upload and process a local file with pytransloadit, the maintained Python client for the Transloadit REST API.
Executable recipe
Build the integration
The script reads one file path from the command line, uploads it, resizes the image, waits for completion, and prints the Assembly ID.
- Create a virtual environment and install pytransloadit.
- Set TRANSLOADIT_KEY and TRANSLOADIT_SECRET in the process environment.
- Run python process_image.py path/to/photo.jpg.
Install
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade 'pytransloadit>=2,<3'process_image.py
import os
import sys
from transloadit import client
transloadit = client.Transloadit(
os.environ['TRANSLOADIT_KEY'],
os.environ['TRANSLOADIT_SECRET'],
)
assembly = transloadit.new_assembly()
with open(sys.argv[1], 'rb') as input_file:
assembly.add_file(input_file)
assembly.add_step('resize', '/image/resize', {
'width': 1200,
'height': 1200,
'resize_strategy': 'fit',
})
response = assembly.create(retries=5, wait=True)
if response.data.get('error'):
raise RuntimeError('Media processing failed')
print(response.data['assembly_id'])Authentication
- Read the Transloadit Auth Key and Auth Secret from server environment variables and pass both to the official Python SDK.
- The SDK signs requests when the secret is supplied; never commit either credential to source control.
- Use a fixed Template when application users choose files, or validate every dynamic Step before creating an Assembly.
Limitations and operational notes
- wait=True blocks the process until the Assembly finishes. For web workers and long-running media jobs, store the Assembly ID and observe completion asynchronously.
- Version 2 requires Python 3.12 or newer. The install command selects version 2 explicitly instead of silently installing the older 1.x SDK on Python 3.9 to 3.11.
- The retries option bounds resumable uploads and rate-limited Assembly creation or status polling; it does not provide application-level idempotency. With wait=True, exhausted polling retries raise AssemblyPollingError while the Assembly may still be running. Use the exception’s recovery details to track the existing Assembly instead of blindly submitting the job again.
More integrations