petchr
A zero-dependency HTTP client for Python with retry, timeout, and rate-limiting built in.
pip install petchr
Requires Python 3.9+
Why petchr?
requests is great but has no built-in retry or rate-limiting. httpx is modern but requires extra packages for resilience. petchr wraps Python's built-in urllib with everything you need — zero dependencies.
| Feature | urllib | requests | petchr |
|---|---|---|---|
| Zero dependencies | ✅ | ❌ | ✅ |
| Auto-retry w/ backoff | ❌ | ❌ | ✅ |
| Timeout | ✅ | ✅ | ✅ |
| Rate limiting | ❌ | ❌ | ✅ |
| JSON body shorthand | ❌ | ✅ | ✅ |
| Query params object | ❌ | ✅ | ✅ |
| Shared instance config | ❌ | ✅ | ✅ |
Quick Start
from petchr import petch
resp = petch("https://api.example.com/users/1")
print(resp.data) # parsed JSON
Instance API
from petchr import Petchr
api = Petchr(
base_url="https://api.example.com",
headers={"Authorization": f"Bearer {token}"},
timeout=10.0,
retry=3,
)
user = api.get("/users/1")
post = api.post("/posts", json={"title": "Hello"})
api.delete("/posts/123")
Retry
resp = petch("https://api.example.com/data",
retry=5,
retry_delay=1.0, # initial delay in seconds
retry_backoff=2.0, # exponential multiplier
retry_max_delay=30.0, # cap
retry_on={429, 503}, # status codes to retry
on_retry=lambda attempt, err, resp: print(f"Retry {attempt}"),
)
Timeout
from petchr import PetchrTimeoutError
try:
resp = petch("https://slow-api.example.com", timeout=5.0)
except PetchrTimeoutError as e:
print(f"Timed out after {e.timeout}s")
Rate Limiting
from petchr import Petchr, RateLimiter
api = Petchr(
base_url="https://api.example.com",
rate_limiter=RateLimiter(max_requests=10, window_seconds=1.0),
)
Error Handling
from petchr import petch, PetchrError, PetchrTimeoutError, PetchrRateLimitError
try:
resp = petch("https://api.example.com/users/1")
except PetchrTimeoutError as e:
print(f"Timed out after {e.timeout}s")
except PetchrRateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after}s")
except PetchrError as e:
print(f"HTTP {e.status_code}: {e}")
License
MIT
Metadata
Release files for petchr 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| petchr-1.0.0.tar.gz | 7.8 kB | Without provenance | Details for petchr-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| petchr-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for petchr-1.0.0-py3-none-any.whl |
Total release size: 14.4 kB
Release files / petchr-1.0.0.tar.gz
| Download URL | petchr-1.0.0.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf0050d93d88e4d5b14e472a133c0503b0e75b5b7ef7ae344d90b6cdb084433f
|
|
BLAKE2b-256 checksum How to use checksums |
831292cc655363d611a380fae94ff0ec1c63097390eb17b1f31a5a94f076b50c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / petchr-1.0.0-py3-none-any.whl
| Download URL | petchr-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
379430a70ef0e35e023ab6fd320cc841c57e66aa51d80ba134acd1e50f92fa59
|
|
BLAKE2b-256 checksum How to use checksums |
27309d84ead67190a101097cc3b52f51c84fda99bcb49b246fb2e53a517f8ff0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Security for petchr 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.