Cloudflare updates Workers platform with Python support, event notifications, and improved local development

Cloudflare updates Workers platform with Python support, event notifications, and improved local development

Cloudflare has updated its serverless Workers platform with new features including Python support, event notifications from R2 storage, and improved local development support integrated with popular front-end frameworks.

The Workers platform uses the V8 JavaScript engine, also used by Chromium and Node.js, taking advantage of the V8’s isolate feature for lightweight code environments. When combined with the Cloudflare content delivery network, this forms a cost-effective serverless platform for applications. The company states that 2 million developers are now building on the platform.

V8 has native support for JavaScript and WebAssembly, so in principle the platform can run any language that compiles to WebAssembly, including Rust and C or C++. Cloudflare has now added official Python support, but rather than simply compiling Python to WebAssembly, it has built Pyodide, a port of CPython to WebAssembly, into workerd, the Workers runtime. This support is now in beta.

Cold start time is an issue for Pyodide. “Pyodide itself is 6.4MB – and Python packages can also be quite large” observes the official Cloudflare post. In order to mitigate this, Cloudflare prepares a Worker when it is deployed and snapshots its memory. This snapshot is then loaded when requests are received, taking cold start to “below 1 second,” according to the post. The team expects this to reduce further during 2024, by using shared snapshots of the Pyodide environment. 

Choosing a framework for a Cloudflare Workers application

The introduction of first-class Python support is one of several new Workers features introduced this week as part of Cloudflare’s developer week 2024.

Now in open beta is event notifications for R2, Cloudflare’s storage service. Each time there is a change to the data, an event can be received by a Cloudflare Queue, and then received by a Worker to take further actions as needed. The company plans to add further events types in future, including changes to key-value pairs in a Workers KV database, updates to a D1 SQL database, and deployments to Cloudflare Workers.

There is also a new upcoming storage ingestion service called Pipelines, with support for streaming data to HTTP, WebSocket or Apache Kafka endpoints. This will be coming to open beta later in 2024.

Cloudflare has also been working on the local development experience. The idea is to enable use of the local development server provided with frameworks like Next.js while still supporting Cloudflare-specific APIs. This has been made possible by proxying access to Miniflare, a local Cloudflare emulator, from a Node.js host. Supported frameworks include Astro, Next.js, Nuxt, Qwik, Remix, SolidStart and SvelteKit.

Local development using a proxy to support Cloudflare APIs

On the AI front, Workers AI, which includes GPU support, is now generally available – and AI developers will likely appreciate the new Python support too. There are also cost reductions on some models and a revised AI dashboard and AI playground, with usage analytics and price prediction. Additional models are now supported, including Anthropic, Google Vertex, and Perplexity.

The advantage Cloudflare Workers has over hosting services such as Vercel, Netlify or Deno Deploy is that Cloudflare has its own infrastructure, enabling lower prices. The limitation is that everything runs on V8 isolates; but compatibility is improving. Regarding Python support, Cloudflare engineer Hood Chatham remarked that “there’s an 80/20 rule here. Most packages are not very hard to port, and generally the ones that are hard to build use features like threads and multiprocessing, graphics cards, raw sockets, green threads, or other capabilities that have no obvious analogue in a webassembly runtime.”