Skip to main content

Async http client/server framework

aiohttp logo Travis status for master branch codecov.io 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.

  • Web-server has middlewares and pluggable routing.

Getting started

Client

To retrieve something from the web:

import aiohttp
import asyncio
import async_timeout

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

async def main():
    async with aiohttp.ClientSession() as session:
        html = await fetch(session, 'http://python.org')
        print(html)

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

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)

Documentation

https://aiohttp.readthedocs.io/

Communication channels

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

Feel free to post your questions and ideas here.

gitter chat https://gitter.im/aio-libs/Lobby

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

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

Changelog

3.0.8 (2018-03-12)

  • Use asyncio.current_task() on Python 3.7 (#2825)

3.0.7 (2018-03-08)

  • Fix SSL proxy support by client. (#2810)

  • Restore a imperative check in setup.py for python version. The check works in parallel to environment marker. As effect a error about unsupported Python versions is raised even on outdated systems with very old setuptools version installed. (#2813)

3.0.6 (2018-03-05)

  • Add _reuse_address and _reuse_port to web_runner.TCPSite.__slots__. (#2792)

3.0.5 (2018-02-27)

  • Fix InvalidStateError on processing a sequence of two RequestHandler.data_received calls on web server. (#2773)

3.0.4 (2018-02-26)

  • Fix IndexError in HTTP request handling by server. (#2752)

  • Fix MultipartWriter.append* no longer returning part/payload. (#2759)

3.0.3 (2018-02-25)

  • Relax attrs dependency to minimal actually supported version 17.0.3 The change allows to avoid version conflicts with currently existing test tools.

3.0.2 (2018-02-23)

Security Fix

  • Prevent Windows absolute URLs in static files. Paths like /static/D:\path and /static/\\hostname\drive\path are forbidden.

3.0.1

  • Technical release for fixing distribution problems.

3.0.0 (2018-02-12)

Features

  • Speed up the PayloadWriter.write method for large request bodies. (#2126)

  • StreamResponse and Response are now MutableMappings. (#2246)

  • ClientSession publishes a set of signals to track the HTTP request execution. (#2313)

  • Content-Disposition fast access in ClientResponse (#2455)

  • Added support to Flask-style decorators with class-based Views. (#2472)

  • Signal handlers (registered callbacks) should be coroutines. (#2480)

  • Support async with test_client.ws_connect(...) (#2525)

  • Introduce site and application runner as underlying API for web.run_app implementation. (#2530)

  • Only quote multipart boundary when necessary and sanitize input (#2544)

  • Make the aiohttp.ClientResponse.get_encoding method public with the processing of invalid charset while detecting content encoding. (#2549)

  • Add optional configurable per message compression for ClientWebSocketResponse and WebSocketResponse. (#2551)

  • Add hysteresis to StreamReader to prevent flipping between paused and resumed states too often. (#2555)

  • Support .netrc by trust_env (#2581)

  • Avoid to create a new resource when adding a route with the same name and path of the last added resource (#2586)

  • MultipartWriter.boundary is str now. (#2589)

  • Allow a custom port to be used by TestServer (and associated pytest fixtures) (#2613)

  • Add param access_log_class to web.run_app function (#2615)

  • Add ssl parameter to client API (#2626)

  • Fixes performance issue introduced by #2577. When there are no middlewares installed by the user, no additional and useless code is executed. (#2629)

  • Rename PayloadWriter to StreamWriter (#2654)

  • New options reuse_port, reuse_address are added to run_app and TCPSite. (#2679)

  • Use custom classes to pass client signals parameters (#2686)

  • Use attrs library for data classes, replace namedtuple. (#2690)

  • Pytest fixtures renaming, add aiohttp_ prefix (#2578)

  • Add aiohttp- prefix for pytest-aiohttp command line parameters (#2578)

Bugfixes

  • Correctly process upgrade request from server to HTTP2. aiohttp does not support HTTP2 yet, the protocol is not upgraded but response is handled correctly. (#2277)

  • Fix ClientConnectorSSLError and ClientProxyConnectionError for proxy connector (#2408)

  • Fix connector convert OSError to ClientConnectorError (#2423)

  • Fix connection attempts for multiple dns hosts (#2424)

  • Fix writing to closed transport by raising asyncio.CancelledError (#2499)

  • Fix warning in ClientSession.__del__ by stopping to try to close it. (#2523)

  • Fixed race-condition for iterating addresses from the DNSCache. (#2620)

  • Fix default value of access_log_format argument in web.run_app (#2649)

  • Freeze sub-application on adding to parent app (#2656)

  • Do percent encoding for .url_for() parameters (#2668)

  • Correctly process request start time and multiple request/response headers in access log extra (#2641)

Improved Documentation

  • Improve tutorial docs, using literalinclude to link to the actual files. (#2396)

  • Small improvement docs: better example for file uploads. (#2401)

  • Rename from_env to trust_env in client reference. (#2451)

  • Fixed mistype in Proxy Support section where trust_env parameter was used in session.get(“http://python.org”, trust_env=True) method instead of aiohttp.ClientSession constructor as follows: aiohttp.ClientSession(trust_env=True). (#2688)

  • Fix issue with unittest example not compiling in testing docs. (#2717)

Deprecations and Removals

  • Simplify HTTP pipelining implementation (#2109)

  • Drop StreamReaderPayload and DataQueuePayload. (#2257)

  • Drop md5 and sha1 finger-prints (#2267)

  • Drop WSMessage.tp (#2321)

  • Drop Python 3.4 and Python 3.5.0, 3.5.1, 3.5.2. Minimal supported Python versions are 3.5.3 and 3.6.0. yield from is gone, use async/await syntax. (#2343)

  • Drop aiohttp.Timeout and use async_timeout.timeout instead. (#2348)

  • Drop resolve param from TCPConnector. (#2377)

  • Add DeprecationWarning for returning HTTPException (#2415)

  • send_str(), send_bytes(), send_json(), ping() and pong() are genuine async functions now. (#2475)

  • Drop undocumented app.on_pre_signal and app.on_post_signal. Signal handlers should be coroutines, support for regular functions is dropped. (#2480)

  • StreamResponse.drain() is not a part of public API anymore, just use await StreamResponse.write(). StreamResponse.write is converted to async function. (#2483)

  • Drop deprecated slow_request_timeout param and **kwargs` from RequestHandler. (#2500)

  • Drop deprecated resource.url(). (#2501)

  • Remove %u and %l format specifiers from access log format. (#2506)

  • Drop deprecated request.GET property. (#2547)

  • Simplify stream classes: drop ChunksQueue and FlowControlChunksQueue, merge FlowControlStreamReader functionality into StreamReader, drop FlowControlStreamReader name. (#2555)

  • Do not create a new resource on router.add_get(…, allow_head=True) (#2585)

  • Drop access to TCP tuning options from PayloadWriter and Response classes (#2604)

  • Drop deprecated encoding parameter from client API (#2606)

  • Deprecate verify_ssl, ssl_context and fingerprint parameters in client API (#2626)

  • Get rid of the legacy class StreamWriter. (#2651)

  • Forbid non-strings in resource.url_for() parameters. (#2668)

  • Deprecate inheritance from ClientSession and web.Application and custom user attributes for ClientSession, web.Request and web.Application (#2691)

  • Drop resp = await aiohttp.request(…) syntax for sake of async with aiohttp.request(…) as resp:. (#2540)

  • Forbid synchronous context managers for ClientSession and test server/client. (#2362)

Misc

  • #2552

Metadata

Release files for aiohttp 3.0.8

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 3.0.8
File Size Uploaded Provenance Actions
aiohttp-3.0.8.tar.gz 738.5 kB Without provenance Details for aiohttp-3.0.8.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for aiohttp 3.0.8
File Actions
aiohttp-3.0.8-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details for aiohttp-3.0.8-cp36-cp36m-win_amd64.whl
aiohttp-3.0.8-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details for aiohttp-3.0.8-cp36-cp36m-win32.whl
aiohttp-3.0.8-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details for aiohttp-3.0.8-cp36-cp36m-manylinux1_x86_64.whl
aiohttp-3.0.8-cp36-cp36m-manylinux1_i686.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-32 Details for aiohttp-3.0.8-cp36-cp36m-manylinux1_i686.whl
aiohttp-3.0.8-cp36-cp36m-macosx_10_12_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.12+ x86-64 Details for aiohttp-3.0.8-cp36-cp36m-macosx_10_12_x86_64.whl
aiohttp-3.0.8-cp36-cp36m-macosx_10_11_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.11+ x86-64 Details for aiohttp-3.0.8-cp36-cp36m-macosx_10_11_x86_64.whl
aiohttp-3.0.8-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details for aiohttp-3.0.8-cp35-cp35m-win_amd64.whl
aiohttp-3.0.8-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details for aiohttp-3.0.8-cp35-cp35m-win32.whl
aiohttp-3.0.8-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details for aiohttp-3.0.8-cp35-cp35m-manylinux1_x86_64.whl
aiohttp-3.0.8-cp35-cp35m-manylinux1_i686.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-32 Details for aiohttp-3.0.8-cp35-cp35m-manylinux1_i686.whl
aiohttp-3.0.8-cp35-cp35m-macosx_10_12_x86_64.whl CPython 3.5 CPython 3.5 pymalloc macOS 10.12+ x86-64 Details for aiohttp-3.0.8-cp35-cp35m-macosx_10_12_x86_64.whl
aiohttp-3.0.8-cp35-cp35m-macosx_10_11_x86_64.whl CPython 3.5 CPython 3.5 pymalloc macOS 10.11+ x86-64 Details for aiohttp-3.0.8-cp35-cp35m-macosx_10_11_x86_64.whl
aiohttp-3.0.8-cp35-cp35m-macosx_10_10_x86_64.whl CPython 3.5 CPython 3.5 pymalloc macOS 10.10+ x86-64 Details for aiohttp-3.0.8-cp35-cp35m-macosx_10_10_x86_64.whl

Total release size: 6.5 MB

Release files / aiohttp-3.0.8.tar.gz

Download URL aiohttp-3.0.8.tar.gz
Size 738.5 kB
Tags Source
SHA-256 checksum
How to use checksums
09636b2788925ffab2e78fbfe44a1be8dd4dbc5de593d9b046b3842665554d32
BLAKE2b-256 checksum
How to use checksums
c95b11cd4157b95a64b912fedf8ebe2cbda9b8b21c6a4b65f6656e63de2360c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL aiohttp-3.0.8-cp36-cp36m-win_amd64.whl
Size 361.1 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
754a10a14c54d029009ac9a1d158a73ac733bc65e2da81a87438b6c8e500bb7e
BLAKE2b-256 checksum
How to use checksums
5e6ccf27e7970923ec3f579d5482ef3525c280d97b5bd0642dfe4191e4a4114d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL aiohttp-3.0.8-cp36-cp36m-win32.whl
Size 349.8 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
49c409ce1320483a11775368b642519347b9c36e59818f1cd82a23daa6fc3085
BLAKE2b-256 checksum
How to use checksums
31b8675c7332c1d8d6aa4c3d8dd13e4b4ee1866005ce1e346f796300e0c6c476
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

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

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

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

Release files / aiohttp-3.0.8-cp36-cp36m-macosx_10_12_x86_64.whl

Download URL aiohttp-3.0.8-cp36-cp36m-macosx_10_12_x86_64.whl
Size 365.2 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
26b4ddf450a5781169b779c27804614dc217e5ef1a27cd8efbafb8557754da51
BLAKE2b-256 checksum
How to use checksums
eca5eb8d88b8e53271d3c526de2f46fd7613564e7b35e16528cefbb8989a5509
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-3.0.8-cp36-cp36m-macosx_10_11_x86_64.whl

Download URL aiohttp-3.0.8-cp36-cp36m-macosx_10_11_x86_64.whl
Size 373.3 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.11+ x86-64
SHA-256 checksum
How to use checksums
235aa785d1615f83b607d9aff042644b6acc8661df87f4a78c45c7a16781678f
BLAKE2b-256 checksum
How to use checksums
66b96821bbb626f6002ded6cdf864da6cca850d6ff9bc5c4972a1499cb7badaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL aiohttp-3.0.8-cp35-cp35m-win_amd64.whl
Size 359.2 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
f908c3888082625ce315151439f5f98fbd3bbd07446b8e14d36c8f48679b2166
BLAKE2b-256 checksum
How to use checksums
2c9d12e5aa2055b9b6135df470571ad7119613ae7f67eff3c510acf7c649ff80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

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

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

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

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

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

Release files / aiohttp-3.0.8-cp35-cp35m-macosx_10_12_x86_64.whl

Download URL aiohttp-3.0.8-cp35-cp35m-macosx_10_12_x86_64.whl
Size 363.9 kB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
af069a139ee4f0771c6398b7f4ad12de034712c074fc78f60c3f3f5336dc38a2
BLAKE2b-256 checksum
How to use checksums
cb22fc3524524ae1e2495de44fc69b1b110a96d7dcaee7a516c16d605f6d99fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-3.0.8-cp35-cp35m-macosx_10_11_x86_64.whl

Download URL aiohttp-3.0.8-cp35-cp35m-macosx_10_11_x86_64.whl
Size 370.9 kB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.11+ x86-64
SHA-256 checksum
How to use checksums
2a99c2b4bace2b8052be8f949ad28654de65c76ac012d79a4ccfda32468bf7eb
BLAKE2b-256 checksum
How to use checksums
2f555b42b5ad3a7a7d7d37f9c1b3ce73857c87a33060f7f5b8c4e113c51616b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / aiohttp-3.0.8-cp35-cp35m-macosx_10_10_x86_64.whl

Download URL aiohttp-3.0.8-cp35-cp35m-macosx_10_10_x86_64.whl
Size 371.9 kB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.10+ x86-64
SHA-256 checksum
How to use checksums
74de1b425f2a873136405100af5226274fa00845b91573a4131b863fa77e22d3
BLAKE2b-256 checksum
How to use checksums
88212b7ab3cc5c87c6710d65ffde66ba9fbd9759282fb55d7afc4ccd117cd931
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for aiohttp 3.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.0.8 This release

14 release files No provenance

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