Skip to main content

Rate Limiting and Caching HTTPX Client

Project description

HTTPX Wrapper with Rate Limiting and Caching Transports.

PyPI Version Python Versions

BuildRelease Tests Coverage badge

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

httpxthrottlecache-0.1.6.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

httpxthrottlecache-0.1.6-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

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

Hashes for httpxthrottlecache-0.1.6.tar.gz
Algorithm Hash digest
SHA256 1d065e853643587193a5149c8313a5e44f28586a7bcfc7c36e7256626258c9d7
MD5 ba519700083c1eebf143b35219ecd192
BLAKE2b-256 5aafe0cd319037f7bf85d8df725faace0f7451b51d40101f808a017d0b5ee914

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpxthrottlecache-0.1.6.tar.gz:

Publisher: build_deploy.yml on paultiq/httpxthrottlecache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file httpxthrottlecache-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for httpxthrottlecache-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c92239babfa3dca046fada685dfd1778732eb94dfca9fd96693d86fda29e8245
MD5 e9034eb3dd9bfe82960984705370a699
BLAKE2b-256 bd5638efca1d1c8491638b58aead247c41a6e9306e71f1b0c31070a6d7e26a0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for httpxthrottlecache-0.1.6-py3-none-any.whl:

Publisher: build_deploy.yml on paultiq/httpxthrottlecache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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