Skip to main content

HTTP Client Mixin for Tornado RequestHandlers

Project description

HTTP Client Mixin for Tornado RequestHandlers. Automatically retries on errors, sleep when rate limited, and handles content encoding and decoding using MsgPack and JSON.

Version Travis CodeCov Docs

Installation

sprockets.mixins.http is available on the Python Package Index and can be installed via pip or easy_install:

pip install sprockets.mixins.http

If you would like to use tornado.curl_httpclient.CurlAsyncHTTPClient, you can install pycurl with:

pip install sprockets.mixins.http[curl]

Documentation

https://pythonhosted.org/sprockets.mixins.http/

Requirements

Example

This examples demonstrates the most basic usage of sprockets.mixins.http

from tornado import ioloop, web
from sprockets.mixins import http


class RequestHandler(http.HTTPClientMixin, web.RequestHandler):

   async def get(self, *args, **kwargs):
       response = await self.http_fetch('https://api.github.com')
       if not response.ok:
           self.set_status(response.code)
       self.write(response.body)


if __name__ == "__main__":
   app = web.Application([(r'/', RequestHandler)])
   app.listen(8000)
   ioloop.IOLoop.current().start()

As with Tornado, to use the curl client which has numerous benefits:

from tornado import httpclient, ioloop, web
from sprockets.mixins import http

httpclient.AsyncHTTPClient.configure(
    'tornado.curl_httpclient.CurlAsyncHTTPClient')


class RequestHandler(http.HTTPClientMixin, web.RequestHandler):

   async def get(self, *args, **kwargs):
       response = await self.http_fetch('https://api.github.com')
       if not response.ok:
           self.set_status(response.code)
       self.write(response.body)


if __name__ == "__main__":
   app = web.Application([(r'/', RequestHandler)])
   app.listen(8000)
   ioloop.IOLoop.current().start()

Environment Variables

HTTP_MAX_CLIENTS

An optional setting that specifies the maximum number of simultaneous asynchronous HTTP requests. If not specified, the default Tornado value of 10 will be used.

License

sprockets.mixins.http is released under the 3-Clause BSD license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sprockets.mixins.http-2.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sprockets.mixins.http-2.1.0-py2.py3-none-any.whl (9.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file sprockets.mixins.http-2.1.0.tar.gz.

File metadata

  • Download URL: sprockets.mixins.http-2.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for sprockets.mixins.http-2.1.0.tar.gz
Algorithm Hash digest
SHA256 38fab3de6b0155a56b783f8460bcab8b363f81a08677b809eb305658ee2c246a
MD5 f3f20715e8e7d074e067834d3e8c1711
BLAKE2b-256 093a240995c6627ac287574998e63bd1683b9ec2d7e02d2fc8a7a4db360416bf

See more details on using hashes here.

File details

Details for the file sprockets.mixins.http-2.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: sprockets.mixins.http-2.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for sprockets.mixins.http-2.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 efca805239f1d2d4b12efa5c7227ddbf46c316883aad36c5114fa2eabda39c6a
MD5 a521f9d3186e88060c76095eff928212
BLAKE2b-256 8980f230124bd70ab405e05cfe29e3e18a5e7814978f1ecde7a027eb64e77ea9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page