Cloudflare Workers Containers Python Template
A template for creating Cloudflare Workers applications using Python and Cloudflare Workers Containers.
Overview
This template enables you to build and deploy Python applications on Cloudflare's edge network using Workers Containers. It combines the flexibility of Python with the performance and global distribution of Cloudflare Workers.
Key Features:
- Python runtime support on Cloudflare Workers
- Containerized Python applications at the edge
- Global edge deployment with low latency
- Serverless scaling and execution
- Easy to configure and deploy
- Fast cold starts with container optimization
- Hybrid TypeScript/JavaScript and Python setup
- Automated CI/CD with GitHub Actions
- Live deployment example available
Getting Started
Installation
git clone https://github.com/CROW-B3/cloudflare-workers-containers-python-template.git
cd cloudflare-workers-containers-python-template
pip install -r requirements.txt
Configure your Cloudflare credentials in wrangler.jsonc.
Deployment
wrangler deploy # Builds Python container, pushes to Cloudflare, deploys globally
Architecture
Workers Containers allow you to run Python code in a containerized environment at the edge. Your Python app is packaged in a Docker container, distributed to Cloudflare's global network, and executes at the nearest edge location for incoming requests.
Configuration
Configure your worker in wrangler.jsonc and create a Dockerfile for your Python application. See the repository for example configurations.
Best Practices
- Minimize container size using slim Python images and essential dependencies only
- Keep initialization code minimal to optimize cold starts
- Use Docker layer caching effectively
- Store secrets in Cloudflare Worker environment variables
- Validate all incoming data
- Keep Python packages up to date
Limitations
Be aware of Cloudflare Workers Containers limitations including CPU time per request, memory constraints, ephemeral file system, and initial container startup time.
Resources
- Repository: GitHub
- Live Demo: cloudflare-workers-containers-python-template.bitbybit-b3.workers.dev
- Cloudflare Workers Containers Docs: developers.cloudflare.com
- Python Documentation: python.org
- Wrangler CLI: developers.cloudflare.com/workers/wrangler
- License: MIT
Support
For issues and questions:
- Check the GitHub Issues
- Review Cloudflare Workers documentation
- Join the CROW-B3 community
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request