Simple caching transport for httpx.
Project description
HTTPX-CACHE
Note: Early development / alpha, use at your own risk.
httpx-cache is yet another implementation/port is a port of the caching algorithms in httplib2 for use with httpx Transport object.
It is is heavily insipired by:
This project supports the latest version of httpx (at of the time of writing): httpx@0.21.1
, when httpx
releases a v1 version, the update should be straithforward for this project.
Documentation
Full documentation is available at https://obendidi.github.io/httpx-cache/
Installation
Using pip:
pip install httpx-cache
Quickstart
The lib provides an httpx
compliant transport that you can use instead of the the defult one when creating your httpx
client:
import httpx
from httpx_cache import CacheControlTransport
with httpx.Client(transport=CacheControlTransport()) as client:
response = client.get("https://httpbin.org/get")
# the response is effectively cached, calling teh same request with return a response from the cache
response2 = client.get("https://httpbin.org/get")
You can also wrap an existing transport with CacheControlTransport
. The CacheControlTransport
will use the existing transport for making the request call and then cach the result if it satisfies the cache-control headers.
import httpx
from httpx_cache import CacheControlTransport
my_transport = httpx.HTTPTransport(http2=True, verify=False)
with httpx.Client(transport=CacheControlTransport(transport=my_transport)) as client:
response = client.get("https://httpbin.org/get")
# the response is effectively cached, calling teh same request with return a response from the cache
response2 = client.get("https://httpbin.org/get")
Examples
more examples in ./examples.
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 httpx_cache-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6465c57f17349069d15b1887f24e38b39e914d57dab9c0ce28e79b92920cd01 |
|
MD5 | ce13ca28f4982bf92edfcbf26d6478bb |
|
BLAKE2b-256 | 0725fa2d9d67bffaaf7f617fb09c2cf121777029dd8f3e9c9361edd52cc6145f |