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

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

Uploaded Source

Built Distributions

aiohttp-2.0.5-cp36-cp36m-win_amd64.whl (259.5 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-2.0.5-cp36-cp36m-win32.whl (253.5 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-2.0.5-cp36-cp36m-manylinux1_x86_64.whl (643.0 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.5-cp36-cp36m-manylinux1_i686.whl (627.1 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.5-cp35-cp35m-win_amd64.whl (258.0 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-2.0.5-cp35-cp35m-win32.whl (252.3 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-2.0.5-cp35-cp35m-manylinux1_x86_64.whl (634.5 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.5-cp35-cp35m-manylinux1_i686.whl (618.1 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.5-cp34-cp34m-win_amd64.whl (255.1 kB view details)

Uploaded CPython 3.4m Windows x86-64

aiohttp-2.0.5-cp34-cp34m-win32.whl (251.4 kB view details)

Uploaded CPython 3.4m Windows x86

aiohttp-2.0.5-cp34-cp34m-manylinux1_x86_64.whl (437.1 kB view details)

Uploaded CPython 3.4m

aiohttp-2.0.5-cp34-cp34m-manylinux1_i686.whl (419.6 kB view details)

Uploaded CPython 3.4m

File details

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

File metadata

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

File hashes

Hashes for aiohttp-2.0.5.tar.gz
Algorithm Hash digest
SHA256 ea5d251f8a0a2734e3c19f293307560b9bf52b300e69fdae3060bffb0c433714
MD5 68e896d943db6059f97013ea4947b49a
BLAKE2b-256 baf059bead4038ccc3f42d2dfdcab43bfb6411684bfb0d0764948c778e0f15a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.5-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 0d0b34979c67c2d80443d3b30ce0a7ded92379c0b9892b98ca0c6c92dd03feb4
MD5 d4c9913f69d0ee5552e55f8fadb4fe68
BLAKE2b-256 59b7dbad48fb9bab266259f0979f88ad61d028a0b70a16ceeb340ae946b2ac15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.5-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 c1683ff2734b11105a085fc51bc1dd9f689689d17701dbe86a5f0eb575ff7b58
MD5 c720dcc923b3b910b4ac14dd1267e493
BLAKE2b-256 baefc56f418a73681e48683d647480690ca42a91c9091545be7e98ae5f4f43e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.5-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 59e5d0007857e0c10dc2c2aff6a6edab7719b64ebac0880a5f03d8033514a287
MD5 09351f21094ec3d60135630c01dc03d3
BLAKE2b-256 b2edf66e1484b4247a21db7851706dd6234fdde69f6a8db2731ccaee498e4ef6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.5-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 94aff570b3e8fe9659e7d42bc8811914c0fcf6a4a6f4fc7aa3cbf1440b03df6b
MD5 1a4c6304353bf01ecf401789225d1b6e
BLAKE2b-256 bccc4145eee8b0149a615375172ca7e34438688a008715d8a1a58c5918693672

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.5-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 95d2d2345fafa5de31b472443ca9a06e722af7be7e7364be033da5d60be272fa
MD5 c31ec86fbb05aba711f1f859ce8e9b50
BLAKE2b-256 de19ce25aa37c996d7b157aab9b002949d3a2fb42eaee60fd5471db1a057ad47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.5-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 7d189387d9e8b6b2c7d9a8276f2f760bbdaced861f05960a08e77413a90b4f1d
MD5 58b5c78e609949cf59e465ad3ee3c811
BLAKE2b-256 743fa27028c78281639e83197e0694f6ac37a818bea2f697dee18e6a1a4caa26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.5-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 acad1246adb4ff92ec4c3479118195de0f4a30df992e569fa5d0ae2fecbaa04d
MD5 77ef86ddcfac400fbebd91061f04fe26
BLAKE2b-256 0f3c306aa198637cfaa909c7c6b35d6dd06c46492528a8288ee6fcbf48afc95e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.5-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 72dae304a7aae4ba37036fa78f12c5d172c8c61372c7b7b826bbf80cbc60fc26
MD5 dd0632b334c3b257bc8507371ae099a7
BLAKE2b-256 7327f93d9f94e54358206488f12eeaa244b4534d6e4c2aa1a24c6b1fe7528ca8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.5-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 74e3ce0bf3b48ed853ce4806af079620337f048d00e14743dcc35c26329b7af4
MD5 7446a29548aaae43833ff491b049f9c5
BLAKE2b-256 004a3a2c616e4d96d232f022a602c57afb44087b7022ca0425a4505ff2a92cac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.5-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 cd97f51af2a05b16139435dd68b91c3adbb41069b32f2871c20dd43aeae702c0
MD5 33abd52c8d36fdc5eaa1db0bc5d5c471
BLAKE2b-256 d1b942cec32bf218291ffdc5b54645e393b382cd84ceabcbaed9c1c6581b6b7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.5-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ed5096e883bffc2aa7cff7947c00e24c1ae9f6564b77a20e1f6c21f859d21e8c
MD5 0ff9d60b74da391db554cb6a1d4ed2e7
BLAKE2b-256 95eb7629df3681ffb6134e5a0540768c9d227b174551c30128a14b517d8dc5c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.5-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 ec40c131814650ea4f97449f3ad6431a58b4df6ddaa8b2d1e2da6f1c14129185
MD5 1ee3e16ba2160d728b6c83fe5e878691
BLAKE2b-256 e0c1110244b67ba6b2162649eeafc627e90f14237f2ff659091b25e3b6259293

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