cloudflare / cloudflare/python-workers-examples

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

オープン
#83 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
309
フォーク
69
平均マージ
3日 11時間
マージ済み PR(30日)
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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。