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.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

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

Uploaded Source

Built Distributions

aiohttp-2.0.4-cp36-cp36m-win_amd64.whl (259.3 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-2.0.4-cp36-cp36m-win32.whl (253.3 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-2.0.4-cp36-cp36m-manylinux1_x86_64.whl (642.8 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.4-cp36-cp36m-manylinux1_i686.whl (626.9 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.4-cp35-cp35m-win_amd64.whl (257.8 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-2.0.4-cp35-cp35m-win32.whl (252.1 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-2.0.4-cp35-cp35m-manylinux1_x86_64.whl (634.2 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.4-cp35-cp35m-manylinux1_i686.whl (617.9 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.4-cp34-cp34m-win_amd64.whl (254.9 kB view details)

Uploaded CPython 3.4m Windows x86-64

aiohttp-2.0.4-cp34-cp34m-win32.whl (251.2 kB view details)

Uploaded CPython 3.4m Windows x86

aiohttp-2.0.4-cp34-cp34m-manylinux1_x86_64.whl (436.9 kB view details)

Uploaded CPython 3.4m

aiohttp-2.0.4-cp34-cp34m-manylinux1_i686.whl (419.4 kB view details)

Uploaded CPython 3.4m

File details

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

File metadata

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

File hashes

Hashes for aiohttp-2.0.4.tar.gz
Algorithm Hash digest
SHA256 9471ec0a59ffa7810fe1d82fb70cacad045d741c6522328660925628c6001730
MD5 16d1c51ddf21b2198fc630aa3413d46d
BLAKE2b-256 e96e550f4591bfa358c56e4f8abfdb6d99d747cf20d22af3cd56956165f7be81

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 bd03d0a8a0c7afeafd1c8a3cbce2cf1d41c509963c8211490924c8789eebd523
MD5 51e4a31ef6657e3ccf1598dce9413e62
BLAKE2b-256 f84ec590da806fa04f5ce19ba3e48190805c92ebcbbc5567a25090087d299e40

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.4-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 9c92b4da6402ef9eb376f8da4960535987369fdb05790cdcb2f35b373059f0b4
MD5 2526ea9c454810184a7ae6a9b238ec7e
BLAKE2b-256 67bbfa652b554b0ea04f97ca47581101abafb2afd4ac2b23243a76e23532fb6d

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 893d9bd45674a074e1ae201a1ff3ed8cfae52990c9dcc663705add3615cc604e
MD5 8524a74528ba4875c4be4c5dcd2ce3bb
BLAKE2b-256 ecc68be6d208a4d65a0f191542850d7068163e76a0ab66a2ed525897bf5b92ad

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.4-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 043b083030e2b06c384225e3c92ab95c0dacdf8d82effdf9dc1392b46862f670
MD5 a56cb0823151154f9dff58565276ea90
BLAKE2b-256 14ea47fbd4c2fb2ced99957296825fe72d8cc7212617ea9de4b9b3237db14245

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.4-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 a9177b01e163f037c0732ff9485d450573746fda18644089556a102a0a2364f1
MD5 e86b8d89f5bd7ad5fcbbb6b4a8f7ebbb
BLAKE2b-256 967b5f529eda81ab9e78deeb3f5a60c4cbf9f2f138d9029fcb998b1259e50902

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.4-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 c3a0ab445c7f82f6f3eba78004bef8a91c58548a8948bef76ea3087fbd04956b
MD5 cee830ef4a8c4daebe6e4a785efa58bb
BLAKE2b-256 53f6bf25eea49e05d34a694b03cdbe9677a62141f3df4f384d81deb29f6f35fc

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.4-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0f4738047988494f36d855381b6ea60b9d024f229895026912215d73212e150e
MD5 d91106bf4b33b65204bd5fb1e3aea7fc
BLAKE2b-256 e1956c29b86db596c345d3c088a9abd6b42fa7629c8f652f8b2682642c616c1f

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.4-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 495b3de55754609fcbcc07a7d5be6905fe0395ecb73b80a80ca55a619c7bc42b
MD5 8403e9bb2aad6f2a343ef2a84a5badbe
BLAKE2b-256 0229f393a68cd780c6310ff4a72a883830ae5ef982ddb088de036c7511da9fff

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.4-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 6e1702162479ca7afecaeb9193d93d7ef92261d0b4b6d39108cb64c408e2c849
MD5 e98bf7819653b770d15e7b1f4c32b593
BLAKE2b-256 8b2a6bd41de03268ed1d2ac85dde3085f100062e4c4134d847098a46c1236d66

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.4-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 c00d332c5720b6d2fb862c4a01c5ef5349481c2a9eca723c1bde3114f92d28e6
MD5 01c67f9f9424628883632f59a937c151
BLAKE2b-256 4902c762eb1e8b7417551c117a104328ad7f7fca0869027aee767efc16abc0b3

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.4-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b60d303f247a0e9ffd452767acdc4aa916e091f5fd38eb82094db66999b1d5c0
MD5 c04e9e25e7380d343b772a33c45dca82
BLAKE2b-256 7e8f3d2bcbb69d90b89f39ad83100fe83c68848d6fb4e873474cea99f1dabcf5

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.4-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 71f626bc45ebf309637da90ab646464f1b2f9ad630dbe37b90a21fea0403e5f3
MD5 9f960658932c35a653741d9b420e9b37
BLAKE2b-256 e76e83675cd2b660ceadab384c17766cc90fe0a8cefaefc2f26aecf2d272fd69

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