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.
Installation
Using pip:
pip install httpx-cache
Using poetry:
poetry add httpx-cache
Features
- In memory dict cache store
- Support for cache-controle headers
- Sync cache transport for httpx
- Async cache transport for httpx
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.
TODO
- support etags
- support cache expiry dates
- support file cach
- support redis (sync/async) cache
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.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b9e428ee0e25b492ab9115977daeed136f07ac763480761dc0e2758b6af54bb |
|
MD5 | 1c9428db6c5e72a049a7aa412406c77c |
|
BLAKE2b-256 | 71d7272fdeeadedf072c7791904884396d54e15a1b366756935ec7a8a30152c6 |