Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Cloudflare Docs
Log in

Cloudflare Workers provides a first-class Python experience, including support for:

Introduction

A Python Worker can be as simple as four lines of code:

Python
from workersimport WorkerEntrypoint, Response
classDefault(WorkerEntrypoint):
asyncdeffetch(self,request):
returnResponse("Hello World!")

Similar to other Workers, the main entry point for a Python worker is thefetch handler which handles incoming requestssent to the Worker.

In a Python Worker, this handler is placed in aDefault class that extends theWorkerEntrypoint class (which you can import from theworkers SDK module).

Thepywrangler CLI tool

To run a Python Worker locally, install packages, and deploy it to Cloudflare, you usepywrangler,the CLI for Python Workers.

To set it up, first, ensureuv andNode are installed.

Then set up your development environment:

uv init
uv tool install workers-py
uv run pywrangler init

This will create apyproject.toml file withworkers-py as a developmentdependency.pywrangler init will create a wrangler config file. You can thenrunpywrangler with:

Terminal window
uvrunpywranglerdev

To deploy a Python Worker to Cloudflare, runpywrangler deploy:

Terminal window
uvrunpywranglerdeploy

Python Worker Templates

When you initialize a new Python Worker project and select from one of many templates:

Terminal window
uvrunpywranglerinit

Or you can clone the examples repository to explore more options:

Terminal window
gitclonehttps://github.com/cloudflare/python-workers-examples
cdpython-workers-examples/01-hello

Next Up


[8]
ページ先頭

©2009-2026 Movatter.jp