cloudflare / cloudflare/python-workers-examples

Please add examples about how to bundle python dependencies in dynamic worker

未关闭
#83 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
309
派生
69
平均合并
3 天 11 小时
30 天内合并 PR
13

描述

https://github.com/cloudflare/python-workers-examples/pull/82

shows how to call python dynamic worker from a python worker. I tried to rewrite this to typescript to python dynamic worker, my steps are as follows:

```shell
npm create cloudflare@latest -- my-first-worker
```

choose the typescript template, then edit `src/index.ts`

```ts
const DYNAMIC_WORKER_SOURCE = `
from workers import Response, WorkerEntrypoint

class Default(WorkerEntrypoint):
async def fetch(self, request):
result = 2**10
return Response("Hello from a dynamically-loaded Python Worker! " + str(result))
`

export default {
async fetch(request, env, ctx): Promise {
const worker = env.LOADER.load({
compatibilityDate: "2026-05-01",
"compatibilityFlags": ["python_workers"],
mainModule: "entry.py",
modules: {
"entry.py": DYNAMIC_WORKER_SOURCE,
},
// Block all outbound network access
globalOutbound: null,
});
const result = await worker.getEntrypoint().fetch(request);
const text = await result.text();
console.log("Result from dynamically-loaded Python Worker:", text);
// return result;

return new Response("Hello World!" + text);
},
} satisfies ExportedHandler;

```

This demo works, but I want to know how can I bundle python dependencies to this worker, the docs https://developers.cloudflare.com/dynamic-workers/getting-started/ says use `@cloudflare/worker-bundler` but it doesn't support python worker

贡献指南

打开贡献指南

调研方向

Compare PR #82 with the dynamic-workers getting-started documentation and inspect the `src/index.ts` example in the issue. Investigate how `@cloudflare/worker-bundler` relates to Python Workers, then add an example that demonstrates the supported dependency-bundling workflow and verify that the documented steps work.

由索引模型根据 Issue 内容生成。

评估

技术栈
python, typescript
领域
documentation
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。