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

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded CPython 3.6m

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

Uploaded CPython 3.6m

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

Uploaded CPython 3.6mmacOS 10.12+ x86-64

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

Uploaded CPython 3.6mmacOS 10.11+ x86-64

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

Uploaded CPython 3.6mmacOS 10.10+ x86-64

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

Uploaded CPython 3.5m

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

Uploaded CPython 3.5m

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

Uploaded CPython 3.5mmacOS 10.12+ x86-64

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

Uploaded CPython 3.5mmacOS 10.11+ x86-64

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

Uploaded CPython 3.5mmacOS 10.10+ x86-64

File details

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

File metadata

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

File hashes

Hashes for aiohttp-3.3.2a0.tar.gz
Algorithm Hash digest
SHA256 d14043ba802ec3614f401348eae6cce31f790c68cbf21f8b8d15eb8ac9c2a63a
MD5 70e331ccfa4e208eb37c7f9f17592a4f
BLAKE2b-256 314cddc159ef34701882d0dad1b2c48df8b83d728fc73f378b5a7de8681b6662

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2a0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 34375efd708d1cc5b68f850d09fc40659af019d22735abd66d64b2bd5df783e6
MD5 642c67e2c0be8fa204f62abbfe97e8d2
BLAKE2b-256 65a5586f669c61701d0166b5f19ae5a1c1130ac3c5d3ed374fe37c8e3b0053b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2a0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 c2eef6d44ee86dc2e271bb8fc97edc0575ae674c5dc3526f8a2bb41912cc635c
MD5 3b3d1eaed97ae5c99035e9c7d63f37ad
BLAKE2b-256 be32edb60877e240b403b6a58f24ab8fd91f00ab73fdf4ae94274c9eded7b8e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2a0-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2cdef3082095c80e3d4c561faa2eb3395c33c2f2f774182d005b3fd658707c51
MD5 f028bbc07a3ffe7661e0af2b0f025225
BLAKE2b-256 256e059735274a8155768aade7489395f7c6eea170822da37291817e94fc1a3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2a0-cp36-cp36m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 84b2f673c3ea2d3edaf955b10ae48f8a93a1dd83c2d6a85f469a8e28392d19ae
MD5 6c70338291ba5182e0810e539576b20a
BLAKE2b-256 70ace04b3e86eee99570814a3c58bc139b77e8d7194b389e109a4a2c27fcb003

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2a0-cp36-cp36m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 a5590567adf30f5262090adedd1d6608e101386bf068d24836714f7d3ae53fef
MD5 7159dac235abf67663b6ffae052661a6
BLAKE2b-256 a99efbe40a3fb68b49035ec184837ba3f702ab1e2a450c4730a25da4f7286fcc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2a0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c0a3242526317404aefb5628c70c02b6af805ee3474b15b51cfead95d41ba600
MD5 1cc91de59f9550f24318c1b17bde2891
BLAKE2b-256 9e5acfd0f168cc8979955db27b445ba287c7c2d8509ec199bb3f43f94c941e19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2a0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 dde06e518cfdceecc9528738a2179830a714e814091c79ac870b416152810616
MD5 a59adcc46e624b7c63721bcf89dea27d
BLAKE2b-256 40cfa3bbffd15e2337843b9782bbad2d98ea5db1c336f64ccc7887684da9070c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2a0-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 04a4e4170d202f32c2a1e4893061437e67220f7ae3c560d9ffb92632912bf698
MD5 6b9a3b3ed562f3fecbd2447905224bc2
BLAKE2b-256 b40530d5c962b062f24a12bd827ec6445b02db964a95abfcf50b1dd234762f26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2a0-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 0f5329e879eb31d27a3110b042065906d69e9f2c238e9e11b942a1a625d4e62b
MD5 2782f2ed9903cb313e4ac0db7d79bfd1
BLAKE2b-256 690f57468d875a883d481a05ea2b74445ada88c0a7d13a463feab6585cb597ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.2a0-cp35-cp35m-macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 5d463f568e0cda4e4ec740c562cdbe59b139c4dccf76bab31f0cc1ab99f1e9bb
MD5 ebd1480844d93918d6e11b064eacbf7c
BLAKE2b-256 da259c09c518f49d52adc69165c10d863e23f02a7178af22d0f8c2a3e1066948

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page