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 without the Callback Hell.

  • Web-server has middlewares and pluggable routing.

Getting started

Client

To retrieve something from the web:

import aiohttp
import asyncio

async def fetch(session, url):
    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 wshandle(request):
    ws = web.WebSocketResponse()
    await ws.prepare(request)

    async for msg in ws:
        if msg.type == web.WSMsgType.text:
            await ws.send_str("Hello, {}".format(msg.data))
        elif msg.type == web.WSMsgType.binary:
            await ws.send_bytes(msg.data)
        elif msg.type == web.WSMsgType.close:
            break

    return ws


app = web.Application()
app.add_routes([web.get('/', handle),
                web.get('/echo', wshandle),
                web.get('/{name}', handle)])

web.run_app(app)

Documentation

https://aiohttp.readthedocs.io/

Demos

https://github.com/aio-libs/aiohttp-demos

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.3.1 (2018-06-05)

  • Fix sock_read timeout. (#3053)

  • When using a server-request body as the data= argument of a client request, iterate over the content with readany instead of readline to avoid Line too long errors. (#3054)

3.3.0 (2018-06-01)

Features

  • Raise ConnectionResetError instead of CancelledError on trying to write to a closed stream. (#2499)

  • Implement ClientTimeout class and support socket read timeout. (#2768)

  • Enable logging when aiohttp.web is used as a program (#2956)

  • Add canonical property to resources (#2968)

  • Forbid reading response BODY after release (#2983)

  • Implement base protocol class to avoid a dependency from internal asyncio.streams.FlowControlMixin (#2986)

  • Cythonize @helpers.reify, 5% boost on macro benchmark (#2995)

  • Optimize HTTP parser (#3015)

  • Implement runner.addresses property. (#3036)

  • Use bytearray instead of a list of bytes in websocket reader. It improves websocket message reading a little. (#3039)

  • Remove heartbeat on closing connection on keepalive timeout. The used hack violates HTTP protocol. (#3041)

  • Limit websocket message size on reading to 4 MB by default. (#3045)

Bugfixes

  • Don’t reuse a connection with the same URL but different proxy/TLS settings (#2981)

  • When parsing the Forwarded header, the optional port number is now preserved. (#3009)

Improved Documentation

  • Make Change Log more visible in docs (#3029)

  • Make style and grammar improvements on the FAQ page. (#3030)

  • Document that signal handlers should be async functions since aiohttp 3.0 (#3032)

Deprecations and Removals

  • Deprecate custom application’s router. (#3021)

Misc

  • #3008, #3011

Release history Release notifications | RSS feed

This version

3.3.1

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

Uploaded Source

Built Distributions

aiohttp-3.3.1-cp36-cp36m-win_amd64.whl (478.0 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-3.3.1-cp36-cp36m-win32.whl (460.9 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-3.3.1-cp36-cp36m-manylinux1_x86_64.whl (875.9 kB view details)

Uploaded CPython 3.6m

aiohttp-3.3.1-cp36-cp36m-manylinux1_i686.whl (846.5 kB view details)

Uploaded CPython 3.6m

aiohttp-3.3.1-cp36-cp36m-macosx_10_12_x86_64.whl (477.3 kB view details)

Uploaded CPython 3.6m macOS 10.12+ x86-64

aiohttp-3.3.1-cp36-cp36m-macosx_10_11_x86_64.whl (486.9 kB view details)

Uploaded CPython 3.6m macOS 10.11+ x86-64

aiohttp-3.3.1-cp36-cp36m-macosx_10_10_x86_64.whl (489.3 kB view details)

Uploaded CPython 3.6m macOS 10.10+ x86-64

aiohttp-3.3.1-cp35-cp35m-win_amd64.whl (475.8 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-3.3.1-cp35-cp35m-win32.whl (458.7 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-3.3.1-cp35-cp35m-manylinux1_x86_64.whl (857.8 kB view details)

Uploaded CPython 3.5m

aiohttp-3.3.1-cp35-cp35m-manylinux1_i686.whl (828.0 kB view details)

Uploaded CPython 3.5m

aiohttp-3.3.1-cp35-cp35m-macosx_10_12_x86_64.whl (476.0 kB view details)

Uploaded CPython 3.5m macOS 10.12+ x86-64

aiohttp-3.3.1-cp35-cp35m-macosx_10_11_x86_64.whl (484.2 kB view details)

Uploaded CPython 3.5m macOS 10.11+ x86-64

aiohttp-3.3.1-cp35-cp35m-macosx_10_10_x86_64.whl (486.3 kB view details)

Uploaded CPython 3.5m macOS 10.10+ x86-64

File details

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

File metadata

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

File hashes

Hashes for aiohttp-3.3.1.tar.gz
Algorithm Hash digest
SHA256 16ac24a3278375d277dacf992ac07084865c3aad3e625fc5be693c4b7e7f550d
MD5 9a58ffe9ae0b37428dd99dd55bb69820
BLAKE2b-256 1561e527f5094e5717d31ab2a92135e67e131659068626d426b95244e9c3aa8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 421ba132f3fe091a9482b2f28e4e510408bf4591eefb2e5881b2d2cba79f563d
MD5 e5efd20a8090d376322907514f50d2e1
BLAKE2b-256 a854b0e61c8a3790dfa5d09e538bdafc2ef0ed7c5bb31308063ac451efd9726a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 2c56cf25b61f5be1f30e718b3865deadf687b2d2e8266441bc64e9ec401f5703
MD5 c78efe3e80ce89b6c0f598f769c57220
BLAKE2b-256 9e47f8cb1d67be373172c574737ce85f536d30f6ae6424760bbf7f441c22eec0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9aa0f69463d33d028b1f75872886f56a7411925a2aa563ac15f29a0af919a07d
MD5 63b88f5474bd47ccde20b2450c115c88
BLAKE2b-256 933f8856fa8eec985e64ae3d8b1353acb7edec0d870abd9a5fce3cf39d3c323d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 e8d97bd24a556ae513d8bccd080421d27b5ae68adf9530fec8c9954f4aa90bb8
MD5 ed6a0a58c4b1d6d066a1764bf31f4315
BLAKE2b-256 9a80c2164a46b6d3acd9f0b53ef12db1bc3576973d7cebc37ef96047fdef3c4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 467c2208192943ea497b287d06444dc8483296857600157affc463f53c629f62
MD5 f1834c08ed752f91fbdfd11d2efb45d8
BLAKE2b-256 f2e9015300c260c5e2c063bcc0dc8c4ed50df1af898f984318112aac01a8d76e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 a45330dacdf3a3cebd0b74c0b5e0bc4982f0dbb757d5df021b52049a94a2bce0
MD5 885b2e35883e5859685ffed628f827f6
BLAKE2b-256 93b3e2fe348633ada4a611108a3699b08dee22554107f7cb7cbaeec7a6f4e2c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 c07054f3971af9035aa7295d4faa05bafc1ddd4af5cc92c0901600a5e97d1962
MD5 ebededa20262caf89e6dd6845ccbf882
BLAKE2b-256 4d5e02cc05795d8f5af3eadb7662121f705f14c6a43385eacebaa98bdb54ed42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 4969022967b7c7b141711842151d937ca3ccbea485d18b4f154c3f5582df866c
MD5 3792cffdcaa4ddfa34cdb4203ae2781d
BLAKE2b-256 3ff9a4fc8a186ebcca7f15bbf0cac973a69bac8dd1e92ee2885339fba339a7d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 90236edee174b2ae1a9ccee08940f89466076db33edd212d6aeef9ff7f1af48c
MD5 496e29768dc5251215cb3a72067a768e
BLAKE2b-256 f704b730d08648b2bdb5c6300d9c9fa3fe879ec2caf3d104da37978939c709b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fca7f31bddbca4114c4bb36380f4c85608c09c39902cd5f33764053ad70c2fc5
MD5 668ca99c0cfc258956b2c60db20e79ba
BLAKE2b-256 8edf6c2fccc2d0077836f3170b01dc7d8857bf3a2b260f70d1a7e41d31275071

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 86224c3200a90fdf4bf6eda66c8e6db09d49c85c8c1065224354fb5f6f1ccffe
MD5 9175a169c9ac9c7d80cec42794a41676
BLAKE2b-256 712f66a46a6fc3494ef57754729c7e6f2780758920e6efc4684459e1e875a7eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fecc50a3c5ec6baf8dd41d5e739d1dec5d0741ac479fa4e209d770008aeb58a1
MD5 c5d2d83c122fa161b75ff8dba8d24a13
BLAKE2b-256 2f99cca163e157310055fc722f668e1d1e09c20e1d5e63113eaf4625dffdb2be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 ace77e76c94aac79104229b3a589cd26d55f52769cb458befab3342b93a3c9eb
MD5 b312d06bc8b65235079e15f098ee0210
BLAKE2b-256 dd2494f8871b3a90aecd408b74e95be8b5f7196ee24744628a07a5767ad0fbd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.1-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 9aa0bbd1967fef07abda7c9117cbac63226146020abe2a3ac8a9b0ce33f50ee5
MD5 cec9f69249903a5536aece41c4fd48dc
BLAKE2b-256 6119b5a345c82eb44b4fa44c51dcd9dc019b1eefe8bd24442311ebf8d40719fb

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