Git Product home page Git Product logo

aiohttp's Introduction

http client/server for asyncio

image

Requirements

License

aiohttp is offered under the BSD license.

Documentation

http://aiohttp.readthedocs.org/

Getting started

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)

The signature of request is the following:

request(method, url, *,
        params=None,
        data=None,
        headers=None,
        cookies=None,
        auth=None,
        allow_redirects=True,
        max_redirects=10,
        encoding='utf-8',
        version=aiohttp.HttpVersion11,
        compress=None,
        chunked=None,
        expect100=False,
        connector=None,
        read_until_eof=True,
        request_class=None,
        response_class=None,
        loop=None
)

It constructs and sends a request. It returns response object. Parameters are explained as follow:

  • method: HTTP method
  • url: Request url
  • params: (optional) Dictionary or bytes to be sent in the query string of the new request
  • data: (optional) Dictionary, bytes, StreamReader or file-like object to send in the body of the request
  • headers: (optional) Dictionary of HTTP Headers to send with the request
  • cookies: (optional) Dict object to send with the request
  • auth: (optional) BasicAuth tuple to enable Basic HTTP Basic Auth
  • allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.
  • version: Request http version.
  • compress: Boolean. Set to True if request has to be compressed with deflate encoding.
  • chunked: Boolean or Integer. Set to chunk size for chunked transfer encoding.
  • expect100: Boolean. Expect 100-continue response from server.
  • connector: aiohttp.connector.BaseConnector instance to support connection pooling and session cookies.
  • read_until_eof: Read response until eof if response does not have Content-Length header.
  • request_class: Custom Request class implementation.
  • response_class: Custom Response class implementation.
  • loop: Optional event loop.

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

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

Gunicorn worker

Since version 0.19.0 gunicorn has native support for aiohttp.

Paster configuration example:

[server:main]
use = egg:gunicorn#main
host = 0.0.0.0
port = 8080
worker_class = aiohttp.worker.AsyncGunicornWorker

aiohttp's People

Contributors

amirouche avatar asvetlov avatar evgenus avatar fafhrd91 avatar fiveside avatar gholt avatar kxepal avatar l04m33 avatar landersson avatar lukmdo avatar madjar avatar mikluko avatar mind1m avatar nbraem avatar oohlaf avatar polymorphm avatar popravich avatar robberphex avatar sffjunkie avatar spumer avatar tailhook avatar the-dud avatar vaibhavsagar avatar vharitonsky avatar xinkai avatar zed avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.