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``.


``WSGIHandler(application, **kwargs)``

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


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

aiohttp_application = Application()
wsgi_handler = WSGIHandler(application)
aiohttp_application.router.add_route("*", "/{path_info:.*}", wsgi_handler.handle_request)

**Available arguments:**

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 preexisting socket object to use for the server. Overrides ``host``.

The maximum number of queued connections for the socket. Defaults to ``1024``.

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 ``[]``.

A list of callbacks to be executed when the server shuts down. Each callback will be passed the aiohttp `Application <>`_.

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

``configure_server()`` also accepts all arguments available to ``WSGIHandler()``.

``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.3.0
Filename, size File type Python version Upload date Hashes
Filename, size aiohttp-wsgi-0.3.0.tar.gz (9.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page