Skip to main content

Async http client/server framework

aiohttp logo https://travis-ci.org/aio-libs/aiohttp.svg?branch=master https://codecov.io/gh/aio-libs/aiohttp/branch/master/graph/badge.svg https://badge.fury.io/py/aiohttp.svg

aiohttp 2.0 release!

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 problems across whole package. Client exceptions handling has been cleaned up and now much more straight forward. Client payload management simplified and allows to extend with any custom type. Client connection pool implementation has been redesigned as well, now there is no need for actively releasing response objects, aiohttp handles connection release automatically.

Another major change, we moved aiohttp development to public organization https://github.com/aio-libs

With this amount of api changes we had to make backward incompatible changes. Please check this migration document http://aiohttp.readthedocs.io/en/latest/migration.html

Please report problems or annoyance with with api to https://github.com/aio-libs/aiohttp

Features

  • 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

Client

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, 'http://python.org')
        print(html)

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

Server

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(msg.data))
        elif msg.type == web.MsgType.binary:
            await ws.send_bytes(msg.data)
        elif msg.type == web.MsgType.close:
            break

    return ws


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

web.run_app(app)

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:

@asyncio.coroutine
def coro(...):
    ret = yield from f()

Documentation

https://aiohttp.readthedocs.io/

Discussion list

aio-libs google group: https://groups.google.com/forum/#!forum/aio-libs

Requirements

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

License

aiohttp is offered under the Apache 2 license.

Keepsafe

