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

Project details


Release history Release notifications | RSS feed

This version

3.0.6

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

Uploaded Source

Built Distributions

aiohttp-3.0.6-cp36-cp36m-win_amd64.whl (360.6 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-3.0.6-cp36-cp36m-win32.whl (349.4 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-3.0.6-cp36-cp36m-manylinux1_x86_64.whl (656.8 kB view details)

Uploaded CPython 3.6m

aiohttp-3.0.6-cp36-cp36m-manylinux1_i686.whl (628.3 kB view details)

Uploaded CPython 3.6m

aiohttp-3.0.6-cp36-cp36m-macosx_10_12_x86_64.whl (364.8 kB view details)

Uploaded CPython 3.6m macOS 10.12+ x86-64

aiohttp-3.0.6-cp36-cp36m-macosx_10_11_x86_64.whl (372.8 kB view details)

Uploaded CPython 3.6m macOS 10.11+ x86-64

aiohttp-3.0.6-cp36-cp36m-macosx_10_10_x86_64.whl (374.0 kB view details)

Uploaded CPython 3.6m macOS 10.10+ x86-64

aiohttp-3.0.6-cp35-cp35m-win_amd64.whl (358.8 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-3.0.6-cp35-cp35m-win32.whl (347.7 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-3.0.6-cp35-cp35m-manylinux1_x86_64.whl (641.2 kB view details)

Uploaded CPython 3.5m

aiohttp-3.0.6-cp35-cp35m-manylinux1_i686.whl (612.2 kB view details)

Uploaded CPython 3.5m

aiohttp-3.0.6-cp35-cp35m-macosx_10_12_x86_64.whl (363.5 kB view details)

Uploaded CPython 3.5m macOS 10.12+ x86-64

aiohttp-3.0.6-cp35-cp35m-macosx_10_11_x86_64.whl (370.5 kB view details)

Uploaded CPython 3.5m macOS 10.11+ x86-64

aiohttp-3.0.6-cp35-cp35m-macosx_10_10_x86_64.whl (371.5 kB view details)

Uploaded CPython 3.5m macOS 10.10+ x86-64

File details

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

File metadata

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

File hashes

Hashes for aiohttp-3.0.6.tar.gz
Algorithm Hash digest
SHA256 5b588d21b454aaeaf2debf3c4a37f0752fb91a5c15b621deca7e8c49316154fe
MD5 cd85befc78bb54594974fb932dc3949c
BLAKE2b-256 32393a2bb54a1061b32cb4b0ba585c873227e39c58754052c46c9493a0bf655e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 0458f25f29348437117f03e04e2109a5bc7ed3125b51e9d094df2c0e42204d96
MD5 53e128cd17f09b9abfc367c853cc5dca
BLAKE2b-256 5d0703ff033a45eb611fe2d2e5165620786ff8106e74d62e1207dbff85ca5e32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 ab8713c94b7ab560893f9a716e4acb3d701f77ec4a72d901cb2ab8155fc94ec1
MD5 ee5a251186ff2866b865ac3ce95b131e
BLAKE2b-256 ed4b4cc675ec37f0f371e41ce8a155b968a6c458068f8fccf85580f66ae257b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 22f2c138746ffcdff4e23f0b78f84ce70292a8fde57cf5628755de5ff83b48b9
MD5 1ba33e32e250d4bd3da0e6fb9da9e07c
BLAKE2b-256 04d5a63b0aec6a7f31b792f43ce1111220fe8ce7ef9d67b886802c36e1a2b15d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 1807906fdb97d315347470787f9a8e712507b8d905c6414fc782659a49b88872
MD5 0ecb7a000784747dab9699e47c42eed5
BLAKE2b-256 7c1bc555e62874ffb9db45df25249a81e1f478c6370bea8edeadcc3fefe19958

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c78701bb30a09428f10079082e2889b867e75ac38d4691f1be75247186284852
MD5 9583c56453872f79244a0d7c4704055c
BLAKE2b-256 3c07bd10ef9f75016f51315d059a5616ff7c80eea5752219b82146b48ee5fb62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 d0b318b48b7f35ddda92ecc7da4103cd5f35641dc97a8edc52252cfc1762b025
MD5 9937aba19f601bafc8f500ec0fa3af64
BLAKE2b-256 c5c8bfa77f7efb9f96a16d57f549555a66d9229d2675fcb47fb91c750697b679

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 49658926978391687b6deb3d3ce634d3387ebc1e2a0b826fe16cf8e67fec6970
MD5 58c6ce816271a48ea242f8ac5bc03aab
BLAKE2b-256 3c0c8d1f0e5a29376802d0f5cf634ea3b3b05c841ed1e6c6ed565891c9b3c1ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 aaa0c224afc606dff510f6ad0afc5e48a8e93ecd8c677ac73b83cba8190106e6
MD5 acf5ed11aada1de3df67f73394f16cec
BLAKE2b-256 27d9105912861896a42cac73c9c9d65d9feff60bfca342d7cf21839456092600

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 a6aaeddc2717fb458e53dafd639d77019ba4f295984f005958ad26b3ff0be76f
MD5 e0ff469d0bd8df5ada25e87c76698844
BLAKE2b-256 527d4a13e2a5fd917d364e1b79cefa8003ad008a0347aeaf5f743f656aa0c7e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 19f07bfc0751f7cffe1e6e1edadc24bccca2832794baafdc485119a699ca8bdc
MD5 8c2661a2aa74ddea6c2fbc5e35a5a70b
BLAKE2b-256 408c7aa25b1f067b45a87bba2eee2db2c57ee5c23b94abccd924f948755e3af8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 46a75284e6b470cb0ac9cd1e5dca745426e344e504cab216fe34418ef7d2728e
MD5 7462c84c1cf4525586c6444bb8356a48
BLAKE2b-256 319e1207b9304b116b791b5f8324a7b3ff57d6bc002fb21b2a1bb27fbf588b41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 eb4abcea6ac950fbcd40ad59f85ef90e0a06c4b423038e0a1ea4daacf55e3b55
MD5 e24aaa80cb2d4512a21577efa9c22d44
BLAKE2b-256 ce09a45bb58e70a5fa77de1562a1cc0ed49f7915e0f65329d9ab5427f1905024

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 acb7299ac0b4c3b62fd6b5af680a20c698a2bfe757e3a58d8231575c99f6a10e
MD5 d387e9dc4098a2d79845cefdbd50b48e
BLAKE2b-256 8083450c8076c81d3cc3d7b80d58eacf64c733d4ec1980db007d43992a91469e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.6-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 30205486843b8aa6933dea828f00c9fa41133788a0537d2a4c08fe2845761be7
MD5 b4d6bd4b9ecf23291bcd8656f98390a6
BLAKE2b-256 bfb271c9be79d6fc33b1c8e81a9ce07a2f64ea094e6d44f86621d002a1569228

See more details on using hashes here.

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