Skip to content

Crosswind

Crosswind provides Python SDKs for Cloudflare Workers, Durable Objects, Agents, Containers and Sandboxes. Its typed, async APIs replace the workers package, and its wynd CLI replaces pywrangler.

Every package is alpha. Pin exact versions.

Agents cf-agents

Stateful agents with WebSocket clients, schedules, durable tasks and streaming chat.

from workers import Request, Response, WorkerEntrypoint
from agents import Agent, callable, route_agent_request


class Counter(Agent):
    initial_state = {"count": 0}

    @callable  # clients call this over a WebSocket
    async def increment(self, by: int = 1) -> int:
        self.set_state({"count": self.state["count"] + by})  # saved, sent to every client
        return self.state["count"]


class Default(WorkerEntrypoint):
    async def fetch(self, request: Request) -> Response:
        # /agents/counter/<name> reaches the counter called <name>
        return await route_agent_request(request, self.env) or Response("Not found", status=404)

Sandboxes crosswind-sandboxes

Read and write files, mount S3 buckets and back up directories in a sandbox container.

from sandboxes import Files
from workers import DurableObject, Request, Response, WorkerEntrypoint


class Sandbox(DurableObject):
    async def save(self, text: str) -> str:
        if not self.ctx.container.running:
            self.ctx.container.start()

        files = Files(self.ctx.container)
        await files.mkdir("/workspace", recursive=True)
        await files.write_file("/workspace/notes.txt", text)  # still there on the next request
        entries = await files.read_directory("/workspace")
        return ", ".join(entry.name for entry in entries)


class Default(WorkerEntrypoint):
    async def fetch(self, request: Request) -> Response:
        # One sandbox per user, with its own container and files
        user_id = request.url.rsplit("/", 1)[-1]
        sandbox = self.env.SANDBOX.getByName(user_id)
        return Response(await sandbox.save(await request.text()))

Containers containers-py

Start, stop and route requests to Cloudflare Containers, and filter their outbound traffic.

from workers import Request, Response, WorkerEntrypoint
from containers import Container, get_container


class Transcoder(Container):
    default_port = 8080
    sleep_after = "5m"
    enable_internet = False


class Default(WorkerEntrypoint):
    async def fetch(self, request: Request) -> Response:
        # One container per video, started on the first request
        video_id = request.url.rsplit("/", 1)[-1]
        container = get_container(self.env.TRANSCODER, video_id)
        return await container.fetch(request)

Workers crosswind-workers

Drop-in replacement for the official workers package, with type hints on bindings, requests and Durable Objects.

from env import Env  # generated by wynd from wrangler.jsonc
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:
        # self.env.COUNTER is typed, so a misspelled method fails the type check
        count = await self.env.COUNTER.get_by_name("global").increment(1)
        return Response.json({"count": count})

Wynd wynd

Replaces pywrangler. It drops vendored files your Worker never imports before each upload.

$ uvx wynd init my-worker
  1) crosswind-workers
  2) workers-runtime-sdk
Workers SDK [1]: 1
  1) containers-py
  2) cf-agents
Add SDKs, comma-separated: 
wynd: wrote src/env.py
wynd: created my-worker. Run `wynd dev` in ~/my-worker to serve it.
​
$ cd my-worker
$ uvx wynd dev
 ⛅️ wrangler 4.129.0
───────────────────────────────────────────────────
╭──────────────────────────╮
│  [b] open a browser      │
│  [d] open devtools       │
│  [e] open local explorer │
│  [t] start tunnel        │
│  [c] clear console       │
│  [x] to exit             │
╰──────────────────────────╯
Attaching additional modules:
┌────────────────────┬────────┬────────────┐
│ Name               │ Type   │ Size       │
├────────────────────┼────────┼────────────┤
│ env.py             │ python │ 0.13 KiB   │
├────────────────────┼────────┼────────────┤
│ Vendored Modules   │        │ 131.24 KiB │
├────────────────────┼────────┼────────────┤
│ Total (43 modules) │        │ 131.37 KiB │
└────────────────────┴────────┴────────────┘
⎔ Starting local server...
[wrangler:info] Ready on http://localhost:8787
​
$ uvx wynd deploy --dry-run
wynd: python_modules is 134,389 bytes, 85,098 after pruning (49,291 fewer). Each file's decision is in .wynd/shake.txt.
 ⛅️ wrangler 4.129.0
───────────────────────────────────────────────────
Attaching additional modules:
┌────────────────────┬────────┬───────────┐
│ Name               │ Type   │ Size      │
├────────────────────┼────────┼───────────┤
│ env.py             │ python │ 0.13 KiB  │
├────────────────────┼────────┼───────────┤
│ Vendored Modules   │        │ 83.10 KiB │
├────────────────────┼────────┼───────────┤
│ Total (37 modules) │        │ 83.24 KiB │
└────────────────────┴────────┴───────────┘
Total Upload: 83.42 KiB / gzip: 19.53 KiB
No bindings found.
--dry-run: exiting now.

What Crosswind is

Crosswind provides Python SDKs for Cloudflare Workers, Durable Objects, Agents, Containers and Sandboxes.

Python Workers run Python on Cloudflare's network. Several Cloudflare products ship their developer kits only for TypeScript, so using them from Python means calling JavaScript objects through Pyodide's foreign function interface.

Each Crosswind package ports one of those kits to Python. You subclass a Python class, override async methods and call typed functions, and the package makes the JavaScript calls.

Packages

Project Package What it does Start here Version
Agents cf-agents Stateful agents with WebSocket clients, schedules, durable tasks and streaming chat. Build an agent cf-agents on PyPI
Containers containers-py Start, stop and route requests to Cloudflare Containers, and filter their outbound traffic. Run a container containers-py on PyPI
Sandboxes crosswind-sandboxes Read and write files, mount S3 buckets and back up directories in a sandbox container. Create a sandbox crosswind-sandboxes on PyPI
Workers crosswind-workers Drop-in replacement for the official workers package, with type hints on bindings, requests and Durable Objects. Write a Worker crosswind-workers on PyPI
Wynd wynd Replaces pywrangler. It drops vendored files your Worker never imports before each upload. Switch from pywrangler wynd on PyPI

For a new Python Worker, use crosswind-workers and deploy it with Wynd.

How the packages work

  • Python classes. You subclass a class and override async methods. Bindings and state have type hints, so a type checker catches a misspelled method before you deploy.
  • TypeScript behaviour. Each package keeps the defaults, timeouts and wire protocols of the TypeScript SDK it ports. The Cloudflare docs for that product still describe what your code does, and TypeScript clients such as the useAgent React hook connect to a Python Worker unchanged.
  • Web frameworks. crosswind-workers serves ASGI apps such as FastAPI and Starlette, and WSGI apps such as Flask. See Serve FastAPI or Flask.
How Agents, Containers, Workers and Wynd connect Python sits at the centre of Crosswind. Agents, Containers, Wynd and Workers connect to it. Wynd drops the dependencies a Worker never imports, packs the rest into a bundle and deploys it to Workers. Select a package in the diagram to open its docs.

Demo

Mosslight Valley is a small game that runs on Python Workers. Its server is written with cf-agents. Open it in a new tab

Status

Every package is alpha and pre-1.0. A minor release can rename or remove an API, so an unpinned dependency can break a deploy that worked yesterday. Pin exact versions, test each upgrade before you deploy it, and expect to change your code when you upgrade:

uv add "crosswind-workers==<version>"

Each SDK's overview lists the features it doesn't port yet. Crosswind is an independent community project. It isn't affiliated with or endorsed by Cloudflare.