Skip to main content

WSGI adapter for aiohttp.

Project description


**aiohttp-wsgi** is a WSGI adapter for aiohttp.


- Run WSGI applications (e.g. Django, Flask) on `aiohttp <>`_.
- Handle thousands of client connections, using the latest `evented networking library <>`_.
- Add `websockets <>`_ to your
existing Python app!


1. Install using ``pip install aiohttp-wsgi``.


``middleware.wsgi(application, **kwargs)``

`Middleware factory <>`_ that wraps a WSGI application for use inside an aiohttp `Application <>`_.


from aiohttp.web import Application
from aiohttp_wsgi.middleware import wsgi
from your_app.wsgi import application

aiohttp_application = Application(middlewares=[

**Available arguments:**

The URL prefix to mount the WSGI application. Corresponds to ``environ["SCRIPT_NAME"]``. This should **not** end with a slash. Defaults to ``""``.

hint about the URL scheme used to access the application. Corresponds to ``environ["wsgi.uri_scheme"]``. Default value auto-detected to ``"http"`` or ``"https"``.

A file-like value for WSGI error logging. Corresponds to ``environ["wsgi.errors"]``. Defaults to ``sys.stderr``.

An `Executor <>`_ instance used to run WSGI requests. Defaults to the asyncio base executor.

The asyncio `loop <>`_. Defaults to ``asyncio.get_event_loop()``.

``configure_server(application, **kwargs)``

High-level factory method that wraps a WSGI application in an asyncio `server <>`_ and aiohttp `Application <>`_.


from aiohttp_wsgi import configure_server
from your_app.wsgi import application

server, app = configure_server(application)

**Available arguments:**

The IP address to bind the server. Defaults to ``""``.

The network port to bind the server. Defaults to ``8080``.

The path to a unix socket to bind the server. Overrides ``host``.

A set of filesystem permissions to apply to the unix socket. Defaults to ``0o600``.

A list of ``(method, path, handler)`` routes to add to the aiohttp `Application <>`_. Defaults to ``[]``.

A list of ``(path, dirname)`` static routes to add to the aiohttp `Application <>`_. Defaults to ``[]``.

``configure_server()`` also accepts all arguments available to ``middleware.wsgi()``.

``serve(application, **kwargs)``

High-level factory method that starts a `server <>`_ running a WSGI application.


from aiohttp_wsgi import serve
from your_app.wsgi import application


``serve()`` accepts all arguments available to ``configure_server()``.


WSGI applications are run on an asyncio `executor <>`_.
This allows existing Python frameworks like Django and Flask to run normally without
blocking the main event loop or resorting to hacks like monkey-patching the Python
standard library. This enables you to write the majority of your application code in a safe,
predictable environment.

Asyncronous parts of your application (e.g. `websockets <>`_)
can be run on the same network port, using the `aiohttp router <>`_
to switch between your WSGI app and asyncronous code.

Build status

This project is built on every push using the Travis-CI service.

.. image::

Support and announcements

Downloads and bug tracking can be found at the `main project
website <>`_.

More information

The aiohttp-wsgi project was developed by Dave Hall. You can get the code
from the `aiohttp-wsgi project site <>`_.

Dave Hall is a freelance web developer, based in Cambridge, UK. You can usually
find him on the Internet in a number of different places:

- `Website <>`_
- `Twitter <>`_
- `Google Profile <>`_

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aiohttp-wsgi, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size aiohttp-wsgi-0.1.1.tar.gz (6.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page