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

This version

3.3.0

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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.6m Windows x86-64

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

Uploaded CPython 3.6m Windows x86

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

Uploaded CPython 3.6m

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

Uploaded CPython 3.6m

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

Uploaded CPython 3.5m Windows x86-64

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

Uploaded CPython 3.5m Windows x86

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

Uploaded CPython 3.5m

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

Uploaded CPython 3.5m

File details

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

File metadata

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

File hashes

Hashes for aiohttp-3.3.0.tar.gz
Algorithm Hash digest
SHA256 3128d3ef7b575dbb272cdacd4d4c9a7cf67b18899e96260d55ae3a5782d886e7
MD5 20ecf6ec314b035d6306c6155413cf07
BLAKE2b-256 bfafa6f68012ff76916902fda95ca6ec1150386aa6c998eaefca7d5fbc2e8a92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 e2960362e0c2f9d48bfdc8e0d084a5bb416817be86c94914bc79e45421471f48
MD5 ff2109a22139f810c1e5ed330e5f2728
BLAKE2b-256 247e6f2cbf89cfaa599ba256ffd3352e3959de2404b5223bfbcf2a9780cc6752

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 a05ff430d849095ea4662a833bb790d6ca876ab88305e49fdba445ab1a236b7b
MD5 3d8abb2c35914f608cc895955165effc
BLAKE2b-256 1a53a54689acf9c5cd6c6be9beadcff908cecb692b9a96eb72a2e00eaccf5299

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 899d5253d23e56ea1bff42e6d742f3118d80ceaa993f0cedc9b436feaacd128b
MD5 27476c3b08f6d6b7ea2afa4af454c9d1
BLAKE2b-256 0706a2ee8e3c6c7fb3ad8057e7049a8e59a3c9e47efe64dca0ffa1916eb26709

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 b4e354f8e29d99c60628ddc5d5d959ac2bd8dcb388808e6ccbca3860b7b59269
MD5 e31dadae7e124862e4457826da239c12
BLAKE2b-256 539e7c5b9808adf36ea7d2f0ff3f1dc751838353d2423b5c78d947cb5abdfb6c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 5eba807790f45cfc5df935a425aca30c43f35159b94a34b2d2d360fca9406cbb
MD5 89b5803a1a4a4b6dac9a5f4dca16fd45
BLAKE2b-256 36302a02f97e7171d3dbed560e5b3b704d80c42fe7b1b2b9e5dff7fafdcd1e2e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 85860218fab4e8991f3ed629e0319331e82f7697557bd9eed278fb9f5dba7f29
MD5 20ee14992de85d854d9c13ab95b6ba19
BLAKE2b-256 3f45ede420c6733d43dcf290131ae7d641359bd3fb374e3adb0ace6bf3dcfb17

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2293bc184be9eda99ede8afbfc8fe3a8e65fc82f2d5ab94cb5b7714d766bbb2d
MD5 9ec583873fb26bcda33a704318fe7b21
BLAKE2b-256 4aaeaf1e0b4a1d64dc1eb7ec283b311a57a64ffefc7752e31496691c5bd71348

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiohttp-3.3.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 4417ab2f296fa57b65a946c28326ef7de345d8e94b429037ce1623c5bc96850e
MD5 244ad44f9ee88964ef435fdb5d49e4be
BLAKE2b-256 b74920acca87bad83201e47b8da21392238de52c933dd44e4bdfb98283fc4c2b

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