Skip to main content

Async http client/server framework (asyncio)

Project description

Async http client/server framework

aiohttp logo https://travis-ci.org/aio-libs/aiohttp.svg?branch=master https://codecov.io/gh/aio-libs/aiohttp/branch/master/graph/badge.svg https://badge.fury.io/py/aiohttp.svg

aiohttp 2.0 release!

For this release we completely refactored low-level implementation of http handling. Finally uvloop gives performance improvement. Overall performance improvement should be around 70-90% compared to 1.x version.

We took opportunity to refactor long standing api design problems across whole package. Client exceptions handling has been cleaned up and now much more straight forward. Client payload management simplified and allows to extend with any custom type. Client connection pool implementation has been redesigned as well, now there is no need for actively releasing response objects, aiohttp handles connection release automatically.

Another major change, we moved aiohttp development to public organization https://github.com/aio-libs

With this amount of api changes we had to make backward incompatible changes. Please check this migration document http://aiohttp.readthedocs.io/en/latest/migration.html

Please report problems or annoyance with with api to https://github.com/aio-libs/aiohttp

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

async def fetch(session, url):
    with aiohttp.Timeout(10, loop=session.loop):
        async with session.get(url) as response:
            return await response.text()

async def main(loop):
    async with aiohttp.ClientSession(loop=loop) as session:
        html = await fetch(session, 'http://python.org')
        print(html)

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main(loop))

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)

Note: examples are written for Python 3.5+ and utilize PEP-492 aka async/await. If you are using Python 3.4 please replace await with yield from and async def with @coroutine e.g.:

async def coro(...):
    ret = await f()

should be replaced by:

@asyncio.coroutine
def coro(...):
    ret = yield from f()

Documentation

https://aiohttp.readthedocs.io/

Discussion list

aio-libs google group: https://groups.google.com/forum/#!forum/aio-libs

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

Changes

2.0.0 (2017-03-20)

  • Added json to ClientSession.request() method #1726

  • Added session’s raise_for_status parameter, automatically calls raise_for_status() on any request. #1724

  • response.json() raises ClientReponseError exception if response’s content type does not match #1723

  • Cleanup timer and loop handle on any client exception.

  • Deprecate loop parameter for Application’s constructor

