Skip to main content

Cloudflare Workers Python native SDK and builder toolkit

Project description

EdgeKit: Cloudflare Workers Python native SDK and builder toolkit

EdgeKit has two jobs:

  1. Provide a small Python-first API for writing Workers Python.
  2. Build a runtime bundle by analyzing your project, tree-shaking, vendoring dependencies.

What EdgeKit Provides

  • WorkerEntrypoint[Env] for typed Worker classes
  • Request, Response, Headers, and URL wrappers around the Workers Web APIs
  • Typed binding wrappers for:
    • static assets
    • D1
    • KV
    • R2
    • Queues
    • Durable Objects
  • WSGI and ASGI adapters for framework integration
  • A CLI for:
    • project analysis
    • risk checks for tree-shaking and bundling
    • bundle emission
    • report rendering

Requirements

  • Python >=3.12
  • uv for dependency management
  • wrangler CLI for development and deployment

Local Development

Install Python and Node dependencies in the repository root:

uv sync

Useful commands:

edgekit analyze
edgekit doctor
edgekit build
npm run dev

The root wrangler.jsonc should be configured to call edgekit build before wrangler dev.

Quick Start

Initialize a new project first:

uv run pywrangler init
cd <your-project>
uv add edgekit

The minimal Worker shape looks like this:

from edgekit import Request, Response, WorkerEntrypoint


class Default(WorkerEntrypoint):
    async def fetch(self, request: Request) -> Response:
        return Response.json(
            {
                "ok": True,
                "method": request.method,
                "pathname": request.url.pathname,
            }
        )

Set the Worker entrypoint in pyproject.toml:

[tool.edgekit.builder]
entry = "src/app.py"
compatibility_date = "2026-04-13"

Then point Wrangler at the built output:

{
  "main": "build/edgekit/wrangler/python_modules/app.py",
  "compatibility_date": "2026-04-13",
  "compatibility_flags": ["python_workers"],
  "build": {
    "command": "uv run edgekit build",
  },
}

Run:

wrangler dev

Typed Environment Bindings

EdgeKit can bind the Workers env object to a typed Python protocol or class.

from typing import Protocol

from edgekit import Request, Response, WorkerEntrypoint
from edgekit.bindings import D1Database, StaticAssets


class Env(Protocol):
    ASSETS: StaticAssets
    DB: D1Database


class Default(WorkerEntrypoint[Env]):
    async def fetch(self, request: Request) -> Response:
        ok = await self.env.DB.prepare("select 1 as ok").first("ok", type=int)
        asset = await self.env.ASSETS.fetch("/hello.txt")
        return Response.json(
            {
                "ok": ok if ok is not None else 0,
                "asset": await asset.read_text(),
            }
        )

Runtime Helpers

edgekit.runtime exports two helpers:

  • current_env([EnvType])
    • Returns the active env object for the current request scope.
    • Used by adapters such as WSGI and ASGI to expose the current Worker env inside framework code.
  • await_sync(awaitable)
    • Runs an awaitable synchronously via Pyodide runtime bindings.

Example:

from typing import Protocol

from edgekit.adapters import WSGI
from edgekit.bindings import StaticAssets
from edgekit.runtime import await_sync, current_env


class Env(Protocol):
    ASSETS: StaticAssets


def read_asset_text(path: str) -> str:
    env = current_env(Env)
    response = await_sync(env.ASSETS.fetch(path))
    return await_sync(response.read_text())

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

edgekit-0.1.1.tar.gz (104.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

edgekit-0.1.1-py3-none-any.whl (80.8 kB view details)

Uploaded Python 3

File details

Details for the file edgekit-0.1.1.tar.gz.

File metadata

  • Download URL: edgekit-0.1.1.tar.gz
  • Upload date:
  • Size: 104.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for edgekit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a23810a4cf5b50e11359fb637c73fe8d2f18aaa089f669b7c8512ad2c580d8d3
MD5 fcb7d97059bf1f2c5adfa260a3064111
BLAKE2b-256 dfc7f5578ce6587dbf4f9c64690e7079f75ca19c4337b8394e792803b6859da5

See more details on using hashes here.

File details

Details for the file edgekit-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: edgekit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 80.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for edgekit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5de7ea5cae5eab72310b62d104a20ece2ae9bdc25b4898ddd5f518e26d568ad2
MD5 c43f21e37a6639d59ff55cf175fd1de6
BLAKE2b-256 3789cda88c8094a667b9a64f8a6497f52baed52486a89436cc55b66dd2182171

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page