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

Uploaded Source

Built Distributions

aiohttp-3.0.4-cp36-cp36m-win_amd64.whl (360.4 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-3.0.4-cp36-cp36m-win32.whl (349.2 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-3.0.4-cp36-cp36m-manylinux1_x86_64.whl (656.5 kB view details)

Uploaded CPython 3.6m

aiohttp-3.0.4-cp36-cp36m-manylinux1_i686.whl (628.1 kB view details)

Uploaded CPython 3.6m

aiohttp-3.0.4-cp36-cp36m-macosx_10_12_x86_64.whl (364.6 kB view details)

Uploaded CPython 3.6m macOS 10.12+ x86-64

aiohttp-3.0.4-cp36-cp36m-macosx_10_11_x86_64.whl (372.6 kB view details)

Uploaded CPython 3.6m macOS 10.11+ x86-64

aiohttp-3.0.4-cp36-cp36m-macosx_10_10_x86_64.whl (373.7 kB view details)

Uploaded CPython 3.6m macOS 10.10+ x86-64

aiohttp-3.0.4-cp35-cp35m-win_amd64.whl (358.5 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-3.0.4-cp35-cp35m-win32.whl (347.5 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-3.0.4-cp35-cp35m-manylinux1_x86_64.whl (640.9 kB view details)

Uploaded CPython 3.5m

aiohttp-3.0.4-cp35-cp35m-manylinux1_i686.whl (612.0 kB view details)

Uploaded CPython 3.5m

aiohttp-3.0.4-cp35-cp35m-macosx_10_12_x86_64.whl (363.2 kB view details)

Uploaded CPython 3.5m macOS 10.12+ x86-64

aiohttp-3.0.4-cp35-cp35m-macosx_10_11_x86_64.whl (370.2 kB view details)

Uploaded CPython 3.5m macOS 10.11+ x86-64

aiohttp-3.0.4-cp35-cp35m-macosx_10_10_x86_64.whl (371.3 kB view details)

Uploaded CPython 3.5m macOS 10.10+ x86-64

File details

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

File metadata

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

File hashes

Hashes for aiohttp-3.0.4.tar.gz
Algorithm Hash digest
SHA256 6569b8850103595be10fcfa1fa911b01f876651921f52d769017b21d822e5dc3
MD5 f7b2333b277b93cefad94314ccf56d6f
BLAKE2b-256 56f876b02134bd3f8812526c4fe86360c7671a3da29d41a2915764c551761825

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 813c8181118a121233839f8f9e84f9e6640e70b8ff3fe0a778b53931b1b39895
MD5 322f45dd2a4f9dc2cd70c874400df5e4
BLAKE2b-256 b9e3c02932b4e7ab262564b19fc3f19eb9eda5f0b992c2caa33c3546bacfa52e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 32277f9378672e45e09ba0dc222cd17326ba1a62e3086103fba772d4c5d3e4b9
MD5 1539615146daff12c6dbd6c84f50f187
BLAKE2b-256 d521d73493899e8e7eba9b6acdc73245be3226e0633fa1b3e0e43947901259f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2b9c7379ed147dd4d9e24784765f2acf1249d4ddbd69dfe6cc5a35639865e98d
MD5 59263f49ecdb9b806ff3a1d966d471b1
BLAKE2b-256 d384181addffd241823bac97d58619fc2f936dd0265d1624d5346b7e6071722a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 a5ddd28a9f77283a10b8f1c2da01026111497b5c51bb04a8de3a997f3d438d33
MD5 2537b1e1769c6454f02a4338843038b6
BLAKE2b-256 9de2e6dd1046b11b21eee942b9d2e025d2a097e2615e4cff11f7df0e4802baa6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 44671200fd8e2a7cf9f7c08ec959a1123fd4183d930927e73a032855ac611d96
MD5 53fdccf5b4b3d921e4c7346e6a7ebb7b
BLAKE2b-256 e4e1b98df3c7bdd1079c7963a9a9e6bf0679abf6d6effaada21c6d7786da3ee2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 b8a9b6e0830ddfd5fa76e13cda7586cc40505ea039d9dce9615e4615fb50122d
MD5 0d1538cb642e02c438d3bac6239f51c6
BLAKE2b-256 129422a3ec1d4bcd2a752c0bd3ce34a012771188e37d8e0ae2fcf58ec3ab3c1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 8284f3652055b929b4ea24528a9a4fe716b9c3bb5bf2fac7169cef6b563755e5
MD5 eaa818745fa873cf979120edeea1b2a8
BLAKE2b-256 73511eb8f9e78939e4bb028782fa934573de5eebb72d833341da38f49da04bdc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 514b64521f54420c9fb7e81167fa437192cb233ff81a6a4d5d9e10f00262544c
MD5 8c911df376cda771080ece95f19cb86a
BLAKE2b-256 75b91762b524e3957d716367179277680eb7e5ef168b2548b58813048f690834

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 200ac902b46b36e27e674e1c4eb2444feaa14c8b4b86b1c2a7bda8309dafd32a
MD5 b02fa556f5995614cd25cc44e004a932
BLAKE2b-256 f75cfdb8ecf3047a9b1066a67d02febdfed6917e3a2d9bc861dc3c91e338883c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f60d7000b6f4ea75c0df463d0e4d9d1557272c63f4a73963925a2d88917ec0ec
MD5 d224fca0cdd0840a0db4153a290d988a
BLAKE2b-256 29a2265dc2ee147208a9367783d97bb5c9edd68f3d2fccc2527fc32dcf7636fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 461e48ef04939e6f197f7bf18c88ec1e54032d70f8cc55cf8c981be9c079d833
MD5 6d2ad4d2e7b7ec541f5271b6d7a224dc
BLAKE2b-256 4c431b27249db3ed7523f15c46ca6c0414dc0a254ad57cd21b30d4469fecd134

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ceaa3057c6ee1a0ff7eca51315266e9cbae723b439d63d195479198db2d19b6c
MD5 3303df6a8d4435c2158b6e690c754a20
BLAKE2b-256 1741e3e7e36f1b747fd7b08887d8007fedd5931a7f56d3feb90a9fab83de8bfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 89abd841563e30a9c69a1e0844a397592390b86789691ca4c9c017eff36e3769
MD5 6138eae40813b812e7303c498cbb2448
BLAKE2b-256 d52291515f0cbbd1d3d78371b558fd079f6129aac645c48905d64201827d6da6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.0.4-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 3d45689bab5782993c4b0ef736a7fa717e2ab8dbe1af762e1d4707ea23138026
MD5 dd78789467c3a104aa54cb43eb1bac11
BLAKE2b-256 819ea33dc22d92298d4bcb543b6129121af15f3d18db73d14af61af0315c1b5d

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