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!)

If the response is cacheable according to RFC 9111, hishel will save it for later use, so the user only needs to change the client and the rest of the staff will be done automatically.

Hishel also works well with httpcore, and you can make your httpcore connection pools cacheable with a single line of code.

Your existing code

from httpcore import ConnectionPool

pool = ConnectionPool()

...

Adding HTTP caching to your program will make it much faster and more efficient.

import hishel
from httpcore import ConnectionPool

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

As you can see, it is extremely simple to integrate.

Because Hishel respects your custom transports and connection pools, it requires the real ConnectionPool and the real HTTPTransport to work on top of it.

Transports example:

import httpx
import hishel

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

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

cache_transport.handle_request(req)
cache_transport.handle_request(req)

How and where are the responses saved?

Hishel supports a variety of backends for storing responses, but the filesystem is the default.

You can also use another backend, such as redis, to store your responses, or even write your own if necessary.

Contributing

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

The most common strategy for contributing Hishel appears to be:

  • Fork the project
  • Make change
  • Open the pull request# Changelog

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.2.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

hishel-0.0.2-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for hishel-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4582dbad400dc6666e26d86b4d391eba3dc13cd1a04a68b0cd76f09dc149969f
MD5 5a9067303f9e5391d6d328f3ec2036c9
BLAKE2b-256 fc48be364ee93af46648032c48d8104e38c12d25570167a39cbb175261f07046

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for hishel-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0570f32cbc17da3bfb34897bf54cc91e687f74fd342f9c0d0e72f00df78a52a
MD5 e64798c55ad0a0ad050eb805806ae374
BLAKE2b-256 bb81f2a189a4dbc9587c99ba5f85a18a8e6f2e71bb7942458c4bcfdd61ad28f0

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