Httpx

Hishel provides an integration with httpx, making it easy to enable flexible caching in only a few seconds.

To get started, you can use SyncHishelClient(or AsyncHishelClient for async) as a drop-in replacement for an httpx client, like so:

from hishel.beta.integrations.clients.httpx import SyncHishelClient

client = SyncHishelClient()
client.get("https://hishel.com")
client.get("https://hishel.com")  # from cache

You can configure the client's storage and cache options like so:

from hishel.beta import CacheOptions, SyncLmdbStorage
from hishel.beta.integrations.clients.httpx import SyncHishelClient

client = SyncHishelClient(
    storage=SyncLmdbStorage(default_ttl=60 * 60 * 24), # 1 day
    cache_options=CacheOptions(supported_methods=["GET", "HEAD"]
)

As lower-level building blocks, Hishel also provides caching httpx transports that you can use to build your own clients or combine with existing transports.

import httpx

from hishel.beta import CacheOptions, SyncLmdbStorage
from hishel.beta.integrations.clients.httpx import SyncCacheTransport

client = httpx.Client(
    transport=SyncCacheTransport(
        transport=httpx.HTTPTransport(),
        storage=SyncLmdbStorage(default_ttl=60 * 60 * 24),  # 1 day
        cache_options=CacheOptions(supported_methods=["GET", "HEAD"]),
    )
)