Skip to main content

Async http client/server framework (asyncio)

Project description

Async http client/server framework

aiohttp logo

Travis status for master branch codecov.io status for master branch Latest PyPI package version Latest Read The Docs Chat on Gitter

Key Features

  • Supports both client and server side of HTTP protocol.

  • Supports both client and server Web-Sockets out-of-the-box without the Callback Hell.

  • 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):
    async with session.get(url) as response:
        return await response.text()

async def main():
    async with aiohttp.ClientSession() as session:
        html = await fetch(session, 'http://python.org')
        print(html)

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

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 wshandle(request):
    ws = web.WebSocketResponse()
    await ws.prepare(request)

    async for msg in ws:
        if msg.type == web.WSMsgType.text:
            await ws.send_str("Hello, {}".format(msg.data))
        elif msg.type == web.WSMsgType.binary:
            await ws.send_bytes(msg.data)
        elif msg.type == web.WSMsgType.close:
            break

    return ws


app = web.Application()
app.add_routes([web.get('/', handle),
                web.get('/echo', wshandle),
                web.get('/{name}', handle)])

web.run_app(app)

Documentation

https://aiohttp.readthedocs.io/

Demos

https://github.com/aio-libs/aiohttp-demos

Communication channels

aio-libs google group: https://groups.google.com/forum/#!forum/aio-libs

Feel free to post your questions and ideas here.

gitter chat https://gitter.im/aio-libs/Lobby

We support Stack Overflow. Please add aiohttp tag to your question there.

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

Changelog

3.3.0 (2018-06-01)

Features

  • Raise ConnectionResetError instead of CancelledError on trying to write to a closed stream. (#2499)

  • Implement ClientTimeout class and support socket read timeout. (#2768)

  • Enable logging when aiohttp.web is used as a program (#2956)

  • Add canonical property to resources (#2968)

  • Forbid reading response BODY after release (#2983)

  • Implement base protocol class to avoid a dependency from internal asyncio.streams.FlowControlMixin (#2986)

  • Cythonize @helpers.reify, 5% boost on macro benchmark (#2995)

  • Optimize HTTP parser (#3015)

  • Implement runner.addresses property. (#3036)

  • Use bytearray instead of a list of bytes in websocket reader. It improves websocket message reading a little. (#3039)

  • Remove heartbeat on closing connection on keepalive timeout. The used hack violates HTTP protocol. (#3041)

  • Limit websocket message size on reading to 4 MB by default. (#3045)

Bugfixes

  • Don’t reuse a connection with the same URL but different proxy/TLS settings (#2981)

  • When parsing the Forwarded header, the optional port number is now preserved. (#3009)

Improved Documentation

  • Make Change Log more visible in docs (#3029)

  • Make style and grammar improvements on the FAQ page. (#3030)

  • Document that signal handlers should be async functions since aiohttp 3.0 (#3032)

Deprecations and Removals

  • Deprecate custom application’s router. (#3021)

Misc

  • #3008, #3011

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-3.3.0a0.tar.gz (722.8 kB view details)

Uploaded Source

Built Distributions

aiohttp-3.3.0a0-cp36-cp36m-win_amd64.whl (477.9 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-3.3.0a0-cp36-cp36m-win32.whl (460.7 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-3.3.0a0-cp36-cp36m-manylinux1_x86_64.whl (875.8 kB view details)

Uploaded CPython 3.6m

aiohttp-3.3.0a0-cp36-cp36m-manylinux1_i686.whl (846.4 kB view details)

Uploaded CPython 3.6m

aiohttp-3.3.0a0-cp35-cp35m-win_amd64.whl (475.6 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-3.3.0a0-cp35-cp35m-win32.whl (458.6 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-3.3.0a0-cp35-cp35m-manylinux1_x86_64.whl (857.7 kB view details)

Uploaded CPython 3.5m

aiohttp-3.3.0a0-cp35-cp35m-manylinux1_i686.whl (827.9 kB view details)

Uploaded CPython 3.5m

File details

Details for the file aiohttp-3.3.0a0.tar.gz.

File metadata

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

File hashes

Hashes for aiohttp-3.3.0a0.tar.gz
Algorithm Hash digest
SHA256 4351d6b9df5a6e389208f665e8c4c5db7ade7b06f564b3e7bee6cf713628c1b5
MD5 44a31cf126a932a741a6dc4fc35e0712
BLAKE2b-256 e0ca1804e24313a80445efad9c7ead32774934b5fd6c2d5c16723d2701c47f35

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.0a0-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.0a0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 caabace30fed76756de657886a700b04919575799eb7fac5848385baf59de6fb
MD5 d4e4bcd09a1e8c6ded6b5d9d0258ecdb
BLAKE2b-256 db17abedaa9923010381e825853b18f4e077247f068e6977c6e82544d03813be

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.0a0-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.0a0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 fc647a08ae3b2b7a0da1064a2f535490f8d628095001969a5d2fc4fec3737764
MD5 44f61565324f514243669cf584afc522
BLAKE2b-256 b62d8a4a3d91bae8ec8f4344533d4d378f035006571f19feec8d8ccaeb64b65a

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.0a0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.0a0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 63034e15986b438cabb69da33aa4d17f1df34ed8fdb8e5ed7a0e23eccc7a8818
MD5 a2978da64690905d35c2d8f7477a2228
BLAKE2b-256 a7ff10e4cd9d1c7cbdea4155d31881ec47392c699eb49b49293eab01575c9831

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.0a0-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.0a0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 5793f153e4082da8e12af4e2dbc598ceade0bc6d1164cd1591c83e45cd50c541
MD5 ce155943acb55ee4c4b395043ff0ee5a
BLAKE2b-256 d2618821d09eb2ba97cb331f2b395139a932bca0455b5091038e91a5038c985d

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.0a0-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.0a0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 7ab7416ca103c116f3d860bdb038c2776bb75027a57e17b97cd7279d6915930f
MD5 3a4d7dad5d7eb41f47cfb78d51201e9a
BLAKE2b-256 0ba1e68134be65e6b2a55d20d3214309dc9e12fabbef1e1d0833a62e04f07fc0

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.0a0-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.0a0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 805bb36918446a5bda653783c4b5c50404572d9cbb12c27bb1ca0b726e8916b0
MD5 92848b4769e826817bc3227d74b4734d
BLAKE2b-256 efc85c5601aea0d63b3889680d8133769656ef78f226e5b4c5d1d6195a13a162

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.0a0-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.0a0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c7918e3dbb09e79b5a3111710d9a3fdd9edbc4fdad97e2454ca2c8a461409027
MD5 d08ccca4833f7f76ece07fb57714d287
BLAKE2b-256 18f94bd664c743dcd29c996dfc70bee9eb31df8c9f7fbbad8be2790748374efc

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.0a0-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.0a0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 7030dcfd60711c6b240d5cc785d83ed362afe024d3bd8b502869b81af667e64a
MD5 df551ab3932aae8957fd1019e08ded6d
BLAKE2b-256 35e8f4383e2e4db6b2854e059d938dc0d45844ada8a8f2f0b149dee127c40ff4

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