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.6 (2017-04-06)

  • Fix web.run_app not to bind to default host-port pair if only socket is passed #1786

  • Keeping blank values for request.post() and multipart.form() #1765

  • TypeError in ResponseHandler.data_received #1770

2.0.5 (2017-03-29)

  • Memory leak with aiohttp.request #1756

  • Disable cleanup closed ssl transports by default.

  • Exception in request handling if the server responds before the body is sent #1761

2.0.4 (2017-03-27)

  • Memory leak with aiohttp.request #1756

  • Encoding is always UTF-8 in POST data #1750

  • Do not add “Content-Disposition” header by default #1755

2.0.3 (2017-03-24)

  • Call https website through proxy will cause error #1745

  • Fix exception on multipart/form-data post if content-type is not set #1743

2.0.2 (2017-03-21)

  • Fixed Application.on_loop_available signal #1739

  • Remove debug code

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

This version

2.0.6

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.6-1.tar.gz (1.1 MB view details)

Uploaded Source

Built Distributions

aiohttp-2.0.6-cp36-cp36m-win_amd64.whl (259.8 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-2.0.6-cp36-cp36m-win32.whl (253.8 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-2.0.6-cp36-cp36m-manylinux1_x86_64.whl (643.5 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.6-cp36-cp36m-manylinux1_i686.whl (627.5 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.6-cp35-cp35m-win_amd64.whl (258.3 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-2.0.6-cp35-cp35m-win32.whl (252.6 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-2.0.6-cp35-cp35m-manylinux1_x86_64.whl (634.9 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.6-cp35-cp35m-manylinux1_i686.whl (618.6 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.6-cp34-cp34m-win_amd64.whl (255.3 kB view details)

Uploaded CPython 3.4m Windows x86-64

aiohttp-2.0.6-cp34-cp34m-win32.whl (251.7 kB view details)

Uploaded CPython 3.4m Windows x86

aiohttp-2.0.6-cp34-cp34m-manylinux1_x86_64.whl (437.3 kB view details)

Uploaded CPython 3.4m

aiohttp-2.0.6-cp34-cp34m-manylinux1_i686.whl (419.9 kB view details)

Uploaded CPython 3.4m

File details

Details for the file aiohttp-2.0.6-1.tar.gz.

File metadata

  • Download URL: aiohttp-2.0.6-1.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for aiohttp-2.0.6-1.tar.gz
Algorithm Hash digest
SHA256 0b285c8a5b2cad31c4040039696ead3cbb8a35fb44eb8ab0b1b7840fba3085f0
MD5 17207ea5e9fe0a4e16d2cc02f683efe2
BLAKE2b-256 663feac06f68743e2654915650de34893391ff1006cd144a48655d2f75084e17

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.6-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 d7466bf92e101cc52ab8aa118588b1fc9665b10a59bd653171b27087f880e63a
MD5 c9d0b3bb4e4aeb0676fb3457563d5f5b
BLAKE2b-256 f9570b88c54f327ecb6e176a8d25233f03c9907c1679f8248f2e481532e20919

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.6-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 4ebb0d75b19d0f411711793267a488671b49402ebf65af8d6a56b48ad7c9ec47
MD5 c6ae43142c01f1130c63965119185e91
BLAKE2b-256 71938dc3bf67c6e04a4ccd9cb907be50c1d13060ece0f7bf1217c2d27f3bfafd

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.6-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4419e5caeb81c3bcfbd7c749212f7873f3c8696db1d3e8d9e515a2de5dab949f
MD5 40f5daaead51dbd6e4136f993bd6d37d
BLAKE2b-256 351ad94737c2170554ce9f1d2189ec4de7d4bad8b5e94b2ad48f77d70f6a122f

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.6-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 1ff4fa51d8c902323f217f0b75914ac7f84a3e2b06e2bc14873daa31b0bc68fa
MD5 43fcb0bc85098d786fb3f090759b22ab
BLAKE2b-256 bc0f6fced0461aa12e75731aed06e40c46bc8dbd5170caeaa74fa69d3c395fa0

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.6-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 787508a954f204873eee631064c30b3382c423a9761678b8e8bf88e3c86f875f
MD5 381746587fa0c5570981a816a8d66b79
BLAKE2b-256 765600db4a12cc5dd49d5eb60e5fe3878bdf5b4b3caa9b5ffc07a0c184b4a6d5

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.6-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 6971be0fcbccab4e736bbda9880a0f5598260997f7d1607b0a7d8b493e8fbc46
MD5 d2d3ed97ce9fdd2089df7fd7612f13cd
BLAKE2b-256 cf3e0d1129bd6cfe0676fac1b0e6ff97c26f72ae29cd95c7c831770f9352755e

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.6-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4a7e10226cee4b69c3eba810fa560622b86df6682e1dfbe21b8cfbbe6eabd8f0
MD5 36cc40b8204762820b46daaf35b29797
BLAKE2b-256 60abb19d90bed6e4dc932d398b5a1583dbc57e38bc4bd14532cb8b29e46b9212

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.6-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 c84dbf4286a23d56a41957a8ec10959643a67dea92fb5cf32f9bdf6d61117048
MD5 004d00ff70474c7d996a49249f8a6b80
BLAKE2b-256 cc8dd9d720f2de9c90b2776098da1e4eebf8c578171946c28a9ac68dcc9e6551

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.6-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 f755fece844063c48bdda95ce51f7706f7344dd32c8f20ad99f0367a8c62dcc3
MD5 238daf1765b06bb54128b7c810d62405
BLAKE2b-256 bc6ce2e9eb6c3d6b6a9adc938af06da0cc86c12bf272c9c9e0691db680f11c76

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.6-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 aa74c29d54d0f2c99aa2a3f39922030f46442959dfcc2da77c2317814c0d43b7
MD5 facf87a841e408cc4e3c9812746eadb0
BLAKE2b-256 8f706ed1452a0d724886ed188ddd884049136839d3fbcaf36292c245ad7ac290

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.6-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 185beeaa223360123ee0cb8466e2d2d55e268f8773c6423b93d5e90216ce4f9a
MD5 21bd3a4ebaf943fbe13a90974a29fd72
BLAKE2b-256 a65b6b0de3d930fae2ef3a9af64f6cd7959ecdfecfd14cd6ad3004fac6d662ea

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.6-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 c61668680a509641a02bebf695cf5d5d1a2347d1cd59f9df89e5a50129a9c776
MD5 3b0c093c16e3d41b19f2196e4dd5b246
BLAKE2b-256 c77382bd8ee6b8d9096ecc9c9d700e3404f5656b336379b1664ce7af1df48cf7

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