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

Uploaded Source

Built Distributions

aiohttp-3.0.1-cp36-cp36m-win_amd64.whl (359.7 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-3.0.1-cp36-cp36m-win32.whl (348.5 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-3.0.1-cp36-cp36m-manylinux1_x86_64.whl (655.9 kB view details)

Uploaded CPython 3.6m

aiohttp-3.0.1-cp36-cp36m-manylinux1_i686.whl (627.4 kB view details)

Uploaded CPython 3.6m

aiohttp-3.0.1-cp36-cp36m-macosx_10_12_x86_64.whl (363.9 kB view details)

Uploaded CPython 3.6m macOS 10.12+ x86-64

aiohttp-3.0.1-cp36-cp36m-macosx_10_11_x86_64.whl (371.9 kB view details)

Uploaded CPython 3.6m macOS 10.11+ x86-64

aiohttp-3.0.1-cp36-cp36m-macosx_10_10_x86_64.whl (373.1 kB view details)

Uploaded CPython 3.6m macOS 10.10+ x86-64

aiohttp-3.0.1-cp35-cp35m-win_amd64.whl (357.9 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-3.0.1-cp35-cp35m-win32.whl (346.8 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-3.0.1-cp35-cp35m-manylinux1_x86_64.whl (640.3 kB view details)

Uploaded CPython 3.5m

aiohttp-3.0.1-cp35-cp35m-manylinux1_i686.whl (611.3 kB view details)

Uploaded CPython 3.5m

aiohttp-3.0.1-cp35-cp35m-macosx_10_12_x86_64.whl (362.6 kB view details)

Uploaded CPython 3.5m macOS 10.12+ x86-64

aiohttp-3.0.1-cp35-cp35m-macosx_10_11_x86_64.whl (369.6 kB view details)

Uploaded CPython 3.5m macOS 10.11+ x86-64

aiohttp-3.0.1-cp35-cp35m-macosx_10_10_x86_64.whl (370.6 kB view details)

Uploaded CPython 3.5m macOS 10.10+ x86-64

File details

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

File metadata

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

File hashes

Hashes for aiohttp-3.0.1.tar.gz
Algorithm Hash digest
SHA256 7aee5c0750584946fde40da70f0b28fe769f85182f1171acef18a35fd8ecd221
MD5 390f559b7745477699edbde1f7e89ad9
BLAKE2b-256 3f1258d4b6ff8bae007e9c3a4e43cec92e3a905aff536fd28fac6b0a6895260b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 4b6fa00885ec778154244b010acecb862d277e6652b87fcd85c0f4735d26451c
MD5 feaf035daf0f81aa688752eb3a64ca19
BLAKE2b-256 7a27c9116f07a335afe9fab1b3732e0a4882bdf5085124701314984215b1a806

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 b53bc7b44b1115af50bd18d9671972603e5a4934e98dd3f4d671104c070e331d
MD5 49be8b4822627a6ccee04947b5454036
BLAKE2b-256 a1fdbf8299ecd990deabe21a9df46a3d139f70061d6ba56d2b8d8fc66cf06ff8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a19b96f77763ddf0249420438ebfc4d9a470daeb26f6614366d913ff520fa29b
MD5 dac1df7a1dd27b3847e7572887411b89
BLAKE2b-256 2640e15cfd699c7294589b5e4da146ce3c1e787cdb203c734f7f813363334e1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 7910089093296b5c8f683965044f553b0c5c9c2dbf310a219db76c6e793fea55
MD5 e0cd311cb23d429a0de5173e3d1e078a
BLAKE2b-256 c911720317cb9bdc05b68a0a1bb5c3b7418b7db1f42b45a79e0d963577eb48ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 15ad4d76bddfd98bf9e48263c70f6603e96d823c5a5c0c842646e9871be72c64
MD5 081d381ac9ecef3edf7bd568313a7583
BLAKE2b-256 0c4cfb7bd50a9b1e15cb513ea7f85d3045e88c8443893542fbd4c74ff1a13902

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 2fe26e836a1803c7414613c376fe29fc4ae0e5145e3813e1db1854cb05c91a3c
MD5 c066e03e328e99c530b453b57d6954e5
BLAKE2b-256 8e437e139e6b354b2e00df9bc31f7d9c074d5d6ea0b2b52342b6525ad8974e16

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 d51673140330c660e68c182e14164ddba47810dca873bbd28662f31d7d8c0185
MD5 a76a01e12a173e3f53023258e7a578e1
BLAKE2b-256 2763df38ea1e7be500a430b3d25d580ae86444c2e6cfd4b76b07b05cc0a6080d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 53988a8cf76c3fb74a759e77b1c2f55ab36880d57c6e7d0d59ad28743a2535fe
MD5 24a778785b331e02673b691d5e8d6eaa
BLAKE2b-256 79194751d4cd0d9b5c3f79095f2d0a74b2c23bb550619dfdf86cc5ca55e27a49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 040eecbc37aa5bd007108388fab6c42b2a01b964c4feac26bdffc8fe8af6c110
MD5 97693031f026703d77e8316fd0757787
BLAKE2b-256 00da0de79fa40230d97daf9a68ca316d02e778168fcd343b43d14e423d60f9a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6eef1d7eff9e6fa1029f7a62504f88b2b0afce89ced5c95d3a4cf1c2faef1231
MD5 eee2e25cdbf9040bfedf6fa1bad50615
BLAKE2b-256 e1bd32da36553cfc3a9025a44a8bccd18622aba6339166da4f00bc3e1387d23a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 9e6d6f0bca955923b515f8b5631c4c4f43aa152763852284cbefc89bd544069e
MD5 5329e8106591c91611564a3eb381ad75
BLAKE2b-256 d661d23d986f4db605762edeb8dc72c935a1a032e782c790db70339a58162dfa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 25825c61688fc95e09d6be19e513e925cb4f08aae4d7a7c38a1fa75e0e4c22bd
MD5 31d474105f82488b0c1771299aab7e21
BLAKE2b-256 561cd7b82fcab9b1b58286c9bee9b5c975bc1b5dd6a81fc42a52f99747af1068

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 4634dd3bbb68d0c7e5e4bca7571369d53c497b3300d9d678f939038e1b1231ee
MD5 4dd377194751c7edf37d5bf40b21a0b5
BLAKE2b-256 d379952948e5ca6ba8211933c3133d85e4693dd672e2eba3872c8fc4eb1762e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.1-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 2e8be4c46083ced9d9bc9ff4d77f31bfcd3e7486613f6138c5aa302d33ea54ed
MD5 d842f042280b3f2c3d023cfd58d9ed40
BLAKE2b-256 c98962157128930a0ab5e401bc4d089f20ec92ead4461f9f549ed88e8365c631

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