Repository navigation
Description
Summary
Define the supported Python Worker workflow for cf dev, cf build, and cf deploy, and agree how deeply cf should integrate with the existing workers-py / Pywrangler tooling.
Python execution and uploads do not inherently require the Wrangler CLI: Miniflare/workerd supports Python modules, and cf already consumes Python Build Output and uploads it through the shared deployment helpers. The missing work is connecting Python dependency preparation, build output, and the development loop.
This issue is for deciding that integration boundary before committing to a standalone Python delegate or a larger refactor of Pywrangler. Related: #56 tracks the cf dev implementation; #392 records the now-fixed upload bug for vendored Python modules.
Current behavior and gaps
known-impls.tslistscloudflare-py-dev-serverand recommends installing it. That package is not available on PyPI. The actual package isworkers-py, which exposes thepywranglerexecutable.- cf's Python discovery therefore ignores a normal
pyproject.tomldeclaringworkers-py. Running the discovery source against a representative manifest withworkers-py,workers-runtime-sdk, anduv.lockreturned no implementation. Adding a Wrangler dependency selected the Wrangler fallback instead. - That fallback invokes
cf-wranglerdirectly and does not run Pywrangler's dependency preparation. Projects whose dependencies have already been vendored can use the existing build/upload machinery, as demonstrated in cf deploy: Python Workers fail with 'No module named workers' because vendored modules are uploaded as ./python_modules/... #392; cf does not yet own a complete Python setup and refresh workflow. - The discovery tests currently use
cloudflare-py-dev-server, so they do not validate the real Python project shape. - Replacing the allowlist package name alone is insufficient: the distribution and executable names differ, and we need a defined
buildcontract that emits Build Output.
Existing pieces to reuse
workers-pysupplies thepywranglerexecutable.- Pywrangler dependency preparation resolves and vendors packages compatible with the selected Python/Pyodide runtime, including the Workers SDK.
- Miniflare/workerd can execute Python modules, so a Python dev implementation can use those runtime libraries directly.
- cf's Build Output adapter already handles Python module types and preserves vendored module paths. Deployment can remain on the existing cf upload path.
There are upstream coupling points to address. Pywrangler's CLI currently prepares dependencies and forwards dev/deploy commands to Wrangler. Its configuration utilities read Wrangler configuration to determine the compatible Python runtime; even pywrangler sync currently requires a Wrangler config.
Integration options to discuss
- Thin integration with existing Pywrangler commands. Reuse its current workflow, accepting Wrangler CLI/configuration coupling where needed. Establish what this delivers for cf dev and how build-only output would work.
- Reuse Python preparation with a cf-compatible adapter. Give the existing Python tooling an explicit preparation interface accepting project path, compatibility date/flags, and destination. Add a real delegate with
devandbuildcommands, using Miniflare/workerd directly and emitting Build Output for cf deployment. - Refactor shared Python tooling more broadly. Separate dependency preparation and project metadata handling from the Pywrangler CLI so both tools use the same supported primitives. Decide whether the additional upstream work is justified now.
These are alternatives for discussion, not a selected implementation. Avoid duplicating the Python resolver and package compatibility logic inside cf.
Decisions needed
- Is avoiding the legacy Wrangler CLI an initial requirement or a later milestone?
- Which responsibilities belong in
workers-py, shared build/runtime libraries, and cf's thin discovery/spawn adapter? Where should a real Python delegate live? - How should
cloudflare.config.ts, mode, and compatibility settings reach Python preparation without maintaining a second source of truth in a Wrangler config? - What supported public API or subprocess contract should expose dependency preparation? How are runtime/tool versions and lockfiles handled?
- How much of dev do we support initially: reloads, dependency changes, bindings, persistence, remote resources, and authentication?
- Should the invalid allowlist entry and installation guidance be removed or corrected independently while the integration is designed?
Follow-up implementation criteria
Once the boundary is agreed, capture the work in #56 and any build/preparation follow-ups:
- A real Python fixture declares the supported tooling and works with
cf dev,cf build, andcf deploy. - Cover a multi-module Worker, the vendored Workers SDK, and at least one supported third-party dependency.
- Exercise source reload, dependency refresh, bindings/configuration, actionable missing-tool errors, and clean shutdown across Windows, Linux, and macOS.
- Preserve the existing Build Output and deployment paths, lazy startup, and the repository's separation between project tooling and cf coordination.
Activity