Elegant HTTP Caching for Python
Project description
Hishel
Elegant HTTP Caching for Python
Hishel (հիշել, to remember in Armenian) is a modern HTTP caching library for Python that implements RFC 9111 specifications. It provides seamless caching integration for popular HTTP clients with minimal code changes.
✨ Features
- 🎯 RFC 9111 Compliant - Fully compliant with the latest HTTP caching specification
- 🔌 Easy Integration - Drop-in support for HTTPX and Requests
- 💾 Flexible Storage - SQLite backend with more coming soon
- ⚡ High Performance - Efficient caching with minimal overhead
- 🔄 Async & Sync - Full support for both synchronous and asynchronous workflows
- 🎨 Type Safe - Fully typed with comprehensive type hints
- 🧪 Well Tested - Extensive test coverage and battle-tested
- 🎛️ Configurable - Fine-grained control over caching behavior
- 🌐 Future Ready - Designed for easy integration with any HTTP client/server
📦 Installation
pip install hishel
Optional Dependencies
Install with specific HTTP client support:
pip install hishel[httpx] # For HTTPX support
pip install hishel[requests] # For Requests support
Or install both:
pip install hishel[httpx,requests]
🚀 Quick Start
With HTTPX
Synchronous:
from hishel.httpx import SyncCacheClient
client = SyncCacheClient()
# First request - fetches from origin
response = client.get("https://api.example.com/data")
print(response.extensions["hishel_from_cache"]) # False
# Second request - served from cache
response = client.get("https://api.example.com/data")
print(response.extensions["hishel_from_cache"]) # True
Asynchronous:
from hishel.httpx import AsyncCacheClient
async with AsyncCacheClient() as client:
# First request - fetches from origin
response = await client.get("https://api.example.com/data")
print(response.extensions["hishel_from_cache"]) # False
# Second request - served from cache
response = await client.get("https://api.example.com/data")
print(response.extensions["hishel_from_cache"]) # True
With Requests
import requests
from hishel.requests import CacheAdapter
session = requests.Session()
session.mount("https://", CacheAdapter())
session.mount("http://", CacheAdapter())
# First request - fetches from origin
response = session.get("https://api.example.com/data")
# Second request - served from cache
response = session.get("https://api.example.com/data")
print(response.headers.get("X-Hishel-From-Cache")) # "True"
🎛️ Advanced Configuration
Custom Cache Options
from hishel import CacheOptions
from hishel.httpx import SyncCacheClient
client = SyncCacheClient(
cache_options=CacheOptions(
shared=False, # Use as private cache (browser-like)
supported_methods=["GET", "HEAD", "POST"], # Cache GET, HEAD, and POST
allow_stale=True # Allow serving stale responses
)
)
Custom Storage Backend
from hishel import SyncSqliteStorage
from hishel.httpx import SyncCacheClient
storage = SyncSqliteStorage(
database_path="my_cache.db",
default_ttl=7200.0, # Cache entries expire after 2 hours
refresh_ttl_on_access=True # Reset TTL when accessing cached entries
)
client = SyncCacheClient(storage=storage)
🏗️ Architecture
Hishel uses a sans-I/O state machine architecture that separates HTTP caching logic from I/O operations:
- ✅ Correct - Fully RFC 9111 compliant
- ✅ Testable - Easy to test without network dependencies
- ✅ Flexible - Works with any HTTP client or server
- ✅ Type Safe - Clear state transitions with full type hints
🔮 Roadmap
While Hishel currently supports HTTPX and Requests, we're actively working on:
- 🎯 Additional HTTP client integrations
- 🎯 Server-side caching support
- 🎯 More storage backends
- 🎯 Advanced caching strategies
- 🎯 Performance optimizations
📚 Documentation
Comprehensive documentation is available at https://hishel.com/dev
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
See our Contributing Guide for more details.
📄 License
This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.
💖 Support
If you find Hishel useful, please consider:
- ⭐ Starring the repository
- 🐛 Reporting bugs and issues
- 💡 Suggesting new features
- 📖 Improving documentation
- ☕ Buying me a coffee
🙏 Acknowledgments
Hishel is inspired by and builds upon the excellent work in the Python HTTP ecosystem, particularly:
- HTTPX - A next-generation HTTP client for Python
- Requests - The classic HTTP library for Python
- RFC 9111 - HTTP Caching specification
Made with ❤️ by Kar Petrosyan
[1.0.0dev0] - 2025-10-19
⚙️ Miscellaneous Tasks
- (docs) Use mike powered versioning
- (docs) Improve docs versioning, deploy dev doc on ci
[0.1.5] - 2025-10-18
🚀 Features
- (perf) Set chunk size to 128KB for httpx to reduce SQLite read/writes
- Better cache-control parsing
- Add close method to storages API (#384)
- (perf) Increase requests buffer size to 128KB, disable charset detection
🐛 Bug Fixes
- (docs) Fix some line breaks
⚙️ Miscellaneous Tasks
- Remove some redundant files from repo
[0.1.4] - 2025-10-14
🚀 Features
- Add support for a sans-IO API (#366)
- Allow already consumed streams with
CacheTransport(#377) - Add sqlite storage for beta storages
- Get rid of some locks from sqlite storage
- Better async implemetation for sqlite storage
🐛 Bug Fixes
- Create an sqlite file in a cache folder
- Fix beta imports
⚙️ Miscellaneous Tasks
- Improve CI (#369)
- (internal) Remove src folder (#373)
- (internal) Temporary remove python3.14 from CI
- (tests) Add sqlite tests for new storage
- (tests) Move some tests to beta
[0.1.3] - 2025-07-06
🚀 Features
- Support providing a path prefix to S3 storage (#342)
📚 Documentation
- Update link to httpx transports page (#337)
[0.1.2] - 2025-04-04
🐛 Bug Fixes
- Requirements.txt to reduce vulnerabilities (#263)
[0.0.30] - 2024-07-12
🐛 Bug Fixes
- Requirements.txt to reduce vulnerabilities (#245)
- Requirements.txt to reduce vulnerabilities (#255)
[0.0.27] - 2024-05-31
🐛 Bug Fixes
- (redis) Do not update metadata with negative ttl (#231)
[0.0.1] - 2023-07-22
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hishel-1.0.0.dev0.tar.gz.
File metadata
- Download URL: hishel-1.0.0.dev0.tar.gz
- Upload date:
- Size: 51.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd8837259fc47117e52f5bf7dcc167b8ced9707335506951df946b78ca301d0a
|
|
| MD5 |
d07304442ddf10e9f2fd60baf92ebf4f
|
|
| BLAKE2b-256 |
f6c740e613c5d1f1b36a5d4cf9cc809e964a113f7411c14108eecf20f6a2a126
|
Provenance
The following attestation bundles were made for hishel-1.0.0.dev0.tar.gz:
Publisher:
publish.yml on karpetrosyan/hishel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hishel-1.0.0.dev0.tar.gz -
Subject digest:
fd8837259fc47117e52f5bf7dcc167b8ced9707335506951df946b78ca301d0a - Sigstore transparency entry: 622116835
- Sigstore integration time:
-
Permalink:
karpetrosyan/hishel@83295fd5c36e7fab9ee701c77fa1180a86f35a31 -
Branch / Tag:
refs/tags/1.0.0.dev0 - Owner: https://github.com/karpetrosyan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@83295fd5c36e7fab9ee701c77fa1180a86f35a31 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hishel-1.0.0.dev0-py3-none-any.whl.
File metadata
- Download URL: hishel-1.0.0.dev0-py3-none-any.whl
- Upload date:
- Size: 58.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
542ef23722a178c108f92f2856ca466e1f4cda287bb5fb87401d5f10cc8cce4b
|
|
| MD5 |
5e09d1b35cee96a44b4543c0500df78d
|
|
| BLAKE2b-256 |
553018f2da480573f9bf1b48aab02509d058252df6c5577e110aa2020681af82
|
Provenance
The following attestation bundles were made for hishel-1.0.0.dev0-py3-none-any.whl:
Publisher:
publish.yml on karpetrosyan/hishel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hishel-1.0.0.dev0-py3-none-any.whl -
Subject digest:
542ef23722a178c108f92f2856ca466e1f4cda287bb5fb87401d5f10cc8cce4b - Sigstore transparency entry: 622116838
- Sigstore integration time:
-
Permalink:
karpetrosyan/hishel@83295fd5c36e7fab9ee701c77fa1180a86f35a31 -
Branch / Tag:
refs/tags/1.0.0.dev0 - Owner: https://github.com/karpetrosyan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@83295fd5c36e7fab9ee701c77fa1180a86f35a31 -
Trigger Event:
push
-
Statement type: