An experiment in running Python functions at scale on Cloudflare with a single command. Write normal Python, execute across multiple containers in parallel.
git clone https://github.com/jonesphillip/pyflare
cd flare
./install.shThis installs the flare CLI globally.
Verify:
flare --versioncd flare-worker
npm install
npx wrangler deployNote the Worker URL from the output. See flare-worker/README.md for details.
flare config init
# Enter Worker URL and generate API keySet the API key in your Worker (this authenticates the Python client with your Worker):
cd flare-worker
echo 'sk_your_generated_key' | npx wrangler secret put API_KEYflare run examples/hello.pyimport flare
app = flare.App("my-app")
@app.function()
def process(x):
return x * 2
@app.local_entrypoint()
def main():
result = process.remote(5)
print(result) # 10flare run script.py@app.function(max_containers=10)
def process_item(item):
return item * 2
@app.local_entrypoint()
def main():
items = [1, 2, 3, 4, 5]
results = process_item.map(items)
print(results) # [2, 4, 6, 8, 10]See execution details:
flare run script.py --execution@app.function(timeout=60) # 60 second timeout
def slow_task(x):
import time
time.sleep(30)
return x * 2import os
@app.function(env={"API_KEY": "secret_value"})
def authenticated_task(x):
import os
api_key = os.environ['API_KEY']
return x * 2
# Load from local environment
@app.function(env={"TOKEN": os.getenv("MY_TOKEN")})
def process(x):
import os
token = os.environ['TOKEN']
return x * 2@app.local_entrypoint()
def main(name: str = "World", count: int = 3):
for i in range(count):
result = greet.remote(name)
print(result)flare run script.py --name "Alice" --count 5@app.function()
def greet(name):
return f"Hello, {name}!"flare run examples/hello.py::greet --name "World"# Run scripts
flare run script.py
flare run script.py::function_name --arg value
flare run script.py --execution # Show execution details
# Configuration
flare config init
flare config show
flare config set-url <url>
flare config set-key <key>
# Help
flare --help
flare run --helpInstall Flare library in your project:
Add to your pyproject.toml:
[project]
dependencies = [
"flare @ file:///path/to/flare"
]Then run:
uv syncDevelop on Flare itself:
# Install in development mode
uv sync --all-extras
# Run locally
# Terminal 1: Start worker
cd flare-worker
npm run dev
# Terminal 2: Run examples (in another terminal)
uv run flare run examples/hello.pyUninstall:
uv tool uninstall flare