Hishel is an elegant HTTP caching library for Python, implementing RFC 9111 specifications to provide seamless caching integration for popular HTTP clients like HTTPX and Requests. It offers flexible storage backends, including SQLite, and supports both synchronous and asynchronous workflows with a focus on high performance and type safety. The library is actively maintained with frequent minor releases, ensuring ongoing compatibility and feature enhancements.
pip install hishelVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates using Hishel's `SyncCacheClient` with HTTPX for both in-memory (default) and file-based (SQLite) caching. The first request fetches data from the origin, while subsequent requests for the same URL will be served from the cache, if applicable according to HTTP caching rules.
Upgrade to Python 3.10 or newer, or pin Hishel to `<1.1.9`.
For reliable caching, use `hishel.CacheClient`, `hishel.AsyncCacheClient`, or `hishel.CacheTransport` directly with your HTTP client.
Always iterate over the response stream (e.g., `for chunk in response.iter_bytes(): pass`) to ensure its content is saved to the cache.
Refer to the `httpx` documentation for available client arguments, as they are compatible with Hishel's cache clients.
Upgrade to Hishel 1.1.8 or newer to benefit from race condition fixes.
Always use `None` as a default for mutable arguments and initialize them inside the function if `None` is passed (e.g., `if filters is None: filters = []`).