Skip to main content

http client/server for asyncio

Project description

Async http client/server framework

aiohttp logo

Major aiohttp2.0 release!

Warning! This is not final release. It contains backward incompatible change, please check compatibility before installing on production systems.

For this release we completely refactored low-level implementation of http handling. Finally uvloop gives performance improvement. Overall performance improvement should be around 70-90% compared to 1.x version.

We took opportunity to refactor long standing api design problem across whole package. Client exceptions handling has been cleaned up and now much more strait forward. Client payload management simplified and allows to extends with any custom types. Client collection pool implementation has been redesigned as well, now there is no need for actively releasing responses, aiohttp handles connection release automatically.

Another major change, we moved aiohttp development to public organization The aiohttp community would like to thank Keepsafe ( for it’s support in the early days of the project.

Alas we had to make backward incompatible changes. Please check this migration document

Please report problems or annoyance with with api to

You can install and test this release with:

pip install


  • Supports both client and server side of HTTP protocol.

  • Supports both client and server Web-Sockets out-of-the-box.

  • Web-server has middlewares and pluggable routing.

Getting started


To retrieve something from the web:

import aiohttp
import asyncio

async def fetch(session, url):
    with aiohttp.Timeout(10, loop=session.loop):
        async with session.get(url) as response:
            return await response.text()

async def main(loop):
    async with aiohttp.ClientSession(loop=loop) as session:
        html = await fetch(session, '')

if __name__ == '__main__':
    loop = asyncio.get_event_loop()


This is simple usage example:

from aiohttp import web

async def handle(request):
    name = request.match_info.get('name', "Anonymous")
    text = "Hello, " + name
    return web.Response(text=text)

async def wshandler(request):
    ws = web.WebSocketResponse()
    await ws.prepare(request)

    async for msg in ws:
        if msg.type == web.MsgType.text:
            await ws.send_str("Hello, {}".format(
        elif msg.type == web.MsgType.binary:
            await ws.send_bytes(
        elif msg.type == web.MsgType.close:

    return ws

app = web.Application()
app.router.add_get('/echo', wshandler)
app.router.add_get('/', handle)
app.router.add_get('/{name}', handle)


Note: examples are written for Python 3.5+ and utilize PEP-492 aka async/await. If you are using Python 3.4 please replace await with yield from and async def with @coroutine e.g.:

async def coro(...):
    ret = await f()

should be replaced by:

def coro(...):
    ret = yield from f()


Discussion list

aio-libs google group:!forum/aio-libs


Optionally you may install the cChardet and aiodns libraries (highly recommended for sake of speed).


aiohttp is offered under the Apache 2 license.


The aiohttp community would like to thank Keepsafe ( for it’s support in the early days of the project.

Source code

The latest developer version is available in a github repository:


If you are interested in by efficiency, AsyncIO community maintains a list of benchmarks on the official wiki:


2.0.0rc1 (2017-03-14)

  • Properly handle payload errors #1710

  • Added ClientWebSocketResponse.get_extra_info() #1717

  • It is not possible to combine Transfer-Encoding and chunked parameter, same for compress and Content-Encoding #1655

  • Connector’s limit parameter indicates total concurrent connections. New limit_per_host added, indicates total connections per endpoint. #1601

  • Use url’s raw_host for name resolution #1685

  • Change ClientResponse.url to yarl.URL instance #1654

  • Add max_size parameter to web.Request reading methods #1133

  • Web stores data in temp files #1469

  • Add the allow_head=True keyword argument for add_get #1618

  • run_app and the Command Line Interface now support serving over Unix domain sockets for faster inter-process communication.

  • run_app now supports passing a preexisting socket object. This can be useful e.g. for socket-based activated applications, when binding of a socket is done by the parent process.

  • Implementation for Trailer headers parser is broken #1619

  • Fix FileResponse to not fall on bad request (range out of file size)

  • Fix FileResponse to correct stream video to Chromes

  • Deprecate public low-level api #1657

  • Deprecate encoding parameter for ClientSession.request() method

  • Dropped aiohttp.wsgi #1108

  • Dropped version from ClientSession.request() method

  • Dropped websocket version 76 support #1160

  • Dropped: aiohttp.protocol.HttpPrefixParser #1590

  • Dropped: Servers response’s .started, .start() and .can_start() method #1591

  • Dropped: Adding sub app via app.router.add_subapp() is deprecated use app.add_subapp() instead #1592

  • Dropped: Application.finish() and Application.register_on_finish() #1602

  • Dropped: web.Request.GET and web.Request.POST

  • Dropped: aiohttp.get(), aiohttp.options(), aiohttp.head(),, aiohttp.put(), aiohttp.patch(), aiohttp.delete(), and aiohttp.ws_connect() #1593

  • Dropped: aiohttp.web.WebSocketResponse.receive_msg() #1605

  • Dropped: ServerHttpProtocol.keep_alive_timeout attribute and keep-alive, keep_alive_on, timeout, log constructor parameters #1606

  • Dropped: TCPConnector’s` .resolve, .resolved_hosts, .clear_resolved_hosts() attributes and resolve constructor parameter #1607

  • Dropped ProxyConnector #1609

Project details

Release history Release notifications | RSS feed

Download files

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

Source Distribution

aiohttp-2.0.0rc1.tar.gz (605.7 kB view hashes)

Uploaded Source

Built Distributions

aiohttp-2.0.0rc1-cp36-cp36m-manylinux1_x86_64.whl (641.6 kB view hashes)

Uploaded CPython 3.6m

aiohttp-2.0.0rc1-cp36-cp36m-manylinux1_i686.whl (625.7 kB view hashes)

Uploaded CPython 3.6m

aiohttp-2.0.0rc1-cp35-cp35m-manylinux1_x86_64.whl (633.0 kB view hashes)

Uploaded CPython 3.5m

aiohttp-2.0.0rc1-cp35-cp35m-manylinux1_i686.whl (616.7 kB view hashes)

Uploaded CPython 3.5m

aiohttp-2.0.0rc1-cp34-cp34m-manylinux1_x86_64.whl (435.7 kB view hashes)

Uploaded CPython 3.4m

aiohttp-2.0.0rc1-cp34-cp34m-manylinux1_i686.whl (418.2 kB view hashes)

Uploaded CPython 3.4m

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page