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

Uploaded Source

Built Distributions

aiohttp-3.0.2-cp36-cp36m-win_amd64.whl (360.1 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-3.0.2-cp36-cp36m-win32.whl (348.9 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-3.0.2-cp36-cp36m-manylinux1_x86_64.whl (656.2 kB view details)

Uploaded CPython 3.6m

aiohttp-3.0.2-cp36-cp36m-manylinux1_i686.whl (627.8 kB view details)

Uploaded CPython 3.6m

aiohttp-3.0.2-cp36-cp36m-macosx_10_12_x86_64.whl (364.3 kB view details)

Uploaded CPython 3.6m macOS 10.12+ x86-64

aiohttp-3.0.2-cp36-cp36m-macosx_10_11_x86_64.whl (372.3 kB view details)

Uploaded CPython 3.6m macOS 10.11+ x86-64

aiohttp-3.0.2-cp36-cp36m-macosx_10_10_x86_64.whl (373.4 kB view details)

Uploaded CPython 3.6m macOS 10.10+ x86-64

aiohttp-3.0.2-cp35-cp35m-win_amd64.whl (358.2 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-3.0.2-cp35-cp35m-win32.whl (347.2 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-3.0.2-cp35-cp35m-manylinux1_x86_64.whl (640.7 kB view details)

Uploaded CPython 3.5m

aiohttp-3.0.2-cp35-cp35m-manylinux1_i686.whl (611.6 kB view details)

Uploaded CPython 3.5m

aiohttp-3.0.2-cp35-cp35m-macosx_10_12_x86_64.whl (362.9 kB view details)

Uploaded CPython 3.5m macOS 10.12+ x86-64

aiohttp-3.0.2-cp35-cp35m-macosx_10_11_x86_64.whl (369.9 kB view details)

Uploaded CPython 3.5m macOS 10.11+ x86-64

aiohttp-3.0.2-cp35-cp35m-macosx_10_10_x86_64.whl (370.9 kB view details)

Uploaded CPython 3.5m macOS 10.10+ x86-64

File details

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

File metadata

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

File hashes

Hashes for aiohttp-3.0.2.tar.gz
Algorithm Hash digest
SHA256 65c885062805fc2bf223806cf19ebb2e6884abdbdc882eb85746e538cc778bdb
MD5 44814676f69dac63b3dc0f19ed178a23
BLAKE2b-256 5240c1b1d51963db440ab730aaf1095d9a05fc07f943c8050b33ce28637a90a2

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 e125efcb4de9500b0f82620d8e194aff711b8c8591ded9ed641c7631fe52c92d
MD5 36c06d8248308a5f7c6cdb5f3b630ce6
BLAKE2b-256 8cc58fa829fa5fccc2037bbfae07afc9a60dad35e1702b85364ff8661aded768

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 8b98ba729dd2f2f1ba58b5d8fac02c2af8dbecb2a819ada6c422a68e1c7c7d41
MD5 617703b20a662766f38fd3806b66ad8c
BLAKE2b-256 c4c2e1fbc528ab8982756703caaf30fc35ec1c80faa029f6b2e99a227f467775

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9e1eec6dabb1b0e8a14a1a9907b4ca6d65d98bef10e33d6e8ca125f3dfe86d7a
MD5 23224be818a0efbb58268883db72e7c6
BLAKE2b-256 d4e779b87be5f6fd7e4c355d8510649782dee313055fe8840f776dcebe5b8e71

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 da70fbe58a38ee713464b24225a2caf0f601b565795d0cb3de0e159c6e2a66b4
MD5 36398d99a1df8c13186ea9908ad8d9f1
BLAKE2b-256 0a4e64cb729a705287ea05965e98a575b944b55d5cecc9edeeb4fffcfdec30ee

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 37feba955656be58c8fd8ae815329d436aac1d079bb65c1edaa2b0fcb80f9a3d
MD5 700aa0503b9709b10d7d79ba8b58ae6d
BLAKE2b-256 98b1d54d4f16e209e1d236c62510722c2798dbcfca266e8a42d59dbcb13a0110

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 2458a733a26fbcbbefb1f7df9b20f988f570a790269f7cb5f8aa370d8cb0db18
MD5 b1bc783589d85489ac57235ccc6ba55b
BLAKE2b-256 18a95c5a5d0b385a522dc6a75347432b953be63aa0536eb7a0659ff97bcf988e

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 9ff930c2a4121b3fc21d406c8e2c3167dff6f8f57abf8b63e92dc36263b693e7
MD5 bb774b35b0fffaff9042e356d4b209bc
BLAKE2b-256 b59afb12273144be97f1cc714152c17618b7c57a1c9a2281a1a0edd060f36a06

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 adb731e5f885038cb9ddb4f9fbaaf62f644785e8fc0abcf71ba879f1cdbf2f7e
MD5 7a54a5a23fbe320647eef108e8af53ca
BLAKE2b-256 3388f8ec0a7a6d26d91c4b042428b0bb32e002d28fdee523c04afde9f98afb3c

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 2d069103fb9ba6a448207a4bf815fdb4c46d2e43443ffc0f10fdaae543c80f7c
MD5 4b7e562eefb29d886dfc956649a35265
BLAKE2b-256 6d6c4308a1d2ec1ba43587178de0cfb5c5a91550ab52fb621a183f6c8858f94f

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 bf8716128dd5a87e25428a6a6d0f83352570f6f10643d85f50dd1d2a891d7beb
MD5 9be80188b9264d5a65c3f5f34cb92489
BLAKE2b-256 f323ddc3156c8806bfa5efaa40c6807cc5b9f011f24f9e52a6d9b0f51af14458

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 98ccab25085e41a7b835e0b7ae4209d33af2ff20c968d6c78a4617e910636f91
MD5 e7a707d24553f804e69b1d896e1f09ea
BLAKE2b-256 95f05201e579139ebfe85c2b93d68c4e0906d730712312145b842a6217566f0c

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 06fd26a4c18bafd88505d27dd523036494a33e4908bc13ce9234c95a0d713d36
MD5 96c0cb83a70e5e17bee714c9bfc52b71
BLAKE2b-256 357a70343704e05c4b26506c9c8cd210135874345d18fbd8924d4935972a286d

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 45e567826a631dde83660e42906ee4b85059f87d273919d1d75854f9f643227f
MD5 37a6b182b2002839a4f9d436f2da0175
BLAKE2b-256 e0d2241835e8c68e686aa029fc2f6f5aabda9b581f8ae8c02faee838f82755c5

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.2-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 0d489ec8c08f7687955579099f344cc97d270bfc9715934fea77a1ceef055b83
MD5 668c7ff29941784f59fadcf1f37fb378
BLAKE2b-256 bdce25e87affe1f7a159bb0cf911cbddae881b4301597b724d16f4b3823c9179

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