Build a typed Python Worker with crosswind-workers
This guide builds a Python Worker on Cloudflare that counts its requests in a
Durable Object. By the
end, curl returns {"greeting": "hello", "count": 1}, and the count goes up
on every request.
Prerequisites
uv0.13.4 or later. Check withuv --version.- Node.js, which provides
npx. Wynd runs Wrangler through it. - A Cloudflare account, for the deploy step only.
1. Create the project
Create a directory with a src/ folder:
mkdir -p hello-worker/src
cd hello-worker
Declare crosswind-workers as a dependency:
[project]
name = "hello-worker"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["crosswind-workers"]
Wynd reads this list to choose the SDK. A project declares either
crosswind-workers or workers-runtime-sdk, never both.
2. Configure Wrangler
{
"name": "hello-worker",
"main": "src/entry.py",
"compatibility_date": "2026-09-08",
"compatibility_flags": ["python_workers"],
"vars": { "GREETING": "hello" },
"durable_objects": {
"bindings": [{ "name": "COUNTER", "class_name": "Counter" }]
},
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["Counter"] }]
}
name = "hello-worker"
main = "src/entry.py"
compatibility_date = "2026-09-08"
compatibility_flags = ["python_workers"]
[vars]
GREETING = "hello"
[[durable_objects.bindings]]
name = "COUNTER"
class_name = "Counter"
[[migrations]]
tag = "v1"
new_sqlite_classes = ["Counter"]
from wynd.config import Config, Worker, bindings, exports
config = Config(
worker=Worker(
name="hello-worker",
entrypoint="src/entry.py",
compatibility_date="2026-09-08",
env={
"GREETING": bindings.Text("hello"),
"COUNTER": bindings.DurableObject("Counter"),
},
exports={"Counter": exports.DurableObject()},
),
)
The python_workers flag and the date pick the Python version. A date of
2026-09-08 or later runs Python 3.14. See
Python targets for the other versions.
main must point into a subdirectory such as src/. Wynd copies that
directory when it deploys, and fails if main sits next to wrangler.jsonc.
uvx wynd init creates the same layout with the config written in Python, in
cloudflare.config.py. This guide uses wrangler.jsonc because Wynd's tests
don't yet cover deploying a Durable Object declared in a Python config. See
Configure a Worker in Python.
3. Write the Worker
from env import Env
from workers import DurableObject, Request, Response, WorkerEntrypoint
class Counter(DurableObject[Env]):
async def increment(self, by: int) -> int:
count = (await self.ctx.storage.get("count") or 0) + by
await self.ctx.storage.put("count", count)
return count
class Default(WorkerEntrypoint[Env]):
async def fetch(self, request: Request) -> Response:
counter = self.env.COUNTER.get_by_name("global")
count = await counter.increment(1)
return Response.json({"greeting": self.env.GREETING, "count": count})
Default handles HTTP requests. get_by_name("global") returns a stub for
the Durable Object named global, and counter.increment(1) calls the method
on it over RPC.
Warning
Pass RPC arguments by position.
counter.increment(by=1)type-checks, but the Durable Object receives one dictionary,{"by": 1}, in place ofby. The request then fails withTypeError: unsupported operand type(s) for +: 'int' and 'JsDict'.
env.py doesn't exist yet. Wynd writes it in the next step.
4. Run it locally
uvx wynd dev
Wynd installs your packages for the Python target into python_modules/,
writes src/env.py, and starts Wrangler's dev server:
wynd: wrote src/env.py
...
[wrangler:info] Ready on http://localhost:8787
In a second terminal:
curl http://localhost:8787/
{"greeting": "hello", "count": 1}
Run it again and count is 2.
The generated src/env.py types every binding in wrangler.jsonc:
# Generated by wynd types. Do not edit.
from __future__ import annotations
from typing import TYPE_CHECKING, Protocol
from workers.bindings import DurableObjectNamespace
if TYPE_CHECKING:
from entry import Counter
class Env(Protocol):
COUNTER: DurableObjectNamespace[Counter]
GREETING: str
Because COUNTER is DurableObjectNamespace[Counter], a type checker reports
counter.incremnt(1) as an error. Commit env.py, and see
Generate typed bindings for how Wynd builds it.
5. Set up your editor
Wynd doesn't create a virtual environment for your editor. Let uv create the
usual .venv:
uv sync
Point your editor at .venv if it doesn't find it. Then add Wynd's output to
.gitignore:
.venv/
.wynd/
Commit pylock.toml. It pins the package versions Wynd installs for the
Worker.
6. Deploy
Log in once, then deploy:
uvx wynd login
uvx wynd deploy
wynd login runs wrangler login. wynd deploy drops the vendored files
your Worker never imports, copies the rest into .wynd/build/ and uploads
that copy. Wrangler prints the Worker's URL when it finishes.
To see the upload without sending it, run uvx wynd deploy --dry-run. Wynd
prints the bytes it removed before Wrangler's own output:
wynd: python_modules is 127,013 bytes, 92,668 after pruning (34,345 fewer). Each file's decision is in .wynd/shake.txt.
Next steps
- Use bindings adds KV, D1, R2 and Queues.
- Build a Durable Object covers storage, alarms and WebSockets.
- Serve FastAPI or Flask runs an existing app as a Worker.