Skip to content

Commit 4ead64f

Browse files
committed
adds back in python workers content
1 parent bee8ada commit 4ead64f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/content/docs/workers/platform/infrastructure-as-code.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,37 @@ EOF
352352
</TabItem>
353353
</Tabs>
354354

355+
### Python Workers
356+
357+
[Python Workers](/workers/languages/python/) (open beta) have their own special `text/x-python` content type and `python_workers` compatibility flag for uploading using the multipart/form-data API.
358+
359+
```bash
360+
curl https://api.cloudflare.com/client/v4/accounts/<account_id>/workers/scripts/my-hello-world-script \
361+
-X PUT \
362+
-H 'Authorization: Bearer <api_token>' \
363+
-F 'metadata={
364+
"main_module": "my-hello-world-script.py",
365+
"bindings": [
366+
{
367+
"type": "plain_text",
368+
"name": "MESSAGE",
369+
"text": "Hello World!"
370+
}
371+
],
372+
"compatibility_date": "$today",
373+
"compatibility_flags": [
374+
"python_workers"
375+
]
376+
};type=application/json' \
377+
-F 'my-hello-world-script.py=@-;filename=my-hello-world-script.py;type=text/x-python' <<EOF
378+
from workers import WorkerEntrypoint, Response
379+
380+
class Default(WorkerEntrypoint):
381+
async def fetch(self, request):
382+
return Response(self.env.MESSAGE)
383+
EOF
384+
```
385+
355386
## Considerations with Durable Objects
356387

357388
[Durable Object](/durable-objects/) migrations are applied with deployments. This means you can't bind to a Durable Object in a Version if a deployment doesn't exist i.e. migrations haven't been applied. For example, running this in Terraform will fail the first time the plan is applied:

0 commit comments

Comments
 (0)