Python Other
Permalink
Failed to load latest commit information.
aiohttp Allow to disable redirect url re-quoting #1474 Mar 28, 2017
demos update docs Mar 11, 2017
docs Allow to disable redirect url re-quoting #1474 Mar 28, 2017
examples do not use deprecated loop parameter Mar 20, 2017
tests do not add content-disposition header to stremimng request by default #… Mar 27, 2017
vendor/http-parser initial implementation Feb 15, 2017
.coveragerc Improve test coverage Jan 14, 2015
.gitignore rename _parser Feb 18, 2017
.travis.yml back to dev Mar 20, 2017
CHANGES.rst Allow to disable redirect url re-quoting #1474 Mar 28, 2017
CONTRIBUTING.rst update docs Mar 11, 2017
CONTRIBUTORS.txt merge fixes from 2.0 Mar 24, 2017
HISTORY.rst prepare release Mar 20, 2017
ISSUE_TEMPLATE.md some corrections and clarifications in the issue/pr templates. (#911) Jun 4, 2016
LICENSE.txt version and dates Mar 13, 2017
MANIFEST.in fix MANIFEST.in: CHANGES.{txt,rst} Aug 12, 2016
Makefile test coverage Mar 21, 2017
PULL_REQUEST_TEMPLATE.md Update PULL_REQUEST_TEMPLATE.md Mar 20, 2017
README.rst prepare release Mar 20, 2017
appveyor.yml change appveyor Mar 20, 2017
build-wheels.sh build py3.6 wheels Feb 9, 2017
build.cmd Try to fix 64 build on Windows Jan 8, 2016
codecov.yml Shrink codecov range Aug 27, 2016
requirements-ci.txt Update gunicorn from 19.7.0 to 19.7.1 Mar 21, 2017
requirements-dev.txt Update ipython from 5.2.2 to 5.3.0 Mar 14, 2017
requirements-wheel.txt Update pytest from 3.0.6 to 3.0.7 Mar 14, 2017
run_docker.sh Update wheel building instructions Jul 14, 2016
setup.cfg check for runtime warnings in tests Mar 23, 2017
setup.py update readme Mar 15, 2017
tox.ini Add pyflakes version requirements Oct 6, 2015

README.rst

Async http client/server framework

aiohttp logo

https://travis-ci.org/aio-libs/aiohttp.svg?branch=master

aiohttp 2.0 release!

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

Another major change, we moved aiohttp development to public organization https://github.com/aio-libs

With this amount of api changes 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

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