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:
            ws.send_str("Hello, {}".format(msg.data))
        elif msg.type == web.MsgType.binary:
            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.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.1

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.1
File Size Uploaded
aiohttp-1.3.1.tar.gz 525.4 kB Details

Built distributions (wheels)

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

Total release size: 2.1 MB

Release files / aiohttp-1.3.1.tar.gz

Download URL aiohttp-1.3.1.tar.gz
Size 525.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e147b0cea568773443683becce9de4071506431118609b5d477fe61508417af1
BLAKE2b-256 checksum
How to use checksums
414276a4cff04488799e78d37c5bb3b607e36d2c4686141621002d2479b54dbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL aiohttp-1.3.1-cp36-cp36m-win_amd64.whl
Size 150.0 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
13f44a971da01093a5abcc6436596558e0c5bfac2532407a097be8607510ee1a
BLAKE2b-256 checksum
How to use checksums
3ac149a013795a1369815673263b3c17b26d761c8d4f4cd399d8e0cd22c52775
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

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

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

Download URL aiohttp-1.3.1-cp35-cp35m-win_amd64.whl
Size 150.0 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
bdd4b816dd2fdda95ca78170c1c2b5763325278ece8e77a6127e1dd4496b6b23
BLAKE2b-256 checksum
How to use checksums
0d032336cb25efb4b5171731aa6f02ef4a9048785356a362d3d0eb8fd69a7f55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL aiohttp-1.3.1-cp35-cp35m-win32.whl
Size 148.8 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
0e8f441d06f6236ceab2f46ba9df0a61e2353b267f23bb74bf2d8e8e2f7df35a
BLAKE2b-256 checksum
How to use checksums
14527780aaeeee1a5adc0a574c706075ded04dded392f22b23536d3451ef5345
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL aiohttp-1.3.1-cp35-cp35m-manylinux1_x86_64.whl
Size 166.9 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
52aa64ae3fa7b9681805ef321d27dd129e1e0c083646c693e688bed46fd141b6
BLAKE2b-256 checksum
How to use checksums
c63ba38626ed0bc5514baecf0e8843492720e2974969c877c4e668f4f0936f52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

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

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

Download URL aiohttp-1.3.1-cp34-cp34m-win_amd64.whl
Size 147.9 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
54ea9e6d43e8446a17ede03f80c17885899d0284cbab3cc273958e6088c75429
BLAKE2b-256 checksum
How to use checksums
31a21b493ebfc4b4a56600a37eb7004cf8ae3bbe69ce781055a41bc0df4cf7ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL aiohttp-1.3.1-cp34-cp34m-win32.whl
Size 147.6 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
01f57f73ae8b448ed0f48b0bc479047429d81adc8b96106b955028decba0943c
BLAKE2b-256 checksum
How to use checksums
5e7d9a8b886a6d0a87afd2858fa88efbf6f50cda26346242776b8e67cccd1a64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

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

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

Download URL aiohttp-1.3.1-cp34-cp34m-manylinux1_i686.whl
Size 164.4 kB
Tags CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-32
SHA-256 checksum
How to use checksums
a7c1ea6d0bae3b959e5fd219bc4900c08f2bd55157b26ac634e610704376fc3c
BLAKE2b-256 checksum
How to use checksums
641e2cdfd081ab3a133dadcdc7cf3dcb6815843314421c059925e362d903e5b5
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

1.3.2

13 release files

This release

1.3.1 This release

11 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