Skip to main content

http client/server for 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

Major aiohttp2.0 release!

Warning! This is not final release. It contains backward incompatible change, please check compatibility before installing on production systems.

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 problem across whole package. Client exceptions handling has been cleaned up and now much more strait forward. Client payload management simplified and allows to extends with any custom types. Client collection pool implementation has been redesigned as well, now there is no need for actively releasing responses, aiohttp handles connection release automatically.

Another major change, we moved aiohttp development to public organization https://github.com/aio-libs The aiohttp community would like to thank Keepsafe (https://www.getkeepsafe.com) for it’s support in the early days of the project.

Alas 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

You can install and test this release with:

pip install https://github.com/aio-libs/aiohttp/archive/2.0.0rc1.tar.gz#egg=aiohttp-2.0.0rc1

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.0rc1 (2017-03-14)

  • 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.0rc1.tar.gz (605.7 kB view details)

Uploaded Source

Built Distributions

aiohttp-2.0.0rc1-cp36-cp36m-manylinux1_x86_64.whl (641.6 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.0rc1-cp36-cp36m-manylinux1_i686.whl (625.7 kB view details)

Uploaded CPython 3.6m

aiohttp-2.0.0rc1-cp35-cp35m-manylinux1_x86_64.whl (633.0 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.0rc1-cp35-cp35m-manylinux1_i686.whl (616.7 kB view details)

Uploaded CPython 3.5m

aiohttp-2.0.0rc1-cp34-cp34m-manylinux1_x86_64.whl (435.7 kB view details)

Uploaded CPython 3.4m

aiohttp-2.0.0rc1-cp34-cp34m-manylinux1_i686.whl (418.2 kB view details)

Uploaded CPython 3.4m

File details

Details for the file aiohttp-2.0.0rc1.tar.gz.

File metadata

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

File hashes

Hashes for aiohttp-2.0.0rc1.tar.gz
Algorithm Hash digest
SHA256 df6cff16929e560078f9d1919b52ffb966f4642d740645518068f16ede66260c
MD5 21b4172dcda4c81fec6a3e67ea2f9686
BLAKE2b-256 bdd492f4205b683586a5f475b46eab1699e0c5551c7b1f6c354a3af4f6cf0bfc

See more details on using hashes here.

File details

Details for the file aiohttp-2.0.0rc1-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-2.0.0rc1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ce4dbb90ca1a005bf3c2fff576c183e0556fd20eb856c4e7f0e521733d0071b4
MD5 99ca7a9b44685fd5f68456872e157419
BLAKE2b-256 70670cc5fd3427ae4267c8ffde8c6a485e3f6be5ac81b8b8ae1cf903be8d359f

See more details on using hashes here.

File details

Details for the file aiohttp-2.0.0rc1-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for aiohttp-2.0.0rc1-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 35744f0810912c15981d5e105dc4b0b7c71d488ce20b3b6e18d35fc589fbb61a
MD5 ced81b3ebaf16435b3f9d672537e0e80
BLAKE2b-256 68c5a5b629baedd3fc4bfb70ea5db28342cbee6c8ad11ba607680001d7d48ba9

See more details on using hashes here.

File details

Details for the file aiohttp-2.0.0rc1-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-2.0.0rc1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9ae4ad449c4b2b57442ffb4f1776991015bcdd9439ed1ebdd2a005db6792a70c
MD5 e3c9b7ad0768707df59830c7679d3731
BLAKE2b-256 444b696b58512cab914f07eac002ea9931c7cac4d5e66cbf96c673bf219a46bd

See more details on using hashes here.

File details

Details for the file aiohttp-2.0.0rc1-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for aiohttp-2.0.0rc1-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 608754bb28f0305428bfe07a9bb79bb094b85238c95f8ede894d068d20a91262
MD5 b61eeec8e30e2f15630c9f56b86f6b13
BLAKE2b-256 d50a52229644ce70fd13d8dd9ae02d2be7576b25c9c86862b4ecac1a31f4f9bf

See more details on using hashes here.

File details

Details for the file aiohttp-2.0.0rc1-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-2.0.0rc1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 57a37ed177e40feeede19dc454f63de0114bab62b6f32f052470180828ebd6ad
MD5 6cad2bb21b301ce1e82e19dca0271054
BLAKE2b-256 5d9848fe25cf568e2b31d52ff90cffcab842d382d8d085f314b5a3d0dfd4732c

See more details on using hashes here.

File details

Details for the file aiohttp-2.0.0rc1-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for aiohttp-2.0.0rc1-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 2a4804da7a7a56026ae8a7076f87f24f214b68e39d09c782a9bed5c9ad8dc585
MD5 4d538498fb44ba7cb5963641c87dd3d2
BLAKE2b-256 dcf4ad77079cbb6e95bd2191f78dc665442277860619b8ac183c05d772111142

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