http¶
src.utils.http
¶
Shared HTTP session factory with retry and rate-limit support.
Usage::
from src.utils.http import create_session
session = create_session()
resp = session.get("https://api.example.com/data", timeout=session.default_timeout)
create_session(*, retries: int = 3, backoff: float = 1.0, timeout: int = 30, extra_headers: dict[str, str] | None = None) -> requests.Session
¶
Create a :class:requests.Session with automatic retries.
The returned session retries on 429/5xx with exponential back-off and
stores a default_timeout attribute for convenience.
Source code in src/utils/http.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |