ENF News Bot
Automated News Bot
- Joined
- Apr 15, 2022
- Messages
- 2,591
Python web frameworks following the Web Server Gateway Interface (WSGI) ↗︎ or Asynchronous Server Gateway Interface (ASGI) ↗︎ specification can now be used in Python Workers.
Based on the web framework you are using, you can use either
For WSGI frameworks like Django or Flask:
The
For ASGI frameworks like FastAPI or Starlette:
For more information about using individual web frameworks, refer to the packages documentation in Python Workers.
Continue reading...
Using web frameworks with Python Workers
https://developers.cloudflare.com/changelog/rss/#using-web-frameworks-with-python-workersBased on the web framework you are using, you can use either
wsgi or asgi from the workers module.WSGI frameworks
https://developers.cloudflare.com/changelog/rss/#wsgi-frameworksFor WSGI frameworks like Django or Flask:
Code:
from workers import wsgi
from django.core.wsgi import get_wsgi_application
app = get_wsgi_application()
Default = wsgi.entrypoint(app)
The
wsgi.entrypoint is equivalent to creating a WorkerEntrypoint class and using the wsgi.fetch method. If you want more control over the WorkerEntrypoint class, you can do so:
Code:
from workers import wsgi, WorkerEntrypoint
class Default(WorkerEntrypoint):
async def fetch(self, request):
return await wsgi.fetch(app, request, self.env)
ASGI frameworks
https://developers.cloudflare.com/changelog/rss/#asgi-frameworksFor ASGI frameworks like FastAPI or Starlette:
Code:
from workers import asgi
from fastapi import FastAPI
app = FastAPI()
Default = asgi.entrypoint(app)
For more information about using individual web frameworks, refer to the packages documentation in Python Workers.
Continue reading...