Skip to main content

Async http client/server framework (asyncio)

Project description

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.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

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.0.5.tar.gz (738.0 kB view details)

Uploaded Source

Built Distributions

aiohttp-3.0.5-cp36-cp36m-win_amd64.whl (360.5 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-3.0.5-cp36-cp36m-win32.whl (349.3 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-3.0.5-cp36-cp36m-manylinux1_x86_64.whl (656.6 kB view details)

Uploaded CPython 3.6m

aiohttp-3.0.5-cp36-cp36m-manylinux1_i686.whl (628.2 kB view details)

Uploaded CPython 3.6m

aiohttp-3.0.5-cp36-cp36m-macosx_10_12_x86_64.whl (364.7 kB view details)

Uploaded CPython 3.6m macOS 10.12+ x86-64

aiohttp-3.0.5-cp36-cp36m-macosx_10_11_x86_64.whl (372.7 kB view details)

Uploaded CPython 3.6m macOS 10.11+ x86-64

aiohttp-3.0.5-cp36-cp36m-macosx_10_10_x86_64.whl (373.9 kB view details)

Uploaded CPython 3.6m macOS 10.10+ x86-64

aiohttp-3.0.5-cp35-cp35m-win_amd64.whl (358.7 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-3.0.5-cp35-cp35m-win32.whl (347.6 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-3.0.5-cp35-cp35m-manylinux1_x86_64.whl (641.1 kB view details)

Uploaded CPython 3.5m

aiohttp-3.0.5-cp35-cp35m-manylinux1_i686.whl (612.1 kB view details)

Uploaded CPython 3.5m

aiohttp-3.0.5-cp35-cp35m-macosx_10_12_x86_64.whl (363.4 kB view details)

Uploaded CPython 3.5m macOS 10.12+ x86-64

aiohttp-3.0.5-cp35-cp35m-macosx_10_11_x86_64.whl (370.4 kB view details)

Uploaded CPython 3.5m macOS 10.11+ x86-64

aiohttp-3.0.5-cp35-cp35m-macosx_10_10_x86_64.whl (371.4 kB view details)

Uploaded CPython 3.5m macOS 10.10+ x86-64

File details

Details for the file aiohttp-3.0.5.tar.gz.

File metadata

  • Download URL: aiohttp-3.0.5.tar.gz
  • Upload date:
  • Size: 738.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiohttp-3.0.5.tar.gz
Algorithm Hash digest
SHA256 bb873da531401416acb7045a8f0bdf6555e9c6866989cd977166fae3cbbb954b
MD5 34e2ac3cd75dadb4b8663a14e7d7920c
BLAKE2b-256 cc59f7cee429b1566f2071888893bb16e880f619fa629068a799aae050544b57

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 f0831139ee003f850eee06e345dd905f99d1b655e634f8af6f03fcdb7222d0bf
MD5 8257030db2c554975ec08baf8d97ec18
BLAKE2b-256 9a004501247999434ac070abd8b92f109ca717f5681d37f933defca12d15aa5a

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 1ec1a759831eca5aa20efb5023afebb915c43212635d50fad03e669a1b093ea6
MD5 51b2e8023b387d8e96471da06ac40d0b
BLAKE2b-256 ca6a0e792315e67575960479e50b7b3058d2fd6a0e4708dac0b80392a516d46c

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7cb40af76a01349e6ab84f577ffccbe4e22c738d9c5f400b3117dffcde422387
MD5 43233992566dfa4523e8ffc12732f4a2
BLAKE2b-256 c97058c4d510c2efa78cfb7cdbdf9214ba708f352fed77b32c2fe3705e12fbba

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 fcd0e1d1d765ba24b25c3524aad9baf9e812e0983922d2528f464b0ca98fd932
MD5 e6f47f55af7572f94b4aab84ce009e6e
BLAKE2b-256 885e57640755dde02bb50bc474cd25fbff7b158c85ac0efd58ccc256477f0d89

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp36-cp36m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 21f8499675437bf3a31724c360af7484bae840f0294c16d979f148343df01493
MD5 bebc9411a5b548f62ec9182c719be719
BLAKE2b-256 5cf2ade3782b5a9c1d997b48d1eebae366ed98c8e72d4507b1964b24da0a1556

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp36-cp36m-macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 286aa16fca37a81a6f48c1b60178592efead43acdc0fd0ff9588b216ea848f30
MD5 a078df0ec637f950f74ae10cff5e52eb
BLAKE2b-256 7be0c020e28668c08e370e65e6a6bd6b46f5678aada226a940d1de7ee7a2dd91

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp36-cp36m-macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 c44987443235468fce44be4059655311a59c1c0e8e5a2aeea38dc196d41c9c1d
MD5 32700b2ec90d05f36a32174fec1bf5dc
BLAKE2b-256 3bc5cc73529502016201348f2b79ad5f769600a4a5301ebcadbc6db15b954145

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 16761ca659ce0609b76114a23f8f24c1f1e83e5cbfcd118fd29d6d3bd981fce0
MD5 120ec9065b1e7e43c4888d6658fad967
BLAKE2b-256 08b8ffdba5edcfd21b1b027d7b743bd9bf0cc10d9704f823fe2ab5cc9793e822

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 cac147cab6ea173f234ce91e941241812bc7cb1d544e4893cebff314a012844a
MD5 3e79fda23e117c0bd2e1172d83386745
BLAKE2b-256 7171f5f9d7a9f00912e20edced048f4706a8dc63ad198eec1b75cf1365f3613e

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e909d4bc3655c8857ae5120f7ab5172c0bf11c8afda7c0ea05e91ddebd213dc4
MD5 780331d971d4361dc20c36cb89edf745
BLAKE2b-256 8b6f527283bf898328b1edadf1931658d2791195c2ee8439de6d25d5dc95ff6c

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 0bcf2dced281db97ad6d16aefe6d846c4bc6cabf8f1bc7dd7868feb20fb039ea
MD5 3337dfbecc5a5b219398eb6c281dfeff
BLAKE2b-256 30d34f6eab29b2a85d0d823a49a3e11b68f3ab6ec401d43c81d0440792fbb277

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp35-cp35m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9d874b9fa19858130c5538a12db0eadf4ea18724412bc03d78e21723202072a9
MD5 799af67ec5be56b23383cfacc49cac76
BLAKE2b-256 b526d2f4ab06a880d968ee1b209824e5ae6bb344394298cdd9df14c66d9ea988

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp35-cp35m-macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 1dd839c079d25c9b458101c3b79a16ed319c27d1fbb7a98ce8a90c60f05afc2e
MD5 b5a02c06dcedc2b4fe86b47d679e60da
BLAKE2b-256 232394a97fc531c0f0594f010e8b0537fc6ff06689aaefaa440fcefec403695c

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-3.0.5-cp35-cp35m-macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.0.5-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 3e8a93e4cb25b929354d9c88c98ca87bef6c49cd03d375f2fb4f595172fc4d62
MD5 1a95b41b8d1d25ead06edb0daea26856
BLAKE2b-256 36c89402f434d556981cde37f93da0d3ca61612da4e1304976b292d71a940040

See more details on using hashes here.

Provenance

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