Skip to content

HTTPX-CACHE

httpx-cache is an implementation of the caching algorithms in httplib2 and CacheControl for use with httpx transport object.

It is is heavily insipired by:

Installation

Install with pip:

$ pip install httpx-cache

To use RedisCache, install with redis extra:

$ pip install httpx-cache[redis]

Requires Python 3.6+ and HTTPX 0.21+.

Quickstart

Usage with Client

import httpx_cache

with httpx_cache.Client() as client:
  response = client.get("https://httpbin.org/get")

Usage with AsyncClient

import httpx_cache

async with httpx_cache.AsyncClient() as client:
  response = await client.get("https://httpbin.org/get")

When using httpx-cache.Client/httpx_cache.AsyncClient, the interface and features (except caching) are exactly the same as httpx.Client/httpx.AsyncClient

Read the User Guide for a complete walk-through.

Supported Cache Types and Serializers

Serializer DictCache FileCache RedisCache
DictSerializer ✅ ❌ ❌
StringJsonSerializer ✅ ❌ ❌
BytesJsonSerializer ✅ ✅ ✅
MsgPackSerializer ✅ ✅ ✅