The aiohttp community would like to thank Keepsafe (https://www.getkeepsafe.com) for it’s support in the early days of the project.

Source code

The latest developer version is available in a github repository: https://github.com/aio-libs/aiohttp

Benchmarks

If you are interested in by efficiency, AsyncIO community maintains a list of benchmarks on the official wiki: https://github.com/python/asyncio/wiki/Benchmarks

Changes

2.0.0 (2017-03-20)

  • Added json to ClientSession.request() method #1726

  • Added session’s raise_for_status parameter, automatically calls raise_for_status() on any request. #1724

  • response.json() raises ClientReponseError exception if response’s content type does not match #1723

  • Cleanup timer and loop handle on any client exception.

  • Deprecate loop parameter for Application’s constructor

2.0.0rc1 (2017-03-15)

  • 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 Request.post() 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.post(), 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

Metadata

Release files for aiohttp 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiohttp 2.0.0
File Size Uploaded
aiohttp-2.0.0.tar.gz 607.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for aiohttp 2.0.0
File
aiohttp-2.0.0-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
aiohttp-2.0.0-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
aiohttp-2.0.0-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
aiohttp-2.0.0-cp36-cp36m-manylinux1_i686.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32 Details
aiohttp-2.0.0-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details
aiohttp-2.0.0-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details
aiohttp-2.0.0-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details
aiohttp-2.0.0-cp35-cp35m-manylinux1_i686.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-32 Details
aiohttp-2.0.0-cp34-cp34m-win_amd64.whl CPython 3.4 CPython 3.4 pymalloc Windows x86-64 Details
aiohttp-2.0.0-cp34-cp34m-win32.whl CPython 3.4 CPython 3.4 pymalloc Windows x86-32 Details
aiohttp-2.0.0-cp34-cp34m-manylinux1_x86_64.whl CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-64 Details
aiohttp-2.0.0-cp34-cp34m-manylinux1_i686.whl CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-32 Details

Total release size: 5.5 MB

Release files / aiohttp-2.0.0.tar.gz

Download URL aiohttp-2.0.0.tar.gz
Size 607.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9d73c4b530ff11ca58f96184618180fbc1f93d08fe8da600dfe9c858e471bdfa
BLAKE2b-256 checksum
How to use checksums
b088712947e5c06479ea27a59ebf2ab78bf4358798c0b472dbd2535815f8a293
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-2.0.0-cp36-cp36m-win_amd64.whl

Download URL aiohttp-2.0.0-cp36-cp36m-win_amd64.whl
Size 258.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
bc6510935f73fb2c8b5a674da1f385ce679f8a44deb82c05a7837e9906cb8f7f
BLAKE2b-256 checksum
How to use checksums
1d32079c6c481df9d5659f1e88dd6c518dab72aaba7a8ce2e74ddddf10683e00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-2.0.0-cp36-cp36m-win32.whl

Download URL aiohttp-2.0.0-cp36-cp36m-win32.whl
Size 252.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
fee37e748b886cb430644fe97249ae986bb6e935f251c446a9e2110038ab1386
BLAKE2b-256 checksum
How to use checksums
13e3f875358d5fdb4e9922744df49da5f256c32e7b2df23bde5518737fc1b40f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-2.0.0-cp36-cp36m-manylinux1_x86_64.whl

Download URL aiohttp-2.0.0-cp36-cp36m-manylinux1_x86_64.whl
Size 642.2 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
7047ce8553fe390196a115c63d3897464a42fca93270660a0dbf44913ad97b9b
BLAKE2b-256 checksum
How to use checksums
87f2d9b35bf7bf6a14e4ef199f79f3673699c02a96a8848f71f121b409b0f2e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-2.0.0-cp36-cp36m-manylinux1_i686.whl

Download URL aiohttp-2.0.0-cp36-cp36m-manylinux1_i686.whl
Size 626.2 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
eaa474f2212a9dcea53a2581a371cba07849dc1799800289bd6045c9f159003b
BLAKE2b-256 checksum
How to use checksums
d0016c835f6200b3c594bd0654f97204a6d773b9b11974357ece024218cfc2f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-2.0.0-cp35-cp35m-win_amd64.whl

Download URL aiohttp-2.0.0-cp35-cp35m-win_amd64.whl
Size 257.2 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
53d05ff50e8681d93babf8d134f22aca162e667474df5fb20da5e00e63cab5e0
BLAKE2b-256 checksum
How to use checksums
9742f1d01a58c5e1c966e7d10b27073f60100d03e54f14a8bfb850970549161e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-2.0.0-cp35-cp35m-win32.whl

Download URL aiohttp-2.0.0-cp35-cp35m-win32.whl
Size 251.4 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
875cb0ec2b7c2fd103d4efaf4d08058876008aacb60394e8d03b9a4e09ae453e
BLAKE2b-256 checksum
How to use checksums
c984fd40c702a352e1ccf288ad50e2e60331ac45ef92e557141c040bd44875df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-2.0.0-cp35-cp35m-manylinux1_x86_64.whl

Download URL aiohttp-2.0.0-cp35-cp35m-manylinux1_x86_64.whl
Size 633.6 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
41e77a9853a44cee04a748e573ade7806903b867dd7c5ef99981d8bb777b2c9f
BLAKE2b-256 checksum
How to use checksums
4b6e947276936e520a532e549b96332988fa0ebd20955eecd36f12fb9ce154f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-2.0.0-cp35-cp35m-manylinux1_i686.whl

Download URL aiohttp-2.0.0-cp35-cp35m-manylinux1_i686.whl
Size 617.3 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
a24cef553055453aee2347aeac5bc02a946223e88d3079712ba0a54a96e79f7b
BLAKE2b-256 checksum
How to use checksums
336c36f959ed83f55f0475a18cecad25e0d4fe9608dcd44db214dffdb5a85801
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-2.0.0-cp34-cp34m-win_amd64.whl

Download URL aiohttp-2.0.0-cp34-cp34m-win_amd64.whl
Size 254.2 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
4bff5fe18c198044873e57c80cb3528b1284e05fc9f89c0bdf920907d9e880c7
BLAKE2b-256 checksum
How to use checksums
aa9735b4882d414e2ff934a58c9ce87e66b2f709d0e4909b4821d3a778ef4ef5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-2.0.0-cp34-cp34m-win32.whl

Download URL aiohttp-2.0.0-cp34-cp34m-win32.whl
Size 250.6 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
a769a1af5c7645bc744c4904ab4662c544b1315a7c0b81e5e6ca5e0dd22a4a58
BLAKE2b-256 checksum
How to use checksums
8e0716318cfb42dc787e7905dc2eb2b668f89b32f91c042fa459452a6dc81c6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-2.0.0-cp34-cp34m-manylinux1_x86_64.whl

Download URL aiohttp-2.0.0-cp34-cp34m-manylinux1_x86_64.whl
Size 436.2 kB
Tags CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
b7c61dfccdcd69822596066a3f92ccb7412de8f12fc9be30427284f0505cacfd
BLAKE2b-256 checksum
How to use checksums
8bc0961bdf8dc8795ab1e624c966fcb5411935cfdd4609f85c41514a63f7ed0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-2.0.0-cp34-cp34m-manylinux1_i686.whl

Download URL aiohttp-2.0.0-cp34-cp34m-manylinux1_i686.whl
Size 418.8 kB
Tags CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
bda5f69197cd9a7c9cc9839ef4c9c12e53f5a9d52d55c1f775cae534d14fa23a
BLAKE2b-256 checksum
How to use checksums
d0d991a468edd0731136a28fc9f029e55f2a8bcf77116998d324a1b77734124f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

3.9.5

76 release files

3.9.4

76 release files

3.9.3

76 release files

3.9.2

76 release files

3.9.1

76 release files

3.9.0

76 release files

3.8.5

87 release files

3.8.4

87 release files

3.8.3

87 release files

3.8.2

87 release files

3.8.1

72 release files

3.8.0

72 release files

3.7.4

37 release files

3.7.3

37 release files

3.7.2

33 release files

3.7.1

33 release files

3.7.0

33 release files

3.6.3

13 release files

3.6.1

13 release files

3.5.4

22 release files

3.5.3

22 release files

3.5.1

22 release files

3.5.0

22 release files

3.4.1

22 release files

3.4.0

22 release files

3.3.2

15 release files

3.3.0

9 release files

3.2.1

15 release files

3.1.3

15 release files

3.1.1

15 release files

3.1.0

15 release files

3.0.9

15 release files

3.0.8

14 release files

3.0.5

15 release files

3.0.4

15 release files

3.0.3

15 release files

3.0.2

15 release files

3.0.1

15 release files

3.0.0

11 release files

2.3.9

16 release files

2.3.8

16 release files

2.3.7

22 release files

2.3.5

22 release files

2.3.4

22 release files

2.3.3

22 release files

2.3.1

22 release files

2.3.0

13 release files

2.2.0

13 release files

2.1.0

13 release files

2.0.7

8 release files

2.0.5

13 release files

2.0.4

13 release files

2.0.3

13 release files

2.0.2

13 release files

2.0.1

13 release files

This release

2.0.0 This release

13 release files

1.3.5

7 release files

1.3.4

7 release files

1.3.3

13 release files

1.3.2

13 release files

1.3.0

9 release files

1.2.0

9 release files

1.1.6

9 release files

1.1.5

9 release files

1.1.4

9 release files

1.1.3

9 release files

1.1.2

9 release files

1.1.1

9 release files

1.1.0

9 release files

1.0.5

9 release files

1.0.3

9 release files

1.0.2

9 release files

1.0.1

9 release files

1.0.0

9 release files

0.22.4

9 release files

0.22.3

9 release files

0.22.2

9 release files

0.22.1

9 release files

0.22.0

9 release files

0.21.5

5 release files

0.21.4

5 release files

0.21.2

5 release files

0.21.1

5 release files

0.20.2

1 release file

0.20.1

1 release file

0.20.0

1 release file

0.19.0

1 release file

0.18.4

1 release file

0.18.3

1 release file

0.18.2

1 release file

0.18.1

1 release file

0.18.0

1 release file

0.17.4

1 release file

0.17.3

1 release file

0.17.2

1 release file

0.17.1

1 release file

0.17.0

1 release file

0.16.6

1 release file

0.16.5

1 release file

0.16.4

1 release file

0.16.3

1 release file

0.16.2

1 release file

0.16.1

1 release file

0.16.0

1 release file

0.15.3

1 release file

0.15.2

1 release file

0.15.1

1 release file

0.15.0

1 release file

0.14.4

1 release file

0.14.3

1 release file

0.14.2

1 release file

0.14.1

1 release file

0.14.0

1 release file

0.13.1

2 release files

0.13.0

2 release files

0.12.0

1 release file

0.11.0

2 release files

0.10.2

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

1 release file

0.9.0

1 release file

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.5

1 release file

0.6.4

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.4

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page