2.0.0rc1 (2017-03-15)

  • Properly handle payload errors #1710

  • Added ClientWebSocketResponse.get_extra_info() #1717

  • It is not possible to combine Transfer-Encoding and chunked parameter, same for compress and Content-Encoding #1655

  • Connector’s limit parameter indicates total concurrent connections. New limit_per_host added, indicates total connections per endpoint. #1601

  • Use url’s raw_host for name resolution #1685

  • Change ClientResponse.url to yarl.URL instance #1654

  • Add max_size parameter to web.Request reading methods #1133

  • Web Request.post() stores data in temp files #1469

  • Add the allow_head=True keyword argument for add_get #1618

  • run_app and the Command Line Interface now support serving over Unix domain sockets for faster inter-process communication.

  • run_app now supports passing a preexisting socket object. This can be useful e.g. for socket-based activated applications, when binding of a socket is done by the parent process.

  • Implementation for Trailer headers parser is broken #1619

  • Fix FileResponse to not fall on bad request (range out of file size)

  • Fix FileResponse to correct stream video to Chromes

  • Deprecate public low-level api #1657

  • Deprecate encoding parameter for ClientSession.request() method

  • Dropped aiohttp.wsgi #1108

  • Dropped version from ClientSession.request() method

  • Dropped websocket version 76 support #1160

  • Dropped: aiohttp.protocol.HttpPrefixParser #1590

  • Dropped: Servers response’s .started, .start() and .can_start() method #1591

  • Dropped: Adding sub app via app.router.add_subapp() is deprecated use app.add_subapp() instead #1592

  • Dropped: Application.finish() and Application.register_on_finish() #1602

  • Dropped: web.Request.GET and web.Request.POST

  • Dropped: aiohttp.get(), aiohttp.options(), aiohttp.head(), aiohttp.post(), aiohttp.put(), aiohttp.patch(), aiohttp.delete(), and aiohttp.ws_connect() #1593

  • Dropped: aiohttp.web.WebSocketResponse.receive_msg() #1605

  • Dropped: ServerHttpProtocol.keep_alive_timeout attribute and keep-alive, keep_alive_on, timeout, log constructor parameters #1606

  • Dropped: TCPConnector’s` .resolve, .resolved_hosts, .clear_resolved_hosts() attributes and resolve constructor parameter #1607

  • Dropped ProxyConnector #1609

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

Uploaded Source

Built Distributions

aiohttp-2.0.0-cp36-cp36m-win_amd64.whl (258.7 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-2.0.0-cp36-cp36m-win32.whl (252.7 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-2.0.0-cp36-cp36m-manylinux1_x86_64.whl (642.2 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.0-cp36-cp36m-manylinux1_i686.whl (626.2 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.0-cp35-cp35m-win_amd64.whl (257.2 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-2.0.0-cp35-cp35m-win32.whl (251.4 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-2.0.0-cp35-cp35m-manylinux1_x86_64.whl (633.6 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.0-cp35-cp35m-manylinux1_i686.whl (617.3 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.0-cp34-cp34m-win_amd64.whl (254.2 kB view details)

Uploaded CPython 3.4m Windows x86-64

aiohttp-2.0.0-cp34-cp34m-win32.whl (250.6 kB view details)

Uploaded CPython 3.4m Windows x86

aiohttp-2.0.0-cp34-cp34m-manylinux1_x86_64.whl (436.2 kB view details)

Uploaded CPython 3.4m

aiohttp-2.0.0-cp34-cp34m-manylinux1_i686.whl (418.8 kB view details)

Uploaded CPython 3.4m

File details

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

File metadata

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

File hashes

Hashes for aiohttp-2.0.0.tar.gz
Algorithm Hash digest
SHA256 9d73c4b530ff11ca58f96184618180fbc1f93d08fe8da600dfe9c858e471bdfa
MD5 53c81a09db4fb68eec9103ecf682d90c
BLAKE2b-256 b088712947e5c06479ea27a59ebf2ab78bf4358798c0b472dbd2535815f8a293

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 bc6510935f73fb2c8b5a674da1f385ce679f8a44deb82c05a7837e9906cb8f7f
MD5 35c4e4c994f3419f99ff5a0e6d0b0629
BLAKE2b-256 1d32079c6c481df9d5659f1e88dd6c518dab72aaba7a8ce2e74ddddf10683e00

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 fee37e748b886cb430644fe97249ae986bb6e935f251c446a9e2110038ab1386
MD5 82a05597b9e311e475f78b889fd4f154
BLAKE2b-256 13e3f875358d5fdb4e9922744df49da5f256c32e7b2df23bde5518737fc1b40f

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7047ce8553fe390196a115c63d3897464a42fca93270660a0dbf44913ad97b9b
MD5 9f816be27e76d6d9defff341d53e49e5
BLAKE2b-256 87f2d9b35bf7bf6a14e4ef199f79f3673699c02a96a8848f71f121b409b0f2e8

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 eaa474f2212a9dcea53a2581a371cba07849dc1799800289bd6045c9f159003b
MD5 10428d9a36b98d2f99fe7d8e918b3c64
BLAKE2b-256 d0016c835f6200b3c594bd0654f97204a6d773b9b11974357ece024218cfc2f1

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 53d05ff50e8681d93babf8d134f22aca162e667474df5fb20da5e00e63cab5e0
MD5 e9dcf8a1f8b4b6ba3decfe16b5f0b352
BLAKE2b-256 9742f1d01a58c5e1c966e7d10b27073f60100d03e54f14a8bfb850970549161e

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 875cb0ec2b7c2fd103d4efaf4d08058876008aacb60394e8d03b9a4e09ae453e
MD5 1bb85988c4bb0053d2050744ec01a565
BLAKE2b-256 c984fd40c702a352e1ccf288ad50e2e60331ac45ef92e557141c040bd44875df

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 41e77a9853a44cee04a748e573ade7806903b867dd7c5ef99981d8bb777b2c9f
MD5 fe24423ad518aafe90696e1787ec5583
BLAKE2b-256 4b6e947276936e520a532e549b96332988fa0ebd20955eecd36f12fb9ce154f6

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 a24cef553055453aee2347aeac5bc02a946223e88d3079712ba0a54a96e79f7b
MD5 e62c411203cc8392f2a438a08b48bb92
BLAKE2b-256 336c36f959ed83f55f0475a18cecad25e0d4fe9608dcd44db214dffdb5a85801

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-2.0.0-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for aiohttp-2.0.0-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 4bff5fe18c198044873e57c80cb3528b1284e05fc9f89c0bdf920907d9e880c7
MD5 7500f93687645cac9e2d7750ef03f4de
BLAKE2b-256 aa9735b4882d414e2ff934a58c9ce87e66b2f709d0e4909b4821d3a778ef4ef5

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-2.0.0-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for aiohttp-2.0.0-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 a769a1af5c7645bc744c4904ab4662c544b1315a7c0b81e5e6ca5e0dd22a4a58
MD5 60e706140afde657759e0c73038169e7
BLAKE2b-256 8e0716318cfb42dc787e7905dc2eb2b668f89b32f91c042fa459452a6dc81c6f

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-2.0.0-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-2.0.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b7c61dfccdcd69822596066a3f92ccb7412de8f12fc9be30427284f0505cacfd
MD5 8deea890f150060fbac4a800520d8c2d
BLAKE2b-256 8bc0961bdf8dc8795ab1e624c966fcb5411935cfdd4609f85c41514a63f7ed0d

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp-2.0.0-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for aiohttp-2.0.0-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 bda5f69197cd9a7c9cc9839ef4c9c12e53f5a9d52d55c1f775cae534d14fa23a
MD5 862817feb1fa999e5762ca2ed0b95a4c
BLAKE2b-256 d0d991a468edd0731136a28fc9f029e55f2a8bcf77116998d324a1b77734124f

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