Skip to main content

a small library for writing resilient, well-behaved HTTP code

Project description

careful

logo of a warning sign

careful is a Python library for writing resilient, well-behaved HTTP clients.

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

Docs: https://jpt.sh/projects/careful/

PyPI - Version status-badge

Call one function to enchant an httpx.Client, making your HTTP connections more resilient and better mannered.

  • Configure throttling to avoid accidental Denial-of-Service / risking getting banned.
  • Retries help overcome intermittent failures on flaky sites or long crawls.
  • Development caching Cache persists between runs during development, reduces redundant requests made while iterating on your crawlers & scrapers.

Example

from httpx import Client
from careful.httpx import make_careful_client

# the only function you need to call is make_careful_client
# this wraps your existing `httpx.Client` with your preferred
# careful behaviors

client = make_careful_client(
    client=Client(headers={'user-agent': 'spiderman/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(),

    # easy-to-configure throttling
    requests_per_minute=60,
)

# methods on client are called as they always are
# configured behaviors occur without further code changes
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.4.0.tar.gz (18.7 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.4.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: careful-0.4.0.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for careful-0.4.0.tar.gz
Algorithm Hash digest
SHA256 d7a419133b727ea5ecd18fbabdfb394b2e4660ba1b4ee0899975b0addab33cd8
MD5 98522fe05318cca15c687d3bbcb288d1
BLAKE2b-256 e05637312eb5ab8d4238c73623d31c12d6be6e6383c0403c1ac81e01ba3fea18

See more details on using hashes here.

File details

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

File metadata

  • Download URL: careful-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for careful-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5857eb9ff33086bb7faf275560d2ae43f92919a1d7abe05cbfe2e3adc06e7fac
MD5 747c6db7cbf785e39ed16ac287b75d71
BLAKE2b-256 315ddfe84479dad2082e3544be8ae7a1a17015ce001772aef37c4871e02be8ba

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