Sign inConnect your agent
infochanged

Workers - Python Workers now support WSGI web frameworks like Django and Flask

Announced
Tags
Workers
Severity
info, set by reef/rss-rule-v1
Source
https://developers.cloudflare.com/changelog/post/2026-09-02-python-workers-web-framework-support/

<p>Python web frameworks following the <a href="https://peps.python.org/pep-3333/" target="_blank" rel="noopener">Web Server Gateway Interface (WSGI)<span class="external-link"> ↗︎</span></a> or <a href="https://asgi.readthedocs.io/" target="_blank" rel="noopener">Asynchronous Server Gateway Interface (ASGI)<span class="external-link"> ↗︎</span></a> specification can now be used in Python Workers.</p> <div tabindex="-1" class="heading-wrapper level-h4"><h4 id="using-web-frameworks-with-python-workers">Using web frameworks with Python Workers</h4><a class="anchor-link" href="#using-web-frameworks-with-python-workers"><span aria-hidden="true" class="anchor-icon"><svg width="16" height="16" viewBox="0 0 24 24"><path fill="currentcolor" d="m12.11 15.39-3.88 3.88a2.52 2.52 0 0 1-3.5 0 2.47 2.47 0 0 1 0-3.5l3.88-3.88a1 1 0 0 0-1.42-1.42l-3.88 3.89a4.48 4.48 0 0 0 6.33 6.33l3.89-3.88a1 1 0 1 0-1.42-1.42Zm8.58-12.08a4.49 4.49 0 0 0-6.33 0l-3.89 3.88a1 1 0 0 0 1.42 1.42l3.88-3.88a2.52 2.52 0 0 1 3.5 0 2.47 2.47 0 0 1 0 3.5l-3.88 3.88a1 1 0 1 0 1.42 1.42l3.88-3.89a4.49 4.49 0 0 0 0-6.33ZM8.83 15.17a1 1 0 0 0 1.1.22 1 1 0 0 0 .32-.22l4.92-4.92a1 1 0 0 0-1.42-1.42l-4.92 4.92a1 1 0 0 0 0 1.42Z"></path></svg></span></a></div> <p>Based on the web framework you are using, you can use either <code>wsgi</code> or <code>asgi</code> from the <code>workers</code> module.</p> <div tabindex="-1" class="heading-wrapper level-h4"><h4 id="wsgi-frameworks">WSGI frameworks</h4><a class="anchor-link" href="#wsgi-frameworks"><span aria-hidden="true" class="anchor-icon"><svg width="16" height="16" viewBox="0 0 24 24"><path fill="currentcolor" d="m12.11 15.39-3.88 3.88a2.52 2.52 0 0 1-3.5 0 2.47 2.47 0 0 1 0-3.5l3.88-3.88a1 1 0 0 0-1.42-1.42l-3.88 3.89a4.48 4.48 0 0 0 6.33 6.33l3.89-3.88a1 1 0 1 0-1.42-1.42Zm8.58-12.08a4.49 4.49 0 0 0-6.33 0l-3.89 3.88a1 1 0 0 0 1.42 1.42l3.88-3.88a2.52 2.52 0 0 1 3.5 0 2.47 2.47 0 0 1 0 3.5l-3.88 3.88a1 1 0 1 0 1.42 1.42l3.88-3.89a4.49 4.49 0 0 0 0-6.33ZM8.83 15.17a1 1 0 0 0 1.1.22 1 1 0 0 0 .32-.22l4.92-4.92a1 1 0 0 0-1.42-1.42l-4.92 4.92a1 1 0 0 0 0 1.42Z"></path></svg></span></a></div> <p>For WSGI frameworks like Django or Flask:</p> <figure class="nb-code-figure" data-nb-lang="python"><pre class="astro-code astro-code-themes github-light github-dark nb-shiki-c6xiwz" tabindex="0" data-language="python" data-nb-lang="python"><code><span class="line"><span class="nb-shiki-1itgoe">from</span><span class="nb-shiki-140thh"> workers </span><span class="nb-shiki-1itgoe">import</span><span class="nb-shiki-140thh"> wsgi</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-1itgoe">from</span><span class="nb-shiki-140thh"> django.core.wsgi </span><span class="nb-shiki-1itgoe">import</span><span class="nb-shiki-140thh"> get_wsgi_application</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-140thh">app </span><span class="nb-shiki-1itgoe">=</span><span class="nb-shiki-140thh"> get_wsgi_application()</span></span> <span class="line"><span class="nb-shiki-140thh">Default </span><span class="nb-shiki-1itgoe">=</span><span class="nb-shiki-140thh"> wsgi.entrypoint(app)</span></span></code></pre></figure> <p>The <code>wsgi.entrypoint</code> is equivalent to creating a <code>WorkerEntrypoint</code> class and using the <code>wsgi.fetch</code> method. If you want more control over the <code>WorkerEntrypoint</code> class, you can do so:</p> <figure class="nb-code-figure" data-nb-lang="python"><pre class="astro-code astro-code-themes github-light github-dark nb-shiki-c6xiwz" tabindex="0" data-language="python" data-nb-lang="python"><code><span class="line"><span class="nb-shiki-1itgoe">from</span><span class="nb-shiki-140thh"> workers </span><span class="nb-shiki-1itgoe">import</span><span class="nb-shiki-140thh"> wsgi, WorkerEntrypoint</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-1itgoe">class</span><span class="nb-shiki-1t8gfj"> Default</span><span class="nb-shiki-140thh">(</span><span class="nb-shiki-1t8gfj">WorkerEntrypoint</span><span class="nb-shiki-140thh">):</span></span> <span class="line"><span class="nb-shiki-1itgoe"> async</span><span class="nb-shiki-1itgoe"> def</span><span class="nb-shiki-1t8gfj"> fetch</span><span class="nb-shiki-140thh">(self, request):</span></span> <span class="line"><span class="nb-shiki-1itgoe"> return</span><span class="nb-shiki-1itgoe"> await</span><span class="nb-shiki-140thh"> wsgi.fetch(app, request, </span><span class="nb-shiki-dzsirb">self</span><span class="nb-shiki-140thh">.env)</span></span></code></pre></figure> <div tabindex="-1" class="heading-wrapper level-h4"><h4 id="asgi-frameworks">ASGI frameworks</h4><a class="anchor-link" href="#asgi-frameworks"><span aria-hidden="true" class="anchor-icon"><svg width="16" height="16" viewBox="0 0 24 24"><path fill="currentcolor" d="m12.11 15.39-3.88 3.88a2.52 2.52 0 0 1-3.5 0 2.47 2.47 0 0 1 0-3.5l3.88-3.88a1 1 0 0 0-1.42-1.42l-3.88 3.89a4.48 4.48 0 0 0 6.33 6.33l3.89-3.88a1 1 0 1 0-1.42-1.42Zm8.58-12.08a4.49 4.49 0 0 0-6.33 0l-3.89 3.88a1 1 0 0 0 1.42 1.42l3.88-3.88a2.52 2.52 0 0 1 3.5 0 2.47 2.47 0 0 1 0 3.5l-3.88 3.88a1 1 0 1 0 1.42 1.42l3.88-3.89a4.49 4.49 0 0 0 0-6.33ZM8.83 15.17a1 1 0 0 0 1.1.22 1 1 0 0 0 .32-.22l4.92-4.92a1 1 0 0 0-1.42-1.42l-4.92 4.92a1 1 0 0 0 0 1.42Z"></path></svg></span></a></div> <p>For ASGI frameworks like FastAPI or Starlette:</p> <figure class="nb-code-figure" data-nb-lang="python"><pre class="astro-code astro-code-themes github-light github-dark nb-shiki-c6xiwz" tabindex="0" data-language="python" data-nb-lang="python"><code><span class="line"><span class="nb-shiki-1itgoe">from</span><span class="nb-shiki-140thh"> workers </span><span class="nb-shiki-1itgoe">import</span><span class="nb-shiki-140thh"> asgi</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-1itgoe">from</span><span class="nb-shiki-140thh"> fastapi </span><span class="nb-shiki-1itgoe">import</span><span class="nb-shiki-140thh"> FastAPI</span></span> <span class="line"></span> <span class="line"><span class="nb-shiki-140thh">app </span><span class="nb-shiki-1itgoe">=</span><span class="nb-shiki-140thh"> FastAPI()</span></span> <span class="line"><span class="nb-shiki-140thh">Default </span><span class="nb-shiki-1itgoe">=</span><span class="nb-shiki-140thh"> asgi.entrypoint(app)</span></span></code></pre></figure> <p>For more information about using individual web frameworks, refer to the <a href="https://developers.cloudflare.com/workers/languages/python/packages/">packages documentation in Python Workers</a>.</p>

The text above is the source's. reef added the severity, the dates it could read from the text, and the endpoints and scopes named in code.