Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 01-hello/src/entry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from workers import handler, Response
from workers import WorkerEntrypoint, Response

@handler
async def on_fetch(request, env):
class Default(WorkerEntrypoint):
async def fetch(self, request, env):
return Response("Hello world!")
2 changes: 1 addition & 1 deletion 01-hello/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "hello-python"
main = "src/entry.py"
compatibility_flags = ["python_workers"]
compatibility_date = "2024-03-29"
compatibility_date = "2025-08-14"
6 changes: 3 additions & 3 deletions 02-binding/src/entry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from workers import handler, Response
from workers import WorkerEntrypoint, Response

@handler
async def on_fetch(request, env):
class Default(WorkerEntrypoint):
async def fetch(selfrequest, env):
await env.FOO.put("bar", "baz")
bar = await env.FOO.get("bar")
return Response(bar) # returns "baz"
4 changes: 2 additions & 2 deletions 02-binding/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name = "hello-python-bindings"
main = "src/entry.py"
compatibility_flags = ["python_workers"]
compatibility_date = "2024-03-29"
compatibility_date = "2025-08-14"

kv_namespaces = [
{ binding = "FOO", id = "<YOUR_KV_NAMESPACE_ID>" }
]
]
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions 05-query-d1/src/entry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from workers import handler, Response
from workers import WorkerEntrypoint, Response

@handler
async def on_fetch(request, env):
class Default(WorkerEntrypoint):
async def fetch(self, request, env):
query = """
SELECT quote, author
FROM qtable
Expand Down
2 changes: 1 addition & 1 deletion 05-query-d1/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#:schema node_modules/wrangler/config-schema.json
compatibility_date = "2024-08-06"
compatibility_date = "2025-08-14"
main = "src/entry.py"
compatibility_flags = ["python_workers"]

Expand Down
4 changes: 3 additions & 1 deletion 06-vendoring/src/worker.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import jinja2
from fastapi import FastAPI, Request
from workers import WorkerEntrypoint

environment = jinja2.Environment()
template = environment.from_string("Hello, {{ name }}!")


async def on_fetch(request, env):
class Default(WorkerEntrypoint):
async def fetch(self, request, env):
import asgi

return await asgi.fetch(app, request, env)
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ Need to deploy your Worker to Cloudflare? Python Workers are in open beta and ha
## Examples

- [**`01-hello/`**](01-hello) — the most basic Python Worker
- [**`05-query-d1/`**](05-query-d1) - shows how to query D1 with Python Workers
- [**`06-vendoring/`**](06-vendoring) - shows how to vendor packages

These examples are deprecated:

- [**`02-binding/`**](02-binding) — shows how [bindings](https://developers.cloudflare.com/workers/configuration/bindings/) work in Python Workers. Put a key into Workers KV, and then read it.
- [**`03-fastapi/`**](03-fastapi) — demonstrates how to use the [FastAPI](https://fastapi.tiangolo.com/) package with Python Workers
- [**`04-langchain/`**](04-langchain) — demonstrates how to use the [LangChain](https://pypi.org/project/langchain/) package with Python Workers
- [**`05-query-d1/`**](05-query-d1) - shows how to query D1 with Python Workers
- [**`06-vendoring/`**](06-vendring) - shows how to vendor packages that are not included in the built-in package list

## Open Beta and Limits

- Python Workers are in open beta. Currently, you can only deploy Python Workers that use the standard library. [Packages](https://developers.cloudflare.com/workers/languages/python/packages/#supported-packages) **cannot be deployed** and will only work in local development by default.
- If you wish to join our closed beta which enables deploying packages, fill out [this form](https://forms.gle/827KAtKJTZdgAkNm7).
- Python Workers are in open beta. You can use packages in your Workers by vendoring them using the [pywrangler](https://github.com/cloudflare/workers-py?tab=readme-ov-file#pywrangler) tool.
- You must add the `python_workers` compatibility flag to your Worker while Python Workers are in open beta.

We’d love your feedback. Join the `#python-workers channel` in the [Cloudflare Developers Discord](https://discord.cloudflare.com/) and let us know what you’d like to see next.
Expand Down
Loading