Cloudflare Python Workers General Availability

Cloudflare Python Workers are now generally available (GA), transforming Python into a first-class language on the Cloudflare Developer Platform. This allows developers to deploy Python applications and libraries directly to the edge, integrating seamlessly with Cloudflare services like Workers AI, R2, D1, Hyperdrive, and Durable Objects.

Native Integration with Cloudflare Bindings

Python Workers now natively support Cloudflare Developer Platform bindings, eliminating the need for manual type conversion between Python and JavaScript objects at the RPC boundary. Previously, developers had to use glue code (such as to_js from Pyodide) to send data to services like Cloudflare Queues. Now, the runtime and Python SDK encapsulate this process, allowing for a Pythonic interface:

self.env.QUEUE.send({"key": "value"})

Support for Popular Web Frameworks

Developers can now run standard Python web frameworks, including FastAPI, Django, and Flask, within Python Workers. This is achieved through built-in connectors that bridge the Cloudflare Workers runtime to the Web Server Gateway Interface (WSGI) and Asynchronous Server Gateway Interface (ASGI) standards.

  • ASGI Support: The workers.asgi package allows asynchronous frameworks like FastAPI to run without a separate web server like Uvicorn.
  • WSGI Support: The workers.wsgi package enables synchronous frameworks like Django to be deployed.

Because the Cloudflare global network handles load balancing and scaling, these connectors act as a thin bridge, translating native JavaScript requests into the standard structures expected by Python applications without the overhead of running a full server inside the worker.

Database Connectivity via Hyperdrive

Python Workers now support TCP sockets, which was previously a blocker for database drivers. Because Python Workers run in a WebAssembly (Wasm) sandbox, standard POSIX networking syscalls typically fail. Cloudflare implemented socket system calls using the Workers connect API, translating Python socket operations into JavaScript calls.

This enables the use of standard database drivers like aiomysql or asyncpg to connect to relational databases via Hyperdrive. For example, a Python Worker can now execute SQL queries using aiomysql by leveraging the Hyperdrive binding for host, port, and credentials.

Expanding the Wasm Package Ecosystem

To address the limitation of packages with native C/C++/Rust extensions, Cloudflare proposed and helped standardize PEP 783, which defines the PyEmscripten platform. This allows package maintainers to build and publish wheels specifically for the PyEmscripten platform, making them available across all environments that implement it.

Cloudflare has also stabilized the Pyodide build toolchain and added PyEmscripten support to cibuildwheel to simplify the process for package maintainers to adopt this standard.

AI Agents and Pipeline Development

Python's data science ecosystem makes it ideal for AI agents. Cloudflare has ensured that HTTP clients like requests and httpx can route requests through the JavaScript fetch API in Wasm environments. Combined with the new socket support, this allows libraries such as openai, langchain, and mcp to run natively in Python Workers.

Developers can combine these libraries with Workers AI for serverless GPU inference or use the langchain-cloudflare package to orchestrate AI workflows at the edge.

Community Insights and Technical Considerations

While the general availability marks a significant milestone, community discussion highlights several technical trade-offs and architectural concerns:

  • Cold Start Performance: Some developers have raised concerns regarding cold start times. A competitor (Wasmer) claimed in a benchmark that minimal Python applications on Cloudflare Workers had significantly higher startup times (around 900ms) compared to their own implementation (60ms), though these numbers may be outdated.
  • Urllib3 Maintenance: A maintainer of urllib3 noted that while Cloudflare contributed to the Pyodide/Emscripten support, the long-term maintenance burden falls on the upstream project. They cautioned that the Emscripten backend is still considered experimental and may exhibit different networking semantics than standard backends.
  • Resource Overhead: Community members have suggested that the Pyodide-based architecture likely increases memory consumption compared to a native V8 runtime.

"I'm glad the work was contributed upstream and is useful to Pyodide and Cloudflare. But I think there is a meaningful difference between funding a contribution to an upstream project and funding the upstream maintainers who have to support it afterwards."

Production-Ready Patterns

Cloudflare provides several examples of what can be build with Python Workers:

  • Asynchronous AI Orchestration: Image-to-image generators using Cloudflare Queues, Workflows, and Workers AI.
  • Real-time Stream Processing: WebSocket consumers for the Bluesky Jetstream using Durable Objects to maintain long-lived state.
  • MCP Servers: Deploying Model Context Protocol servers using the official Python MCP package.
  • RAG Systems: Building Retrieval-Augmented Generation systems using Workers AI and Vectorize.

Sources

Related

  • Dispatch
  • Project
  • Dispatch
  • Dispatch
  • Dispatch