jpt/careful
1
2
Fork
You've already forked careful
0
a small library for writing resilient, well-behaved HTTP code in Python https://www.jpt.sh/projects/careful/
  • Python 99.3%
  • Just 0.7%
2026年02月14日 01:07:29 -06:00
docs 0.4.0 release 2026年02月14日 01:07:29 -06:00
src/careful fix up for 0.4 2026年02月14日 01:06:18 -06:00
tests fix up for 0.4 2026年02月14日 01:06:18 -06:00
.gitignore lots of docs 2025年09月06日 12:02:27 -05:00
.pre-commit-config.yaml pre-commit 2025年09月05日 03:43:55 -05:00
.spellignore 0.3.0 2025年09月08日 00:12:00 -05:00
.woodpecker.yml drop dependency on lint 2025年09月06日 23:15:03 -05:00
Justfile switch to structured logging 2026年02月14日 00:04:19 -06:00
LICENSE initial port of retry/throttle from scrapelib 2025年09月05日 03:11:35 -05:00
mkdocs.yml move docs 2025年11月22日 11:54:36 -06:00
pyproject.toml 0.4.0 release 2026年02月14日 01:07:29 -06:00
README.md move docs 2025年11月22日 11:54:36 -06:00
trifold.toml move docs 2025年11月22日 11:54:36 -06:00

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