Skip to content

Hishel Logo Hishel Logo

Hishel

Elegant HTTP Caching for Python

PyPI version Python versions License Coverage Downloads


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