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.1 (2017-03-21)

  • Fix allow-head to include name on route #1737

  • Fixed AttributeError in WebSocketResponse.can_prepare #1736

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

Uploaded Source

Built Distributions

aiohttp-2.0.1-cp36-cp36m-win_amd64.whl (258.8 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-2.0.1-cp36-cp36m-win32.whl (252.8 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-2.0.1-cp36-cp36m-manylinux1_x86_64.whl (642.3 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.1-cp36-cp36m-manylinux1_i686.whl (626.4 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.1-cp35-cp35m-win_amd64.whl (257.3 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-2.0.1-cp35-cp35m-win32.whl (251.6 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-2.0.1-cp35-cp35m-manylinux1_x86_64.whl (633.7 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.1-cp35-cp35m-manylinux1_i686.whl (617.4 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.1-cp34-cp34m-win_amd64.whl (254.3 kB view details)

Uploaded CPython 3.4m Windows x86-64

aiohttp-2.0.1-cp34-cp34m-win32.whl (250.7 kB view details)

Uploaded CPython 3.4m Windows x86

aiohttp-2.0.1-cp34-cp34m-manylinux1_x86_64.whl (436.4 kB view details)

Uploaded CPython 3.4m

aiohttp-2.0.1-cp34-cp34m-manylinux1_i686.whl (418.9 kB view details)

Uploaded CPython 3.4m

File details

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

File metadata

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

File hashes

Hashes for aiohttp-2.0.1.tar.gz
Algorithm Hash digest
SHA256 68c77f74bf28ddc1fb509dc89a3c97ff22e1649abbb4a35aad7f2c91f6d17d93
MD5 d90c9d472755f169e8ebb9c8f353fae9
BLAKE2b-256 830d90a20e45723f4da5c584655692d43076f47911f87e53be26aa76ea705889

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 d8a67cbf6391da116ddcc9016c4eccd3cc7938a11dfd0ef0b12e42e67babc8cf
MD5 58b4ce8579f1e40062d729124cb32309
BLAKE2b-256 c10090eb476784600a4f289c4b447a786b63ebcaaa716e335291723ee0f648cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.1-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 244d1864177e6ca16281501acd0aa9f729474f03135f46e4e5e7be78b64d19d3
MD5 1e65e0c6280aa328ab1ddc7c9e5022fa
BLAKE2b-256 4078e300d3d8faf35bea4aa834b411ecc88054ad8789ad077b89c6dbadaa79da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d579734ec1d50f62b42caed5c97d5810d1fbdad944a8eebb388813a6a7bf9874
MD5 f139d815b38c179659b6b4368aaa580b
BLAKE2b-256 5047c8c6d05cd6ede205503e1f2e91caf1db540e6366609819b43c32b2e900ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.1-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 1ba00f86d02b7160beaead2bfb294d9deedc81ce8a6e71b6d4e0997f381f7c33
MD5 36f64243c54b5f45090254501df8d7ac
BLAKE2b-256 520f419b9affaf13df660a8da960aab8386ada9c39c19cb141c4dfbbbdee4b61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 538e48401939cee93b8df5edca042d18ae59775e3f232754d4e1157d003b2b3e
MD5 f6f3509b359db56e6eb60d8927cc0766
BLAKE2b-256 19217ad019942741ee48e5ff2ad535df3947bbb375314f9809be7762e837ac75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.1-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 3577fce1699e539b2c420e14513dfc3321eea813022512b4c91cba1e4e33c931
MD5 3b064b12528dea8025211e0cf9adf2bf
BLAKE2b-256 c6f1c0633d2b49172dc59e2e204f64f0998ede28a04e753e951c9325796a2bde

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 227245f1bdfeab9d2a314daabfa23cd2ebc15f002fe945b19973a8d957876254
MD5 28af822d2a9074c7859a7e8e89ddc3b1
BLAKE2b-256 878a98cc8e08b32366446647510d3ac56f6c79541507224b576c345c565def0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.1-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 fc2978c3ab5d414c2f97a9a2232f9d42e969cc2793e96fde7b14b23178430f8b
MD5 5111eb1d34afd7919a555543c0ee5e2a
BLAKE2b-256 738398d752ef6f83f3dba8e306838bb501f786fa0c9989a38127481143ffc30d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.1-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 940cff2688b6c83ec505c9fc1ef9aef61d90c5bed45fc28970bd45696f1d650d
MD5 35f08a7108e3bcb80c1cdcbddd32e4a8
BLAKE2b-256 61b183bcfeb8c3ba2a44064608ce74c415b65a8ba83561e38906ccfb8a7d0933

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.1-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 0a6e1dd02dc6aea0c50a321cd6926d75b281b7dd68909695856b050564e252d7
MD5 5b4f85770e4f82a5578bf9d8969db5e2
BLAKE2b-256 2ee6eca7da8bed3b1260702589fe22d851e4f2b3c32ff36e09f8ddd3f2d64367

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 90e5adf01f321a0bd881942effa1f1c2986a3d1a18caa0058cd728ba7d47bd76
MD5 2fac6f1cdcc2f9d0a35f6f07c395199f
BLAKE2b-256 b0cee8507d605960869e8f2b5645fd5e9dee766330095101673862989ed548ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.1-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 251b8e1cf27a7c23a8b9cb5bf5b1caa06567cf5b7278682a31510d0d65294894
MD5 2e81ebfcf10625e47164f1df9721ffd1
BLAKE2b-256 d8ee454f799276d44a79bf0fe0cd78c152ae62dcc3755ddd8aa92df06eda544d

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