Worker Languages

Lesson 8 · Cloudflare Workers · ~8 minutes

Workers aren't JavaScript-only. The runtime is polyglot — you can write Workers in several languages, each with different trade-offs. Here's what's available and when you'd pick each one.

First-Class Languages

These have official Cloudflare support with dedicated tooling and documentation:

LanguageMaturityToolingBest For
JavaScript Stable ✅ Wrangler CLI Most use cases. Largest ecosystem, most examples, fastest iteration.
TypeScript Stable ✅ Wrangler CLI Same as JS but with type safety. Recommended for anything non-trivial.
Python Beta 🧪 pywrangler CLI Data processing, AI/ML pipelines, teams that know Python better than JS.
Rust Beta 🧪 Wrangler + workers-rs crate Performance-critical code, existing Rust codebases, CPU-bound work within the 10ms limit.

JavaScript / TypeScript

The default and most mature option. All Cloudflare examples and tutorials use JS/TS. The runtime supports modern ES modules, Web APIs (fetch, crypto, streams), and partial Node.js compatibility.

// JavaScript — the simplest possible Worker
export default {
  async fetch(request, env, ctx) {
    return new Response("Hello from JavaScript!");
  },
};
// TypeScript — same thing, with types
export interface Env {
  MY_KV: KVNamespace;
}

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    const value = await env.MY_KV.get("key");
    return new Response(value ?? "not found");
  },
};
TypeScript is Zero-Config

When you scaffold a project with npm create cloudflare and choose TypeScript, Wrangler handles transpilation automatically. No tsconfig.json tweaking required — it just works.

Python

Python Workers let you write 100% Python — no JavaScript glue code. They support popular packages like FastAPI, Langchain, and Pydantic, and can access all Workers bindings (KV, D1, R2, etc.) via a foreign function interface.

# Python — a simple Worker
from workers import WorkerEntrypoint, Response

class Default(WorkerEntrypoint):
    async def fetch(self, request):
        return Response("Hello from Python!")
# Python with FastAPI
from workers import WorkerEntrypoint
from workers.fastapi import create_app
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello from FastAPI on Workers!"}

class Default(WorkerEntrypoint):
    fetch = create_app(app)

Python Setup

# Install uv (Python package manager) if you don't have it
curl -LsSf https://astral.sh/uv/install.sh | sh

# Scaffold a Python Worker project
uvx --from workers-py pywrangler init

# Run locally
uv run pywrangler dev

# Deploy
uv run pywrangler deploy
Python Workers Are in Beta

Python support works and is actively developed, but you may hit edge cases. The standard library is partially available — check the supported modules list. For production stability, JavaScript/TypeScript is still the safer choice.

Rust

Rust compiles to WebAssembly (Wasm) and runs in the Workers runtime. It gives you maximum performance per CPU millisecond — useful when you're bumping against the 10ms limit and need to squeeze more work in.

// Rust — a simple Worker
use worker::*;

#[event(fetch)]
async fn main(req: Request, env: Env, ctx: Context) -> Result<Response> {
    Response::ok("Hello from Rust!")
}
// Rust with routing
use worker::*;

#[event(fetch)]
async fn main(req: Request, env: Env, ctx: Context) -> Result<Response> {
    let router = Router::new();

    router
        .get("/", |_, _| Response::ok("Home"))
        .get_async("/api/data", |_, ctx| async move {
            let kv = ctx.kv("MY_KV")?;
            let value = kv.get("key").text().await?;
            Response::ok(value.unwrap_or_default())
        })
        .run(req, env)
        .await
}

Rust Setup

# Prerequisites
rustup target add wasm32-unknown-unknown
cargo install cargo-generate

# Scaffold a Rust Worker project
cargo generate cloudflare/workers-rs

# Run locally
npx wrangler dev

# Deploy
npx wrangler deploy
When Rust Makes Sense

Rust Workers are faster per CPU cycle than JavaScript, but slower to develop. Use Rust when: you need maximum computation in 10ms, you're processing binary data (images, protobuf), or you already have Rust logic to reuse. For APIs and CRUD, JavaScript/TypeScript is more productive.

WebAssembly (Other Languages)

Because Workers run Wasm, any language that compiles to WebAssembly can theoretically work. The experience varies:

LanguageCompiles to Wasm?Practical?Notes
GoYes (TinyGo)⚠️ ExperimentalUse TinyGo (not standard Go). Large binary sizes, limited stdlib.
C / C++Yes (Emscripten)⚠️ ExperimentalWorks for compute-heavy tasks. No official Cloudflare SDK.
KotlinYes (Kotlin/Wasm)⚠️ ExperimentalKotlin/Wasm is still maturing. Large output size.
C# / .NETYes (Blazor WASI)⚠️ ExperimentalPossible but heavy. Not recommended for Workers.
ZigYes⚠️ ExperimentalSmall binaries. No official SDK but people have made it work.
The Practical Answer

For most people: use TypeScript. It has the best tooling, the most examples, full access to all bindings, and is the default path Cloudflare optimizes for. Switch to Python if your team is Python-native, or Rust if you need raw performance.

Decision Matrix

If you want...Use
Fastest development, most examplesTypeScript
Quick prototypes, minimal ceremonyJavaScript
Data science / ML / FastAPI patternsPython
Maximum CPU performance per msRust
Existing codebase in another languageWasm (via that language's compiler)

Same Free Tier, Any Language

The free tier limits are identical regardless of language:

The only practical difference: Rust/Wasm Workers tend to use less CPU time per request (faster execution), which means you get more done within the 10ms budget.

You have a team of Python developers who want to build an API on Workers. What's the best approach?
Correct! Python Workers have first-class support, including FastAPI, Pydantic, and access to all bindings. While still in beta, it's the right choice for a Python-native team building an API.
Not quite. While JavaScript is more mature, Python Workers now have official support with FastAPI and full binding access — making them the natural choice for Python teams.
📖 Primary Source

Workers Languages — Cloudflare Docs — official documentation for all supported languages, including setup guides and API references for each.

💬 Questions? Ask me about setting up a specific language, performance comparisons, or migrating existing code to Workers. For example: "Can I use numpy in Python Workers?" or "How big can a Rust Wasm binary be?"
← Back