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

Uploaded Source

Built Distributions

aiohttp-2.0.3-cp36-cp36m-win_amd64.whl (259.1 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-2.0.3-cp36-cp36m-win32.whl (253.1 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-2.0.3-cp36-cp36m-manylinux1_x86_64.whl (642.6 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.3-cp36-cp36m-manylinux1_i686.whl (626.6 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.3-cp35-cp35m-win_amd64.whl (257.6 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-2.0.3-cp35-cp35m-win32.whl (251.9 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-2.0.3-cp35-cp35m-manylinux1_x86_64.whl (634.0 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.3-cp35-cp35m-manylinux1_i686.whl (617.7 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.3-cp34-cp34m-win_amd64.whl (254.6 kB view details)

Uploaded CPython 3.4m Windows x86-64

aiohttp-2.0.3-cp34-cp34m-win32.whl (251.0 kB view details)

Uploaded CPython 3.4m Windows x86

aiohttp-2.0.3-cp34-cp34m-manylinux1_x86_64.whl (436.7 kB view details)

Uploaded CPython 3.4m

aiohttp-2.0.3-cp34-cp34m-manylinux1_i686.whl (419.2 kB view details)

Uploaded CPython 3.4m

File details

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

File metadata

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

File hashes

Hashes for aiohttp-2.0.3.tar.gz
Algorithm Hash digest
SHA256 e7ab4bc22e36a455d604d6fce8b51afd41141d76052dfce3e447121af4e77acd
MD5 a8200672a581211a196a1419d2dcf9b8
BLAKE2b-256 e4827200bb3f94cf6009b3213a9d170525395fbc2587d97d961034785597b58d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.3-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 1a77f5c0e3e6261aa48ba4ecd94bf2bf95f487c8058a90a5b26d9c56446016d3
MD5 5bf9820f0f0e9f11e17b96cb23259894
BLAKE2b-256 428730833cca40e0f46d7ab68d634ac17b33379e50e68c91caa273c8a9eebd78

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.3-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 5c04df10427f39dcfca08919d27587035a5bc22df1fd04c09c2dded1d7d3b044
MD5 6261c5e09cb47d280dbc737f720dcb4e
BLAKE2b-256 9f7f705610796155af2e7d76706c7fb54ff29fb59183e9a4912a2a7cf7dbe0f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 69d6ae27a23529e7b7cfdcffd02ce914a45f26cb7b0567c00ec4e6e14985216c
MD5 b989cfaf72ce364e5e23858e2d866e6b
BLAKE2b-256 a0c94d8e75017e9d109422743adeff61b8776b12dffaabfae5c6a2eeb90e1f42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.3-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 bee84d233f2daf38b8adf21989d8f607cbc39e8c7cb4637560406a7d8a2e9dff
MD5 ba39851bce2cb8278167fd25f50566f7
BLAKE2b-256 70b234c8f045c36a2822bc79765806218f16d49cedfb9d321867aece54f82e72

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.3-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 2f029bc8a2ee287c119462d1ceed51c04dadc6a0400742e6536d5158d06b7481
MD5 a41aeeff01d5fc86c5b220294ed46d78
BLAKE2b-256 378cc5f09d22ab193d00e20823e3dcb71590f27bd8a331e76b7da9f37679f7a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.3-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 f9d21bf44238089b40fe26ca18126eaff503de89de4ffac5f17fab7f4addce90
MD5 4ae69f5615b24f9495c8515c17c40d97
BLAKE2b-256 6ea864e613780f4c1fe4b6e6594b6562b98e67f1b05a9931d81b63c012cb9952

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 db43d1fe9c4ac6cc928fde5772f56ef35489f475ee680c983e2c20f663ef016b
MD5 aab7dfe003c84b888c209f94767acbcf
BLAKE2b-256 3c0332416b53af47075e99a397fdc737556b12b646502a4dee3c95aee53f853a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.3-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 63f25192d98518cae9d6b9c0f5ebefca039ff0d71f4ed5dc76200a7f22852f45
MD5 b5b68349baa6e928d6c1d867c214de73
BLAKE2b-256 ecae1f53d9e8d78cf3cbfdea8cdfb4557153ede9a0521046f84ef01458b7de5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.3-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 947d2000ac6872b0345567d9897132f5a1139ab20d573a1f1f00a80923515564
MD5 f41b656b28e17c0151687771b459cbe3
BLAKE2b-256 caf7241235d2e11f1aa1f573c3c1727ff8c2f6cdd3b22f4585c5399f68e90ed1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.3-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 3ff40440ec1cca04969cc801ef7e2a0436a6e73324d05d0fb519c8dbc0949141
MD5 e661c3f4ece600696790ab171e8f7908
BLAKE2b-256 83fafab4a33573c823d0da4b9f85e36d092db750ccb8cab4d9f0618be6a4e424

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.3-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 cdc8de7ff297e32b3dc9185bf42500d622ae82751c4051e979339209194a15d7
MD5 6110de7a90c5ddd5fb61013230e41bb8
BLAKE2b-256 bd3bfe8317f27ee2cebb9d50391bb7c685cfcfd8e5886f8db39b6f8ed6ea6ca9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-2.0.3-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 92b39e4986c058d261ae911306ec698c3cdefc1f1248d09bab38c6aa7fe0f4ae
MD5 a2ec7b768cfa7bebb9029a8b05aa9f22
BLAKE2b-256 a9f41837ca87f2f45d2cdfe18418f55125308225154858634c799e81d600a08e

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