Skip to main content

careful extensions to httpx: throttle, retry, cache

Project description

careful

logo of a warning sign

careful is a library for making requests to unreliable websites with httpx.

Code: https://codeberg.org/jpt/careful

Docs: https://careful.jpt.sh

It offers enhancements to httpx.Client useful for writing long-running scrapers & crawlers, particularly against sites that are slow or have intermittent errors.

  • configurable retry support. retry on timeouts or other errors, with exponential back-off.
  • simple request throttling. set a maximum number of requests per minute.
  • development cache. configurable caching aimed at reducing redundant requests made while authoring/testing web scrapers.

example

from httpx import Client
from careful.httpx import make_careful_client

client = make_careful_client(
    # can configure httpx.Client however you usually would
    client=Client(headers={'user-agent': 'careful/1.0'}),
    # retries are configurable w/ exponential back off
    retry_attempts=2,
    retry_wait_seconds=5,
    # can cache to process memory, filesystem, or SQLite
    cache_storage=MemoryCache(),
    # requests will automatically be throttled to aim at this rate
    requests_per_minute=60,
)

# all normal methods on httpx.Client make use of configured enhancements
client.get("https://example.com")

Logo licensed from Adrien Coquet via Noun Project

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

careful-0.2.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

careful-0.2.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file careful-0.2.0.tar.gz.

File metadata

  • Download URL: careful-0.2.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.2

File hashes

Hashes for careful-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e3232f06c0d296d8fcdf5caea03aafbabf28274c5d39f1e0e07bcdf11b9a6800
MD5 24efb8281e7f7d2f4cfe853db7c8b7b5
BLAKE2b-256 1217d7d3fda07da37c860d127834f20ceef8cc94cd94799c8ee64f2cd6e9018a

See more details on using hashes here.

File details

Details for the file careful-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: careful-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.2

File hashes

Hashes for careful-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b9360a0a230510e400cd6b50f3cb0fae3b1daa7f168b249dda98a581d424fd5
MD5 23dd4515c7a7a43902d8ace2c9ed0597
BLAKE2b-256 ece9fd23d52eb90856be73eb2d250d929f9a81a9e185dc7c9bf220d4575a220a

See more details on using hashes here.

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