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.2 (2018-06-12)

  • Many HTTP proxies has buggy keepalive support. Let’s not reuse connection but close it after processing every response. (#3070)

  • Provide vendor source files in tarball (#3076)

3.3.1 (2018-06-05)

  • Fix sock_read timeout. (#3053)

  • When using a server-request body as the data= argument of a client request, iterate over the content with readany instead of readline to avoid Line too long errors. (#3054)

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

Uploaded Source

Built Distributions

aiohttp-3.3.2-cp36-cp36m-win_amd64.whl (478.2 kB view details)

Uploaded CPython 3.6m Windows x86-64

aiohttp-3.3.2-cp36-cp36m-win32.whl (461.0 kB view details)

Uploaded CPython 3.6m Windows x86

aiohttp-3.3.2-cp36-cp36m-manylinux1_x86_64.whl (876.1 kB view details)

Uploaded CPython 3.6m

aiohttp-3.3.2-cp36-cp36m-manylinux1_i686.whl (846.7 kB view details)

Uploaded CPython 3.6m

aiohttp-3.3.2-cp36-cp36m-macosx_10_12_x86_64.whl (477.5 kB view details)

Uploaded CPython 3.6m macOS 10.12+ x86-64

aiohttp-3.3.2-cp36-cp36m-macosx_10_11_x86_64.whl (487.1 kB view details)

Uploaded CPython 3.6m macOS 10.11+ x86-64

aiohttp-3.3.2-cp36-cp36m-macosx_10_10_x86_64.whl (489.5 kB view details)

Uploaded CPython 3.6m macOS 10.10+ x86-64

aiohttp-3.3.2-cp35-cp35m-win_amd64.whl (476.0 kB view details)

Uploaded CPython 3.5m Windows x86-64

aiohttp-3.3.2-cp35-cp35m-win32.whl (458.9 kB view details)

Uploaded CPython 3.5m Windows x86

aiohttp-3.3.2-cp35-cp35m-manylinux1_x86_64.whl (858.0 kB view details)

Uploaded CPython 3.5m

aiohttp-3.3.2-cp35-cp35m-manylinux1_i686.whl (828.2 kB view details)

Uploaded CPython 3.5m

aiohttp-3.3.2-cp35-cp35m-macosx_10_12_x86_64.whl (476.1 kB view details)

Uploaded CPython 3.5m macOS 10.12+ x86-64

aiohttp-3.3.2-cp35-cp35m-macosx_10_11_x86_64.whl (484.3 kB view details)

Uploaded CPython 3.5m macOS 10.11+ x86-64

aiohttp-3.3.2-cp35-cp35m-macosx_10_10_x86_64.whl (486.4 kB view details)

Uploaded CPython 3.5m macOS 10.10+ x86-64

File details

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

File metadata

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

File hashes

Hashes for aiohttp-3.3.2.tar.gz
Algorithm Hash digest
SHA256 f20deec7a3fbaec7b5eb7ad99878427ad2ee4cc16a46732b705e8121cbb3cc12
MD5 dfaadf259d1f677a286d203e9470d2a0
BLAKE2b-256 726a5bbf3544fe8de525f4521506b372dc9c3b13070fe34e911c976aa95631d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 96bb80b659cc2bafa160f3f0c346ce7fc10de1ffec4908d7f9690797f155f658
MD5 9ca4deb3c2d5a103957b3001ebd9f96f
BLAKE2b-256 233af9aaa8e67463ad0cef7e3e957d8e17492366328686b2575a1424af177905

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 33aa7c937ebaf063a860cbb0c263a771b33333a84965c6148eeafe64fb4e29ca
MD5 7d1a4590c0bc41d634b5bd07f3468976
BLAKE2b-256 eee96c1744c7e8bb44a1fb9388fc340bede1aeb3d531462fc975aa14138dacfe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 70d56c784da1239c89d39fefa166fd429306dada641178389be4184a9c04e501
MD5 458b31471fff2b9187a22f51895abe55
BLAKE2b-256 54f98b47199ceae89a867edc45c43dc908384fd2e1ac22406b60d101d988752b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 ae7501cc6a6c37b8d4774bf2218c37be47fe42019a2570e8510fc2044e59d573
MD5 1c45d91905b6dbe9d5a409165ac5f1d6
BLAKE2b-256 e266756ad4b3d0456dcbcc3ab59e297dcdc58a3e8a6fee3f14aa474a97964abf

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.2-cp36-cp36m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 550b4a0788500f6d00f41b7fdd9fcce6d78f99706a7b2f6f81d4d331c7ca468e
MD5 a101b417691638ece08f929b2d635097
BLAKE2b-256 7b581d258b6853a3ba9b6627933f53f307958932701ffb2318f89d0d077a1de1

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.2-cp36-cp36m-macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 c833aa6f4c9ac3e3eb843e3d999bae51339ad33a937303f43ce78064e61cb4b6
MD5 f5081453cc5769bd5b344c4ea4c2f781
BLAKE2b-256 d069d84453c151bf9a06bd7f0f13915cc2d0b4337c7d4124da2f221f68e67575

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.2-cp36-cp36m-macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 fe7b2972ff7e779e812f974aa5695edc328ecf559ceeea887ac46f06f090ad4c
MD5 7171ca6e5ec70bddb7d76962dbfea018
BLAKE2b-256 623908e33c975b4d8149b3806f06344077ec17b78fb0eadafb03563e871e5963

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 620f19ba7628b70b177f5c2e6a55a6fd6e7c8591cde38c3f8f52551733d31b66
MD5 5772cc9e13e1decc96cf187ab40dde26
BLAKE2b-256 dcc20b6b6cfde08b068e9592cbe309401023a841b99a50b0bed1189ffcfe3725

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 ff1447c84a02b9cd5dd3a9332d1fb181a4386c3625765bb5caf1cfbc210ab3f9
MD5 c01baebc8cf00dabd19af08aeb959dd0
BLAKE2b-256 eab24936aa1db329d27efdec02b4a4fb4e743a1ed19f6daa205b0b9badabbed1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 7de2c9e445a5d257935011268202338538abef1aaff341a4733eca56419ca6f6
MD5 4f6fa8f8590ec9c2ecc1a289d734a434
BLAKE2b-256 30e773221dc4f32a5c34fa131d64d18003a8940d4f489607ae7f231e32d9d42c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 f52e7287eb9286a1e91e4c67c207c2573147fbaddc68f70efb5aeee5d1992f2e
MD5 1dc9898a0f6daaf8e29f3c5a937b8589
BLAKE2b-256 da7a4c31e0e2884b1e982cae4bd8b066010e76f5e5653037ccd403e9f04f71ec

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.2-cp35-cp35m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 601e8e83123b4d423a9dfddf7d6943f4f520651a78ffcd50c99d065136c7ff7b
MD5 99a90146b745a7f6e341e5195cd37165
BLAKE2b-256 7401e1653fb30a8d112c0dc4837a93775faca2461b62791494855ee046b7cef3

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.2-cp35-cp35m-macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 1a112a1fdf3802b7f2b182e22e51d71e4a8fa7387d0d38e79a268921b869e384
MD5 18ae22066b7b07bc44e113cc0eb31ce4
BLAKE2b-256 6fc9340265675d4b553b46e94560eb1d0d1df7c9484a246b873ddc0516a74a74

See more details on using hashes here.

File details

Details for the file aiohttp-3.3.2-cp35-cp35m-macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for aiohttp-3.3.2-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 dd81d85a342edf3d2a388e2f24d9facebc9c04550043888f970ee2f228c93059
MD5 5b26010d63745c5a1e1ce1b291239923
BLAKE2b-256 8ed76c4716413cbaacb1ca371ee142f0edac87e7d8df8bba8f63165a32aa81cd

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