Overview
This demo showcases how to use Trigger.dev with Python to process an image using Pillow (PIL) from a URL and upload it to S3-compatible storage bucket.Prerequisites
- A project with Trigger.dev initialized
- Python installed on your local machine
Features
- A Trigger.dev task to trigger the image processing Python script, and then upload the processed image to S3-compatible storage
- The Trigger.dev Python build extension to install dependencies and run Python scripts
- Pillow (PIL) for powerful image processing capabilities
- AWS SDK v3 for S3 uploads
- S3-compatible storage support (AWS S3, Cloudflare R2, etc.)
GitHub repo
View the project on GitHub
Click here to view the full code for this project in our examples repository on GitHub. You can
fork it and use it as a starting point for your own project.
The code
Build configuration
After you’ve initialized your project with Trigger.dev, add these build settings to yourtrigger.config.ts file:
trigger.config.ts
Learn more about executing scripts in your Trigger.dev project using our Python build extension
here.
Task code
This task uses thepython.runScript method to run the image-processing.py script with the given image URL as an argument. You can adjust the image processing parameters in the payload, with options such as height, width, quality, output format, etc.
src/trigger/processImage.ts
Add a requirements.txt file
Add the following to yourrequirements.txt file. This is required in Python projects to install the dependencies.
requirements.txt
The Python script
The Python script uses Pillow (PIL) to process an image. You can see the original script in our examples repository here.src/python/image-processing.py
Testing your task
- Create a virtual environment
python -m venv venv - Activate the virtual environment, depending on your OS: On Mac/Linux:
source venv/bin/activate, on Windows:venv\Scripts\activate - Install the Python dependencies
pip install -r requirements.txt - Set up your S3-compatible storage credentials in your environment variables, in .env for local development, or in the Trigger.dev dashboard for production:
- Copy the project ref from your Trigger.dev dashboard and add it to the
trigger.config.tsfile. - Run the Trigger.dev CLI
devcommand (it may ask you to authorize the CLI if you haven’t already). - Test the task in the dashboard by providing a valid image URL and processing options.
- Deploy the task to production using the Trigger.dev CLI
deploycommand.
Example Payload
These are all optional parameters that can be passed to theimage-processing.py Python script from the processImage.ts task.
Deploying your task
Deploy the task to production using the CLI commandnpx trigger.dev@latest deploy
Learn more about using Python with Trigger.dev
Python build extension
Learn how to use our built-in Python build extension to install dependencies and run your Python
code.



