Work with JavaScript objects, methods, functions and globals from Python Workers · Cloudflare Workers docs | Latest TMZ Celebrity News & Gossip | Watch TMZ Live Skip to content
Cloudflare Docs

Foreign Function Interface (FFI)

Via Pyodide, Python Workers provide a Foreign Function Interface (FFI) to JavaScript. This allows you to:

The details of Pyodide's Foreign Function Interface are documented here, and Workers written in Python are able to take full advantage of this.

Using Bindings from Python Workers

Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform. When you declare a binding on your Worker, you grant it a specific capability, such as being able to read and write files to an R2 bucket.

For example, to access a KV namespace from a Python Worker, you would declare the following in your Worker's Wrangler configuration file:

{
"main": "./src/index.py",
"kv_namespaces": [
{
"binding": "FOO",
"id": "<YOUR_KV_NAMESPACE_ID>"
}
]
}

...and then call .get() on the binding object that is exposed on env:

from workers import Response
async def on_fetch(request, env):
await env.FOO.put("bar", "baz")
bar = await env.FOO.get("bar")
return Response(bar) # returns "baz"

Under the hood, env is actually a JavaScript object. When you call .FOO, you are accessing this property via a JsProxy — special proxy object that makes a JavaScript object behave like a Python object.

Using JavaScript globals from Python Workers

When writing Workers in Python, you can access JavaScript globals by importing them from the js module. For example, note how Response is imported from js in the example below:

from js import Response
def on_fetch(request):
return Response.new("Hello World!")

Refer to the Python examples to learn how to call into JavaScript functions from Python, including console.log and logging, providing options to Response, and parsing JSON.

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.