Rate Limiting and Caching HTTPX Client
Project description
HTTPX Wrapper with Rate Limiting and Caching Transports.
Introduction
The goal of this project is a combination of convenience and as a demonstration of how to assemble HTTPX Transports in different combinations.
HTTP request libraries, rate limiting and caching are topics with deep rabbit holes: the technical implementation details & the decisions an end user has to make. The convenience part of this package is abstracting away certain decisions and making certain opinionated decisions as to how caching & rate limiting should be controlled.
This came about while implementing caching & rate limiting for edgartools: reducing network requests and improving overall performance led to a myriad of decisions. The SEC's Edgar site has a strict 10 request per second limit, while providing not-very-helpful caching headers. Overriding these caching headers with custom rules is necessary in certain cases.
Caching
This project provides four cache_mode options:
- Disabled: Rate Limiting only
- Hishel-File: Cache using Hishel using FileStorage
- Hishel-S3: Cache using Hishel using S3Storage
- FileCache: Use a simpler filecache backend that uses file modified and created time and only revalidates using last-modified. For sites where last-modified is provided.
Cache Rules are defined as a dictionary of site regular expressions to path regular expressions.
{
'site_regex': {
'url_regex': duration,
'url_regex2': duration,
'.*': 3600, # cache all paths for this site for an hour
}
}
FileCache
The FileCache implementation stores files with a .meta sidecar. The .meta contains any additional file metadata that will increment on revalidation.
FileCache currently only revalidates using Last-Modified. Will do Etag support when I have a need for it (PRs welcome).
Rate Limiting
Rate limiting is implemented via pyrate_limiter. This is a leaky bucket implementation that allows a configurable number of requests per time interval.
pyrate_limiter supports a variable of backends. The default backend is in-memory, and a single Limiter can be used for both sync and asyncio requests, across multiple threads. Alternative limiters can be used for multiprocess and distributed rate limiting, see examples for more.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file httpxthrottlecache-0.1.6.tar.gz.
File metadata
- Download URL: httpxthrottlecache-0.1.6.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d065e853643587193a5149c8313a5e44f28586a7bcfc7c36e7256626258c9d7
|
|
| MD5 |
ba519700083c1eebf143b35219ecd192
|
|
| BLAKE2b-256 |
5aafe0cd319037f7bf85d8df725faace0f7451b51d40101f808a017d0b5ee914
|
Provenance
The following attestation bundles were made for httpxthrottlecache-0.1.6.tar.gz:
Publisher:
build_deploy.yml on paultiq/httpxthrottlecache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
httpxthrottlecache-0.1.6.tar.gz -
Subject digest:
1d065e853643587193a5149c8313a5e44f28586a7bcfc7c36e7256626258c9d7 - Sigstore transparency entry: 382762518
- Sigstore integration time:
-
Permalink:
paultiq/httpxthrottlecache@f8dddbc5f711f1b9c1072152d30d10d416fd20f9 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/paultiq
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_deploy.yml@f8dddbc5f711f1b9c1072152d30d10d416fd20f9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file httpxthrottlecache-0.1.6-py3-none-any.whl.
File metadata
- Download URL: httpxthrottlecache-0.1.6-py3-none-any.whl
- Upload date:
- Size: 13.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c92239babfa3dca046fada685dfd1778732eb94dfca9fd96693d86fda29e8245
|
|
| MD5 |
e9034eb3dd9bfe82960984705370a699
|
|
| BLAKE2b-256 |
bd5638efca1d1c8491638b58aead247c41a6e9306e71f1b0c31070a6d7e26a0b
|
Provenance
The following attestation bundles were made for httpxthrottlecache-0.1.6-py3-none-any.whl:
Publisher:
build_deploy.yml on paultiq/httpxthrottlecache
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
httpxthrottlecache-0.1.6-py3-none-any.whl -
Subject digest:
c92239babfa3dca046fada685dfd1778732eb94dfca9fd96693d86fda29e8245 - Sigstore transparency entry: 382762522
- Sigstore integration time:
-
Permalink:
paultiq/httpxthrottlecache@f8dddbc5f711f1b9c1072152d30d10d416fd20f9 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/paultiq
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_deploy.yml@f8dddbc5f711f1b9c1072152d30d10d416fd20f9 -
Trigger Event:
push
-
Statement type: