Skip to main content

http client/server for asyncio

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

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.

Source code

The latest developer version is available in a github repository: https://github.com/KeepSafe/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

1.3.2 (2017-02-16)

  • Awaiting on WebSocketResponse.send_* does not work #1645

  • Fix multiple calls to client ws_connect when using a shared header dict #1643

  • Make CookieJar.filter_cookies() accept plain string parameter. #1636

1.3.1 (2017-02-09)

  • Handle CLOSING in WebSocketResponse.__anext__

  • Fixed AttributeError ‘drain’ for server websocket handler #1613

1.3.0 (2017-02-08)

  • Multipart writer validates the data on append instead of on a request send #920

  • Multipart reader accepts multipart messages with or without their epilogue to consistently handle valid and legacy behaviors #1526 #1581

  • Separate read + connect + request timeouts # 1523

  • Do not swallow Upgrade header #1587

  • Fix polls demo run application #1487

  • Ignore unknown 1XX status codes in client #1353

  • Fix sub-Multipart messages missing their headers on serialization #1525

  • Do not use readline when reading the content of a part in the multipart reader #1535

  • Add optional flag for quoting FormData fields #916

  • 416 Range Not Satisfiable if requested range end > file size #1588

  • Having a : or @ in a route does not work #1552

  • Added receive_timeout timeout for websocket to receive complete message. #1325

  • Added heartbeat parameter for websocket to automatically send ping message. #1024 #777

  • Remove web.Application dependency from web.UrlDispatcher #1510

  • Accepting back-pressure from slow websocket clients #1367

  • Do not pause transport during set_parser stage #1211

  • Lingering close doesn’t terminate before timeout #1559

  • setsockopt may raise OSError exception if socket is closed already #1595

  • Lots of CancelledError when requests are interrupted #1565

  • Allow users to specify what should happen to decoding errors when calling a responses text() method #1542

  • Back port std module http.cookies for python3.4.2 #1566

  • Maintain url’s fragment in client response #1314

  • Allow concurrently close WebSocket connection #754

  • Gzipped responses with empty body raises ContentEncodingError #609

  • Return 504 if request handle raises TimeoutError.

  • Refactor how we use keep-alive and close lingering timeouts.

  • Close response connection if we can not consume whole http message during client response release

  • Abort closed ssl client transports, broken servers can keep socket open un-limit time #1568

  • Log warning instead of RuntimeError is websocket connection is closed.

  • Deprecated: aiohttp.protocol.HttpPrefixParser will be removed in 1.4 #1590

  • Deprecated: Servers response’s .started, .start() and .can_start() method will be removed in 1.4 #1591

  • Deprecated: Adding sub app via app.router.add_subapp() is deprecated use app.add_subapp() instead, will be removed in 1.4 #1592

  • Deprecated: aiohttp.get(), aiohttp.options(), aiohttp.head(), aiohttp.post(), aiohttp.put(), aiohttp.patch(), aiohttp.delete(), and aiohttp.ws_connect() will be removed in 1.4 #1593

  • Deprecated: Application.finish() and Application.register_on_finish() will be removed in 1.4 #1602

Metadata

Release files for aiohttp 1.3.2

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 1.3.2
File Size Uploaded
aiohttp-1.3.2.tar.gz 526.2 kB Details

Built distributions (wheels)

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

Total release size: 2.4 MB

Release files / aiohttp-1.3.2.tar.gz

Download URL aiohttp-1.3.2.tar.gz
Size 526.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8a14837dd81740dc23ef777b971fd4d98f21248001a8c9949ad1ca31887812c8
BLAKE2b-256 checksum
How to use checksums
e6567959b331961b34996c83688ccc3a4a1a0000be2bd10bbdbc4ea750c48d1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL aiohttp-1.3.2-cp36-cp36m-win_amd64.whl
Size 150.3 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
a5f78266881e53a4b84c49b3a1947c92080043ed5dde037c0a487539b2b346c1
BLAKE2b-256 checksum
How to use checksums
2653eaa657ddbeacf8bffbba00855948fa8c23bfe5e67ff3c15cc5124160cf2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

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

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

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

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

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

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

Download URL aiohttp-1.3.2-cp35-cp35m-win_amd64.whl
Size 150.3 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
fef465facb975dfd360b40a7d22cadce619ba4975ddf1722b48a143e3f94fefe
BLAKE2b-256 checksum
How to use checksums
130825d553129c83e9f2e5bc07d9fd345d43b0fd8a354bbf2f0bdda6dd189eff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL aiohttp-1.3.2-cp35-cp35m-win32.whl
Size 149.1 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
79821d32608a286f776e438a42e5f1471ccf46d50b59a062d91e304fbc538654
BLAKE2b-256 checksum
How to use checksums
dea890421662d054bfb168e3644e5f79f7fbd3d863493ee558b0fe0a1e831ef4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL aiohttp-1.3.2-cp35-cp35m-manylinux1_x86_64.whl
Size 167.2 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
9e62a5c08d29211d685aebfaebae0b0f2403c81e6e1a687834e791483bcada55
BLAKE2b-256 checksum
How to use checksums
6abcc553a0240cbc5a0837d880ecb48f6f2d13a8a67bc49a695085b1aba8fe33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

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

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

Download URL aiohttp-1.3.2-cp34-cp34m-win_amd64.whl
Size 148.2 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
715635ca77ec8a2218b21561a907146b579d30eef732502ad30f70b8cb1bb88b
BLAKE2b-256 checksum
How to use checksums
aa6ee5e5550a1051850d667394125033a53bebdd8b8680b16f0d0e4394b86fa7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL aiohttp-1.3.2-cp34-cp34m-win32.whl
Size 147.8 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
6f4157ec17443559f5990d68cd3247b80b4c2ab8e1b0d8947f00de80d28db0b9
BLAKE2b-256 checksum
How to use checksums
3129230ee5dd4019ea9857a335e0d0de10af8a5594ab3d163c4e58809379155b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

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

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

Download URL aiohttp-1.3.2-cp34-cp34m-manylinux1_i686.whl
Size 164.6 kB
Tags CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
85e91a663201b2b36107206c975cbad3d635e52e24395ee9c4f0d220038cbe1c
BLAKE2b-256 checksum
How to use checksums
d2397a8ba6fd57bb114f8724b5f4c3400f5fec1598540bc860d0e409422d905f
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

2.0.0

13 release files

1.3.5

7 release files

1.3.4

7 release files

1.3.3

13 release files

This release

1.3.2 This release

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