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

Uploaded Source

Built Distributions

aiohttp-3.0.3-cp36-cp36m-win_amd64.whl (360.3 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-3.0.3-cp36-cp36m-win32.whl (349.0 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-3.0.3-cp36-cp36m-manylinux1_x86_64.whl (656.4 kB view details)

Uploaded CPython 3.6m

aiohttp-3.0.3-cp36-cp36m-manylinux1_i686.whl (627.9 kB view details)

Uploaded CPython 3.6m

aiohttp-3.0.3-cp36-cp36m-macosx_10_12_x86_64.whl (364.4 kB view details)

Uploaded CPython 3.6m macOS 10.12+ x86-64

aiohttp-3.0.3-cp36-cp36m-macosx_10_11_x86_64.whl (372.5 kB view details)

Uploaded CPython 3.6m macOS 10.11+ x86-64

aiohttp-3.0.3-cp36-cp36m-macosx_10_10_x86_64.whl (373.6 kB view details)

Uploaded CPython 3.6m macOS 10.10+ x86-64

aiohttp-3.0.3-cp35-cp35m-win_amd64.whl (358.4 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-3.0.3-cp35-cp35m-win32.whl (347.3 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-3.0.3-cp35-cp35m-manylinux1_x86_64.whl (640.8 kB view details)

Uploaded CPython 3.5m

aiohttp-3.0.3-cp35-cp35m-manylinux1_i686.whl (611.8 kB view details)

Uploaded CPython 3.5m

aiohttp-3.0.3-cp35-cp35m-macosx_10_12_x86_64.whl (363.1 kB view details)

Uploaded CPython 3.5m macOS 10.12+ x86-64

aiohttp-3.0.3-cp35-cp35m-macosx_10_11_x86_64.whl (370.1 kB view details)

Uploaded CPython 3.5m macOS 10.11+ x86-64

aiohttp-3.0.3-cp35-cp35m-macosx_10_10_x86_64.whl (371.1 kB view details)

Uploaded CPython 3.5m macOS 10.10+ x86-64

File details

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

File metadata

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

File hashes

Hashes for aiohttp-3.0.3.tar.gz
Algorithm Hash digest
SHA256 a96be9189b2d51e366106e4207c9afaf3d69462562548a613e399c311ff70b88
MD5 812ac014ec012ac39e2696f45f3d9f7b
BLAKE2b-256 f50de19609868a234695b31a8ee3f5dbfbadde1d9efde6b9150b5e31e1687ae6

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 8befe40664160afa721f4faa710ef0c84316c9478e86bbb3d6ec9f9c0a046bb3
MD5 098d141942b2821fa2213702fbb58aed
BLAKE2b-256 fa728141ff8edc3909cf86a49ffce2298704cea6378436b1894c3bf28b3c4d30

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 981a1b84068516a2758ca6d5bb29eacef644bfb5fd29ddbdc25ba72fa26f946b
MD5 a32617129afd867302904632fe4fdc5a
BLAKE2b-256 2fb42df08750ec523b296e0d00375e3a971ee6ac2ff89d0ddd7920eb04845b11

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f33efb12238e6a4a583f4aff470df7bca07e4df1b412eb469d85de248909eaa6
MD5 36744157b5a73fa6550950539faa7db2
BLAKE2b-256 46e5a12df28956be57f642cf1ee0abed49fffe1deb55b222081c576c97835be3

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 ab90d06955c2d21a24d8fb3c96cdf6ecd1d06041380597bc03a17c453311f52c
MD5 3b2834d9ffc1f4390b3106ba3682cfc5
BLAKE2b-256 59564684922826f03d52b6dabe1702651b3cbd49bf4081649fdcc5eaa0107ab6

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 823cb717882eaaa07208ec8a03a5aedfcd1411b3d8bdb57a024c09f216a086c6
MD5 93b8d5e448cf01b91ede9b05c312b26e
BLAKE2b-256 e570aa6b92787a560f4e44366664c0357b9fc027d3a6b56eb1f84400b594fb65

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 0b718487f46bcd106e954fb4d96d39feb1350539891185f40dffa1c1d5886589
MD5 a7953d03407c3a1a7f8a6fe80f617e49
BLAKE2b-256 a2ba547f6a74dbf15a913d6171ce64db11e563121057e1e415d35c645626313e

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 02b5f096e36d386215c102c32328e6879f5a310166aaed73faeb35e5ac61be43
MD5 420ab3d50acee86af77434e4a4fdf62e
BLAKE2b-256 c33adc3415eab46f1cd85f4f0ca0885321bca5b569221f8d859f493796ce1f6b

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 98ef1f496dca7fe2956905bf2f65a152d16480de3a572fdba079571fb482849d
MD5 29a0ffe3840c97586a9c879fa123235f
BLAKE2b-256 d7f70fe0dff5b70d43038f6b36a7068f03af6cc4381d8d65aed355759bd8dd7a

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 a77eca1f6d66cdc791efdaa9709163c34e870302d56f5957a3f9bbf67ee58fd7
MD5 6c96a52e99d014ea276f779a93f07263
BLAKE2b-256 0189201c0a25d30165994aa5f855a892d5674081db7c39f797c53b5560c81be3

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 21c92f905b2a0cd4cf8ad68e72f1e9de771ce94d7c054f7816b1c9251fdd3279
MD5 7c7f2cf1c3bc1a1a3fdef46ed0228b64
BLAKE2b-256 a6929d7cd2dbeb589e41b899053296a3a4f90c731636849a0965a8a2cd5d7e6f

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 97f7130bd67ca829f301868bd19cb6aaef965ab40057e13496627d4cce11f27a
MD5 5193ee676f3a405169f8b3abd7c133fc
BLAKE2b-256 ae4621202173519caf4d48fc040c21e20c82da44260d9fa756d35fb1b55bdf25

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3c1305d8b282cef804db30a1bb53cbdab176793eb7da7b148cc16256a1a417a8
MD5 ed25d19499e8e355741907d8c0a9bea0
BLAKE2b-256 20a4186cd3a264ac5f3eb4fb7637c7ae0597bcae289c2ff19d1371f6bdd85719

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 c060a061f9d09a97bfdd326c822380e830b05eb6d25e6d07b59c0278339a7b74
MD5 1471c522c7582930400a8915ffa81866
BLAKE2b-256 618cc469a0bbd50e582a076f327e81a9a5acbf12568891e16cce46f9c287bdcc

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.3-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 b5d239a4fb6c0dac9a64936269ef3f65d990d8f17df512e31d1fa43436c39f0a
MD5 75687ce91a5580de38d74f04a7b94593
BLAKE2b-256 cde1c3ab2877447ead850fdbe3ced20a7b67302e3c89d080c61b42bbf90e1a26

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