Skip to content

Latest commit

 

History

History
153 lines (106 loc) · 3.28 KB

index.rst

File metadata and controls

153 lines (106 loc) · 3.28 KB

aiohttp

HTTP client/server for :term:`asyncio` (PEP 3156).

Features

Library Installation

$ pip install aiohttp

You may want to install optional :term:`cchardet` library as faster replacement for :term:`chardet`:

$ pip install cchardet

Getting Started

Client example:

import asyncio
import aiohttp

@asyncio.coroutine
def fetch_page(client, url):
    response = yield from client.get(url)
    assert response.status == 200
    return (yield from response.read())

loop = asyncio.get_event_loop()
client = aiohttp.ClientSession(loop=loop)
content = loop.run_until_complete(
    fetch_page(client, 'http://python.org'))
print(content)
client.close()

Server example:

import asyncio
from aiohttp import web

@asyncio.coroutine
def handle(request):
    name = request.match_info.get('name', "Anonymous")
    text = "Hello, " + name
    return web.Response(body=text.encode('utf-8'))

@asyncio.coroutine
def init(loop):
    app = web.Application(loop=loop)
    app.router.add_route('GET', '/{name}', handle)

    srv = yield from loop.create_server(app.make_handler(),
                                        '127.0.0.1', 8080)
    print("Server started at http://127.0.0.1:8080")
    return srv

loop = asyncio.get_event_loop()
loop.run_until_complete(init(loop))
try:
    loop.run_forever()
except KeyboardInterrupt:
    pass

Source code

The project is hosted on GitHub

Please feel free to file an issue on the bug tracker if you have found a bug or have some suggestion in order to improve the library.

The library uses Travis for Continuous Integration.

Dependencies

  • Python Python 3.4.1+

  • chardet library

  • Optional :term:`cchardet` library as faster replacement for :term:`chardet`.

    Install it explicitly via:

    $ pip install cchardet
    

Contributing

Please read the :ref:`instructions for contributors<aiohttp-contributing>` before making a Pull Request.

Authors and License

The aiohttp package is written mostly by Nikolay Kim and Andrew Svetlov.

It's Apache 2 licensed and freely available.

Feel free to improve this package and send a pull request to GitHub.

Contents:

.. toctree::

   client
   client_reference
   client_websockets
   web
   web_reference
   server
   multidict
   multipart
   api
   gunicorn
   contributing
   changes
   glossary

Indices and tables

.. disqus::