Home ยป Enhanced Python Support in Cloudflare Workers with FastAPI and Langchain Integration

Enhanced Python Support in Cloudflare Workers with FastAPI and Langchain Integration

Cloudflare has announced support for the Python language in its Cloudflare Workers service, which is a serverless platform of its own. Previously, only JavaScript and TypeScript languages were supported.
In reality, Workers already support WebAssembly, so any language that compiles to WebAssembly can be used, including Python. However, using unsupported platforms can be challenging, as configurations may not align properly.
Cloudflare leverages Pyodide framework directly compiled into workers. While various libraries can be written in the requirements.txt file, only libraries supported by Cloudflare can be used. Even the versions rely on the same versioning system as other parts of Workers. Despite limitations, there are many essential libraries available such as FastAPI, LangChain, NumPy, and sqlite for connecting with Workers’ APIs.
One downside of Python is that it starts slower than JavaScript, especially when loading large modules. Initial startup time may take more than 2 seconds. Cloudflare addresses this issue by preloading all modules into an image distributed to real servers, reducing cold start time to less than 1 second and expecting further reductions in the future.
Source: Cloudflare

TLDR: Cloudflare now supports Python in its serverless Cloudflare Workers service alongside JavaScript and TypeScript. Using WebAssembly, Python can be compiled and utilized, but some configurations may pose challenges. Cloudflare utilizes Pyodide framework for direct compilation and supports various essential libraries. Python’s slower startup compared to JavaScript is resolved by preloading modules into images distributed to servers, reducing cold start time to less than 1 second.

More Reading

Post navigation

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Transitioning from Skew to TypeScript: Figma’s Paradigm Shift

Unlock the Potential of Diablo 1: Play Through Your Web Browser Using File Conversion to WebAssembly

WinterJS Unveiled: A Revolutionary Real-Time Service Worker Runtime Initiative, Spearheaded by Wasmer