Skip to main content

http client/server for asyncio

Project description

http client/server for asyncio

aiohttp logo https://secure.travis-ci.org/KeepSafe/aiohttp.png

Requirements

License

aiohttp is offered under the Apache 2 license.

Documentation

http://aiohttp.readthedocs.org/

Getting started

Client

To retrieve something from the web:

import aiohttp

def get_body(url):
    response = yield from aiohttp.request('GET', url)
    return (yield from response.read())

You can use the get command like this anywhere in your asyncio powered program:

response = yield from aiohttp.request('GET', 'http://python.org')
body = yield from response.read()
print(body)

If you want to use timeouts for aiohttp client side please use standard asyncio approach:

yield from asyncio.wait_for(request('GET', url), 10)

Server

In aiohttp 0.12 we’ve added highlevel API for web HTTP server.

There is simple usage 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))
loop.run_forever()

CHANGES

0.13.1 (12-31-2014)

  • Add aiohttp.web.StreamResponse.started property #213

  • Html escape traceback text in ServerHttpProtocol.handle_error

  • Mention handler and middlewares in aiohttp.web.RequestHandler.handle_request on error (#218)

0.13.0 (12-29-2014)

  • StreamResponse.charset converts value to lower-case on assigning.

  • Chain exceptions when raise ClientRequestError.

  • Support custom regexps in route variables #204

  • Fixed graceful shutdown, disable keep-alive on connection closing.

  • Decode http message with utf-8 encoding, some servers send headers in utf-8 encoding #207

  • Support aiohtt.web middlewares #209

  • Add ssl_context to TCPConnector #206

0.12.0 (12-12-2014)

  • Deep refactoring of aiohttp.web in backward-incompatible manner. Sorry, we have to do this.

  • Automatically force aiohttp.web handlers to coroutines in UrlDispatcher.add_route() #186

  • Rename Request.POST() function to Request.post()

  • Added POST attribute

  • Response processing refactoring: constructor does’t accept Request instance anymore.

  • Pass application instance to finish callback

  • Exceptions refactoring

  • Do not unquote query string in aiohttp.web.Request

  • Fix concurrent access to payload in RequestHandle.handle_request()

  • Add access logging to aiohttp.web

  • Gunicorn worker for aiohttp.web

  • Removed deprecated AsyncGunicornWorker

  • Removed deprecated HttpClient

0.11.0 (11-29-2014)

  • Support named routes in aiohttp.web.UrlDispatcher #179

  • Make websocket subprotocols conform to spec #181

0.10.2 (11-19-2014)

  • Don’t unquote environ[‘PATH_INFO’] in wsgi.py #177

0.10.1 (11-17-2014)

  • aiohttp.web.HTTPException and descendants now files response body with string like 404: NotFound

  • Fix multidict __iter__, the method should iterate over keys, not (key, value) pairs.

0.10.0 (11-13-2014)

  • Add aiohttp.web subpackage for highlevel http server support.

  • Add reason optional parameter to aiohttp.protocol.Response ctor.

  • Fix aiohttp.client bug for sending file without content-type.

  • Change error text for connection closed between server responses from ‘Can not read status line’ to explicit ‘Connection closed by server’

  • Drop closed connections from connector #173

  • Set server.transport to None on .closing() #172

Project details


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

Uploaded Source

Built Distribution

aiohttp-0.13.1-py3-none-any.whl (68.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for aiohttp-0.13.1.tar.gz
Algorithm Hash digest
SHA256 abb7103baf532cd5032e2e3b3c296e81afccd4471a92bad1a1395c23aeac070f
MD5 bb74a193af9a56a83fe6716bc884f4e9
BLAKE2b-256 1639ecfbc51971069674072c583bcd8489264be48a6bef6ca962c6832062d090

See more details on using hashes here.

File details

Details for the file aiohttp-0.13.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp-0.13.1-py3-none-any.whl
Algorithm Hash digest
SHA256 de348d41fc76cd12f0d5fb410dfe57ba5c3b4528c8c3c61e7d704780ebf57a74
MD5 8e7c5654e9ad4328519956ecdbc062c0
BLAKE2b-256 d393d528c8d3ea981952825d7a0b0a037df23ddae9ae5e01156ce5a852100593

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