Skip to main content

Persistant cache implementation for httpx and httpcore

Project description

HTTPX

Hishel - An elegant HTTP Cache implementation for httpx and httpcore.

PyPI - Version PyPI - Python Version PyPI - License Codecov


Hishel (հիշել, remember) is a library that implements HTTP Caching for HTTPX and HTTP Core libraries in accordance with RFC 9111, the most recent caching specification.

Features

  • 💾 Persistence: Responses are cached in the persistent memory for later use.
  • 🤲 Compatibility: It is completely compatible with your existing transports or connection pools, whether they are default, custom, or provided by third-party libraries.
  • 🤗 Easy to use: You continue to use the httpx and httpcore interfaces. Can be integrated with no changes to the code.
  • 🧠 Smart: Attempts to clearly implement RFC 9111, understands Vary, Etag, Last-Modified, Cache-Control, and Expires headers, and handles response re-validation automatically.
  • ⚙️ Configurable: You can specify the backend where the responses should be stored, the serializer, and you can write your own backends and serializers. You can also specify which parts of RFC 9111 should be ignored and which should not, for example, you can explicitly disable stale responses for your safety or enable re-validation for each response before using it.
  • 🚀 Very fast: When IO is not required, your requests are even faster.

QuickStart

Install Hishel using pip:

$ pip install hishel

Let's begin with an example of a httpx client.

import hishel

with hishel.CacheClient() as client:
    client.get("https://www.github.com")
    client.get("https://www.github.com")  # takes from the cache (very fast!)

or in asynchronous context

import hishel

async with hishel.AsyncCacheClient() as client:
    await client.get("https://www.github.com")
    await client.get("https://www.github.com")  # takes from the cache

HTTPX and HTTP Core

Hishel also supports the transports of HTTPX and the connection pools of HTTP Core.

Hishel respects existing transports and connection pools and can therefore work on top of them, making hishel a very compatible and flexible library.

Transports example:

import httpx
import hishel

transport = httpx.HTTPTransport()
cache_transport = hishel.CacheTransport(transport=transport)

req = httpx.Request("GET", "https://www.github.com")

cache_transport.handle_request(req)
cache_transport.handle_request(req)  # takes from the cache

Connection Pool example:

import httpcore
import hishel

pool = hishel.CacheConnectionPool(pool=httpcore.ConnectionPool())

pool.request("GET", "https://www.github.com")
pool.request("GET", "https://www.github.com")  # takes from the cache

How and where are the responses saved?

The responses are stored by Hishel in storages. Hishel has a variety of built-in storage options, but the default storage is a filesystem storage. You can switch the storage to another one that Hishel offers or, if necessary, write your own; for more information, see the storage documentation.

Contributing

Hishel is a powerful tool, but it is also a new project with potential flaws, so we welcome contributions!

You can open the pull request by following these instructions if you want to improve Hishel. 💓

  • Fork the project.
  • Make change.
  • Open the pull request.

Changelog

0.0.3 (7/28/2023)

  • Add from_cache response extension.
  • Add typing_extensions into the requirements.

0.0.2 (7/25/2023)

  • Add redis support.
  • Make backends thread and task safe.
  • Add black as a new linter.
  • Add an expire time for cached responses.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hishel-0.0.3.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

hishel-0.0.3-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file hishel-0.0.3.tar.gz.

File metadata

  • Download URL: hishel-0.0.3.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.1

File hashes

Hashes for hishel-0.0.3.tar.gz
Algorithm Hash digest
SHA256 f99c28ccd4e148e0e111ff72b908af0ee2566d12d678788a21b15ca8bade670e
MD5 6b346194b97d3f75d179bb459edc58be
BLAKE2b-256 bc8af4dbee412973627ba9549eb077d4142b2696294b4f2388724378d12ce7ef

See more details on using hashes here.

File details

Details for the file hishel-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: hishel-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.1

File hashes

Hashes for hishel-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d0f36774d9ccfe0ddfcb810d559981fb75d6c54747c407fc315511d772d4e588
MD5 0c134e456a7bb9148137e4aa98e1cd41
BLAKE2b-256 ec454878365f10e3cdc3ac7f61757d1a64b91760bd491f466179bc749ac97d64

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page