Skip to main content

Async http client/server framework (asyncio)

Project description

Async http client/server framework

aiohttp logo

Travis status for master branch AppVeyor status for master branch status for master branch Latest PyPI package version Latest Read The Docs Chat on Gitter

Key Features

  • Supports both client and server side of HTTP protocol.

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

  • Web-server has middlewares and pluggable routing.

Getting started


To retrieve something from the web:

import aiohttp
import asyncio

async def fetch(session, url):
    async with session.get(url) as response:
        return await response.text()

async def main():
    async with aiohttp.ClientSession() 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 wshandle(request):
    ws = web.WebSocketResponse()
    await ws.prepare(request)

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

    return ws

app = web.Application()
app.add_routes([web.get('/', handle),
                web.get('/echo', wshandle),
                web.get('/{name}', handle)])




Communication channels

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

Feel free to post your questions and ideas here.

gitter chat

We support Stack Overflow. Please add aiohttp tag to your question there.


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:


3.3.2 (2018-06-12)

  • Many HTTP proxies has buggy keepalive support. Let’s not reuse connection but close it after processing every response. (#3070)

  • Provide vendor source files in tarball (#3076)

3.3.1 (2018-06-05)

  • Fix sock_read timeout. (#3053)

  • When using a server-request body as the data= argument of a client request, iterate over the content with readany instead of readline to avoid Line too long errors. (#3054)

3.3.0 (2018-06-01)


  • Raise ConnectionResetError instead of CancelledError on trying to write to a closed stream. (#2499)

  • Implement ClientTimeout class and support socket read timeout. (#2768)

  • Enable logging when aiohttp.web is used as a program (#2956)

  • Add canonical property to resources (#2968)

  • Forbid reading response BODY after release (#2983)

  • Implement base protocol class to avoid a dependency from internal asyncio.streams.FlowControlMixin (#2986)

  • Cythonize @helpers.reify, 5% boost on macro benchmark (#2995)

  • Optimize HTTP parser (#3015)

  • Implement runner.addresses property. (#3036)

  • Use bytearray instead of a list of bytes in websocket reader. It improves websocket message reading a little. (#3039)

  • Remove heartbeat on closing connection on keepalive timeout. The used hack violates HTTP protocol. (#3041)

  • Limit websocket message size on reading to 4 MB by default. (#3045)


  • Don’t reuse a connection with the same URL but different proxy/TLS settings (#2981)

  • When parsing the Forwarded header, the optional port number is now preserved. (#3009)

Improved Documentation

  • Make Change Log more visible in docs (#3029)

  • Make style and grammar improvements on the FAQ page. (#3030)

  • Document that signal handlers should be async functions since aiohttp 3.0 (#3032)

Deprecations and Removals

  • Deprecate custom application’s router. (#3021)


  • #3008, #3011

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-3.4.0b1.tar.gz (822.6 kB view hashes)

Uploaded Source

Built Distributions

aiohttp-3.4.0b1-cp37-cp37m-win_amd64.whl (576.3 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

aiohttp-3.4.0b1-cp37-cp37m-win32.whl (550.1 kB view hashes)

Uploaded CPython 3.7m Windows x86

aiohttp-3.4.0b1-cp37-cp37m-macosx_10_13_x86_64.whl (590.0 kB view hashes)

Uploaded CPython 3.7m macOS 10.13+ x86-64

aiohttp-3.4.0b1-cp37-cp37m-macosx_10_11_x86_64.whl (598.5 kB view hashes)

Uploaded CPython 3.7m macOS 10.11+ x86-64

aiohttp-3.4.0b1-cp37-cp37m-macosx_10_10_x86_64.whl (602.0 kB view hashes)

Uploaded CPython 3.7m macOS 10.10+ x86-64

aiohttp-3.4.0b1-cp36-cp36m-win_amd64.whl (576.3 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

aiohttp-3.4.0b1-cp36-cp36m-win32.whl (550.5 kB view hashes)

Uploaded CPython 3.6m Windows x86

aiohttp-3.4.0b1-cp36-cp36m-macosx_10_13_x86_64.whl (593.4 kB view hashes)

Uploaded CPython 3.6m macOS 10.13+ x86-64

aiohttp-3.4.0b1-cp36-cp36m-macosx_10_11_x86_64.whl (598.6 kB view hashes)

Uploaded CPython 3.6m macOS 10.11+ x86-64

aiohttp-3.4.0b1-cp36-cp36m-macosx_10_10_x86_64.whl (601.9 kB view hashes)

Uploaded CPython 3.6m macOS 10.10+ x86-64

aiohttp-3.4.0b1-cp35-cp35m-win_amd64.whl (574.4 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

aiohttp-3.4.0b1-cp35-cp35m-win32.whl (548.7 kB view hashes)

Uploaded CPython 3.5m Windows x86

aiohttp-3.4.0b1-cp35-cp35m-macosx_10_13_x86_64.whl (587.4 kB view hashes)

Uploaded CPython 3.5m macOS 10.13+ x86-64

aiohttp-3.4.0b1-cp35-cp35m-macosx_10_11_x86_64.whl (595.8 kB view hashes)

Uploaded CPython 3.5m macOS 10.11+ x86-64

aiohttp-3.4.0b1-cp35-cp35m-macosx_10_10_x86_64.whl (599.2 kB view hashes)

Uploaded CPython 3.5m macOS 10.10+ x86-64

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