Python Workers handlers now live in an entrypoint class
We are changing how Python Workers are structured by default. Previously, handlers were defined at the top-level of a module as on_fetch
, on_scheduled
, etc. methods, but now they live in an entrypoint class.
Here's an example of how to now define a Worker with a fetch handler:
from workers import Response, WorkerEntrypoint
class Default(WorkerEntrypoint): async def fetch(self, request, env, ctx): return Response("Hello World!")
To keep using the old-style handlers, you can specify the disable_python_no_global_handlers
compatibility flag in your wrangler file:
{ "compatibility_flags": [ "disable_python_no_global_handlers" ]}
compatibility_flags = [ "disable_python_no_global_handlers" ]
Consult the Python Workers documentation for more details.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-