Package: hishel
Hishel- An elegant HTTP Cache implementation for httpx and httpcore.Hishel (հիշել, remember)is a library that implements HTTP Caching forHTTPXandHTTP Corelibraries in accordance withRFC 9111, the most recent caching specification.Features💾Persistence: Responses are cached in thepersistent memoryfor 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 httpx while also enablingweb cache.🧠Smart: Attempts to clearly implement RFC 9111, understandsVary,Etag,Last-Modified,Cache-Control, andExpiresheaders, andhandles response re-validation automatically.⚙️Configurable: You have complete control over how the responses are stored and serialized.📦From the package:Built-in support forFile system,Redis,SQLite, andAWS S3backends.Built-in support forJSON,YAML, andpickleserializers.🚀Very fast: Your requests will be even faster if there areno IO operations.DocumentationGo through theHishel documentation.QuickStartInstallHishelusing pip:$pipinstallhishelLet's begin with an example of a httpx client.importhishelwithhishel.CacheClient()asclient:client.get("https://hishel.com")# 0.4749558370003797sclient.get("https://hishel.com")# 0.002873589000046195s (~250x faster!)or in asynchronous contextimporthishelasyncwithhishel.AsyncCacheClient()asclient:awaitclient.get("https://hishel.com")awaitclient.get("https://hishel.com")# takes from the cacheConfigurationsConfigure when and how you want to store your responses.importhishel# All the specification configscontroller=hishel.Controller(# Cache only GET and POST methodscacheable_methods=["GET","POST"],# Cache only 200 status codescacheable_status_codes=[200],# Use the stale response if there is a connection issue and the new response cannot be obtained.allow_stale=True,# First, revalidate the response and then utilize it.# If the response has not changed, do not download the# entire response data from the server; instead,# use the one you have because you know it has not been modified.always_revalidate=True,)# All the storage configsstorage=hishel.S3Storage(bucket_name="my_bucket_name",# store my cache files in the `my_bucket_name` bucketttl=3600,# delete the response if it is in the cache for more than an hour)client=hishel.CacheClient(controller=controller,storage=storage)# Ignore the fact that the server does not recommend you cache this request!client.post("https://example.com",extensions={"force_cache":True})# Return a regular response if it is in the cache; else, return a 504 status code. DO NOT SEND A REQUEST!client.post("https://example.com",headers=[("Cache-Control","only-if-cached")])# Ignore cached responses and do not store incoming responses!response=client.post("https://example.com",extensions={"cache_disabled":True})How and where are the responses saved?The responses are stored byHishelinstorages.
You have complete control over them; you can change storage or even write your own if necessary.Support the projectYou can support the project by simply leaving a GitHub star ⭐ or bycontributing.
Help us grow and continue developing good software for you ❤️Changelog0.0.24 (14th February, 2024)Fixbotocore is not installedexception when using any kind of storage. (#186)0.0.23 (14th February, 2024)MakeS3Storageto check staleness of all cache files with set interval. (#182)Fix an issue where an empty file inFileCachecould cause a parsing error. (#181)Support caching forPOSTand other HTTP methods. (#183)0.0.22 (31th January, 2024)MakeFileStorageto check staleness of all cache files with set interval. (#169)Support AWS S3 storages. (#164)Movetyping_extensionsfrom requirements.txt to pyproject.toml. (#161)0.0.21 (29th December, 2023)Fix inner transport and connection pool instances closing. (#147)Improved error message when the storage type is incorrect. (#138)0.0.20 (12th December, 2023)Add in-memory storage. (#133)Allow customization of cache key generation. (#130)0.0.19 (30th November, 2023)Addforce_cacheextension to enforce the request to be cached, ignoring the HTTP headers. (#117)Fix issue where sqlite storage cache get deleted immediately. (#119)Support float numbers for storage ttl. (#107)0.0.18 (23rd November, 2023)Fix issue where freshness cannot be calculated to re-send request. (#104)Addcache_disabledextension to temporarily disable the cache (#109)Updatedatetime.datetime.utcnow()todatetime.datetime.now(datetime.timezone.utc)sincedatetime.datetime.utcnow()has been deprecated. (#111)0.0.17 (6th November, 2023)FixLast-Modifiedvalidation.0.0.16 (25th October, 2023)Addinstall_cachefunction. (#95)Add sqlite support. (#92)Movettlargument toBaseStorageclass. (#94)0.0.14 (23rd October, 2023)ReplaceAsyncResponseStreamwithAsyncCacheStream. (#86)Addmust-understandresponse directive support. (#90)0.0.13 (5th October, 2023)Add support for Python 3.12. (#71)Fix connections releasing from the connection pool. (#83)0.0.12 (8th September, 2023)Add metadata into the response extensions. (#56)0.0.11 (15th August, 2023)Add support for requestcache-controldirectives. (#42)Drop httpcore dependency. (#40)Support HTTP methods only if they are defined as cacheable. (#37)0.0.10 (7th August, 2023)Add Response metadata. (#33)Add API Reference documentation. (#30)Use stale responses only if the client is disconnected. (#28)0.0.9 (1st August, 2023)Expose Controller API. (#23)0.0.8 (31st July, 2023)Skip redis tests if the server was not found. (#16)Decrease sleep time for the storage ttl tests. (#18)Fail coverage under 100. (#19)0.0.7 (30th July, 2023)Add support forHeuristic Freshness. (#11)ChangeController.cache_heuristicallytoController.allow_heuristics. (#12)Handle import errors. (#13)0.0.6 (29th July, 2023)FixVaryheader validation. (#8)Dump original requests with the responses. (#7)0.0.5 (29th July, 2023)Fix httpx response streaming.0.0.4 (29th July, 2023)ChangeYamlSerializername toYAMLSerializer.0.0.3 (28th July, 2023)Addfrom_cacheresponse extension.Addtyping_extensionsinto the requirements.0.0.2 (25th July, 2023)Addredissupport.Make backends thread and task safe.Add black as a new linter.Add an expire time for cached responses.