sprockets.mixins.http
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.
Metadata
Release files for sprockets.mixins.http 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sprockets.mixins.http-1.0.4.tar.gz | 6.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sprockets.mixins.http-1.0.4-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 15.9 kB
Release files / sprockets.mixins.http-1.0.4.tar.gz
| Download URL | sprockets.mixins.http-1.0.4.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
466818b49e04e14ad24736a33794625c17c58d03d7a72ed50cc68c872a7254bd
|
|
BLAKE2b-256 checksum How to use checksums |
afa8f746ce8d2501d8ded88f176831728dacf5bb75cacd2ab22f0f46d014253b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / sprockets.mixins.http-1.0.4-py2.py3-none-any.whl
| Download URL | sprockets.mixins.http-1.0.4-py2.py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
f6206ad884a57ee44ff4fe4f8fcee6afd68e64c1d81d3eeeb3407611d9b15280
|
|
BLAKE2b-256 checksum How to use checksums |
28a66cc7c921892e3039422bfc721df7e6cc565f7aa1c17805abe33176e8a04a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |