This is the backend of the app. It has two components:
- The Celery worker, which runs image resizing tasks
- The Flask server, which serves the API to upload new images
Configuration is loaded from the config.py file.
By default, this file reads environment variables to configure the application:
CELERY_BROKER_URL: URL of the message brokerS3_ENDPOINT_URL: Endpoint of the S3 serviceAWS_ACCESS_KEY_ID: Access key used for authenticating S3 operationsAWS_SECRET_ACCESS_KEY: Secret key used for authenticating S3 operationsS3_BUCKET_NAME: Bucket to use for storing images
The easiest way to try the API locally is to use Poetry to install dependencies, Redis as message broker and Minio for S3-compatible storage.
# Install Poetry
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
uv sync
# Run a Redis server via Docker
docker run -d -p 6379:6379 --rm --name redis redis:7.4
# Run a Minio instance via Docker
docker run -d -p 9000:9000 -p 9001:9001 --rm --name minio quay.io/minio/minio server /data --console-address ":9001"
# Set a bunch of environment variables
export CELERY_BROKER_URL=redis://localhost:6379/0
export S3_ENDPOINT_URL=http://localhost:9000
export AWS_ACCESS_KEY_ID=minioadmin
export AWS_SECRET_ACCESS_KEY=minioadmin
export S3_BUCKET_NAME=images
# Run the dev. web server
uv run image-api
# Run the celery worker
uv run celery --app image_api.worker.app worker
# Upload an image
curl -X POST \
http://localhost:8080/image \
--form file=@/path/to/an/image.pngRequires Python >=3.9.
uv sync --no-dev --lockedThe application exposes a WSGI-compatible API under the image_api.web:app module.
Any WSGI-compatible server can be used, like gunicorn or waitress.
Example with gunicorn:
# Install gunicorn
uv pip install gunicorn
# Run gunicorn with 4 threads on port 8080
uv run --no-dev gunicorn --workers 4 --bind 0.0.0.0:8080 image_api.web:appSee https://flask.palletsprojects.com/en/2.1.x/deploying/wsgi-standalone/
uv run --no-dev celery --app image_api.worker.app workerSee https://docs.celeryq.dev/en/stable/userguide/workers.html