Repository navigation
feat(cloudflare/workers): Python Workers (main: worker.py) - #861
Merged
Merged
Conversation
Monorepo-in-monorepo, same as distilled: cloudflare-tools/packages/* join the bun workspace (catalog pins for @distilled.cloud/cloudflare-runtime, -rolldown-plugin, -vite-plugin become workspace:*), its packages are referenced from the root and packages/alchemy tsconfigs, and the root build drives their build scripts. Co-Authored-By: Claude Fable 5 <[email protected]>
A .py entry deploys a Python Worker: no bundling — the entry plus sibling .py files upload as text/x-python modules, python_workers is appended to the compatibility flags, and dependencies are vendored with uv (pyproject.toml -> pylock.toml -> emscripten cross-venv -> python_modules/) against the Pyodide wheel index, mirroring pywrangler. A prebuilt python_modules/ directory (e.g. from pywrangler sync) is uploaded as-is without invoking uv. Local dev serves the same module graph through workerd's built-in Pyodide (PythonModule module type) with a filesystem watcher in place of the rolldown watch stream. Co-Authored-By: Claude Fable 5 <[email protected]>
CI runs `bun tsc -b` right after `bun install`; alchemy's typecheck resolves @distilled.cloud/cloudflare-runtime types from its tsdown-built dist/, so the prepare hook builds the submodule packages after every install. Co-Authored-By: Claude Fable 5 <[email protected]>
Contributor
|
Install the packages built from this commit: alchemy bun add alchemy@https://pkg.ing/alchemy/dfaff80@alchemy.run/better-auth bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/dfaff80@alchemy.run/pr-package bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/dfaff80 |
The runtime's tsdown dts generation resolves @distilled.cloud/cloudflare types from distilled's lib/; on a cold install (CI) that lib doesn't exist yet and the annotated Credentials requirement degraded to any. Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
…Python Workers Encodes the supported-package surface in one live fixture: fastapi served via the runtime asgi module, pydantic request validation, numpy (compiled emscripten-wasm32 wheel — proves vendored binary wheels match the deployed Pyodide ABI), httpx async outbound HTTP, and env bindings threaded through request.scope. Adds the ASGI/FastAPI pattern to the Python Workers guide. Co-Authored-By: Claude Fable 5 <[email protected]>
sam-goodwin
added a commit
that referenced
this pull request
Oct 9, 2026
…ith exports Point distilled at main for exports on dispatch uploads (#860) and the dispatch_namespace field on namespace listings (#861). Dispatch user Workers now upload exports instead of migrations, which removes the migration-tag bookkeeping and its error-message recovery. Namespace listings are scoped to the Worker's own context, so an account Worker and a dispatch Worker with the same script name no longer see each other's classes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Deploy Cloudflare Python Workers by pointing
mainat a.pyfile, and embed cloudflare-tools as a git submodule workspace (same monorepo-in-monorepo setup as distilled).Docs: new Python Workers guide (
website/src/content/docs/cloudflare/compute/python-workers.mdx) +@section Python Workerson the Worker JSDoc.Usage
A Python Worker is a regular
Cloudflare.Workerwhosemainis a.pyfile. It is always an external (async-style) Worker — no inline Effect implementation — and bindings are declared withenv:Dependencies come from a
pyproject.tomlnext to the entry, vendored with uv (>= 0.8.10) on deploy:Python version follows the compatibility date/flags (3.13 for dates >= 2025-09-29 — the default;
no_python_workers_20250116pins 3.12), selecting the matching uv interpreter (cpython-3.1x-emscripten-wasm32-musl) and Pyodide wheel index.alchemy devserves the same module graph from local workerd (built-in Pyodide), rebuilding on.py/pyproject.tomlchanges.How it works
.pyentry skips rolldown entirely: the entry plus every sibling.pyfile upload astext/x-pythonmodules (main_module= the entry), andpython_workersis appended to the compatibility flags. An inline Effect implementation is a deploy-time error.uv pip compileagainst the Pyodide wheel index →pylock.toml→uv pip install --no-buildinto an emscripten cross-venv →site-packagesuploads aspython_modules/<relpath>(application/octet-stream; theworkers-runtime-sdkJS shims underpython_modules/workers/as ESM). Cached under.alchemy/python/on the pyproject hash; the managedworkers-runtime-sdkpackage is always included.python_modules/directory (e.g. frompywrangler sync) is uploaded as-is without invoking uv — the escape hatch for externally-managed deps..py→PythonModule/ vendored files →Datafor workerd, with a filesystem watcher replacing the rolldown watch stream.Verified live (
test/Cloudflare/Workers/PythonWorker.test.ts,PythonWorkerLocal.test.ts): multi-module deploy with env bindings, uv-vendoredhumanizeimportable at runtime, and local workerd serving — plus a clean run of the existing Worker/PrebuiltWorker suites.cloudflare-tools submodule
cloudflare-tools/packages/*(+vendor/*,tools/*) join the bun workspace; the catalog pins for@distilled.cloud/cloudflare-runtime,-rolldown-plugin,-vite-pluginbecomeworkspace:*, and their named catalogs (effect,workers) merge into the root manifest.packages/alchemytsconfigs reference the submodule's composite leaf configs; thepreparehook builds distilled's cloudflare lib then the cloudflare-tools dists on every install (the runtime has nobunexport condition, so its tsdowndist/must exist for type-checking).RemoteWorkerdts), which this monorepo'stsc -bsurfaced.🤖 Generated with Claude Code