<h1>gevent<aclass="headerlink"href="#gevent"title="Link to this heading">¶</a></h1>
<p>Prefer using <aclass="reference internal"href="gunicorn.html"><spanclass="doc">Gunicorn</span></a> or <aclass="reference internal"href="uwsgi.html"><spanclass="doc">uWSGI</span></a> with gevent workers rather
than using <aclass="reference external"href="https://www.gevent.org/">gevent</a> directly. Gunicorn and uWSGI provide much more
configurable and production-tested servers.</p>
<p><aclass="reference external"href="https://www.gevent.org/">gevent</a> allows writing asynchronous, coroutine-based code that looks
like standard synchronous Python. It uses <aclass="reference external"href="https://greenlet.readthedocs.io/en/latest/">greenlet</a> to enable task
switching without writing <codeclass="docutils literal notranslate"><spanclass="pre">async/await</span></code> or using <codeclass="docutils literal notranslate"><spanclass="pre">asyncio</span></code>.</p>
<p><aclass="reference internal"href="eventlet.html"><spanclass="doc">eventlet</span></a> is another library that does the same thing. Certain
dependencies you have, or other considerations, may affect which of the
two you choose to use.</p>
<p>gevent provides a WSGI server that can handle many connections at once
instead of one per worker process. You must actually use gevent in your
own code to see any benefit to using the server.</p>
<sectionid="installing">
<h2>Installing<aclass="headerlink"href="#installing"title="Link to this heading">¶</a></h2>
<p>When using gevent, greenlet>=1.0 is required, otherwise context locals
such as <codeclass="docutils literal notranslate"><spanclass="pre">request</span></code> will not work as expected. When using PyPy,
PyPy>=7.3.7 is required.</p>
<p>Create a virtualenv, install your application, then install <codeclass="docutils literal notranslate"><spanclass="pre">gevent</span></code>.</p>
<divclass="highlight-text notranslate"><divclass="highlight"><pre><span></span>$ cd hello-app
<divclass="code-block-caption"><spanclass="caption-text"><codeclass="docutils literal notranslate"><spanclass="pre">wsgi.py</span></code></span><aclass="headerlink"href="#id2"title="Link to this code">¶</a></div>
<h2>Binding Externally<aclass="headerlink"href="#binding-externally"title="Link to this heading">¶</a></h2>
<p>gevent should not be run as root because it would cause your
application code to run as root, which is not secure. However, this
means it will not be possible to bind to port 80 or 443. Instead, a
reverse proxy such as <aclass="reference internal"href="nginx.html"><spanclass="doc">nginx</span></a> or <aclass="reference internal"href="apache-httpd.html"><spanclass="doc">Apache httpd</span></a> should be used
in front of gevent.</p>
<p>You can bind to all external IPs on a non-privileged port by using
<codeclass="docutils literal notranslate"><spanclass="pre">0.0.0.0</span></code> in the server arguments shown in the previous section. Don’t
do this when using a reverse proxy setup, otherwise it will be possible
to bypass the proxy.</p>
<p><codeclass="docutils literal notranslate"><spanclass="pre">0.0.0.0</span></code> is not a valid address to navigate to, you’d use a specific