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.
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
Requirements
tornado >=4.2.0,<5
Example
This examples demonstrates the most basic usage of sprockets.mixins.http
from tornado import gen, ioloop, web
from sprockets.mixins import http
class RequestHandler(http.HTTPClientMixin, web.RequestHandler):
@gen.coroutine
def get(self, *args, **kwargs):
response = yield self.http_fetch('https://api.github.com')
if not response.ok:
self.set_status(response.code)
self.write(response.body)
self.finish()
if __name__ == "__main__":
app = web.Application([web.url(r'/', RequestHandler)])
app.listen(8000)
ioloop.IOLoop.current().start()
As with Tornado, to use the curl client which has numerous benefits:
from tornado import gen, httpclient, ioloop, web
from sprockets.mixins import http
httpclient.AsyncHTTPClient.configure(
'tornado.curl_httpclient.CurlAsyncHTTPClient')
class RequestHandler(http.HTTPClientMixin, web.RequestHandler):
@gen.coroutine
def get(self, *args, **kwargs):
response = yield self.http_fetch('https://api.github.com')
if not response.ok:
self.set_status(response.code)
self.write(response.body)
self.finish()
if __name__ == "__main__":
app = web.Application([web.url(r'/', RequestHandler)])
app.listen(8000)
ioloop.IOLoop.current().start()
License
sprockets.mixins.http is released under the 3-Clause BSD license.
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
Built Distribution
Hashes for sprockets.mixins.http-1.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 466818b49e04e14ad24736a33794625c17c58d03d7a72ed50cc68c872a7254bd |
|
MD5 | 509ec5c6810b543637761f83d5263515 |
|
BLAKE2b-256 | afa8f746ce8d2501d8ded88f176831728dacf5bb75cacd2ab22f0f46d014253b |
Hashes for sprockets.mixins.http-1.0.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6206ad884a57ee44ff4fe4f8fcee6afd68e64c1d81d3eeeb3407611d9b15280 |
|
MD5 | bd2bc6b85ddb304987c2dab2f52f864a |
|
BLAKE2b-256 | 28a66cc7c921892e3039422bfc721df7e6cc565f7aa1c17805abe33176e8a04a |