API Reference

class http_ping.HttpRequest(url: str, method: str = 'GET', headers: dict[str, str]=<factory>, body: Any = None, timeout: float = 30.0, auth: str | None = None)[source]

Configuration for an HTTP request.

auth: str | None = None
body: Any = None
headers: dict[str, str]
method: str = 'GET'
timeout: float = 30.0
url: str
class http_ping.HttpAuth[source]

Helpers to build common Authorization header values.

static basic(username: str, password: str) str[source]

Return an Authorization header value using the Basic scheme.

static bearer(value: str) str[source]

Return an Authorization header value using the Bearer scheme.

static token(value: str) str[source]

Return an Authorization header value using the Token scheme.

class http_ping.HttpPing(request: HttpRequest, *, retries: int = 3, backoff: float = 1.0)[source]

Executes an HttpRequest and returns status code, body and elapsed time.

Retries automatically on network errors and 5xx responses. Backoff between retries doubles each time: backoff, backoff*2, backoff*4, …

run() dict[str, Any][source]

Execute the request with retry logic.

Returns a dict with:
  • status_code: int

  • body: parsed JSON if possible, else str

  • elapsed_seconds: float (last attempt only)

  • attempts: int

class http_ping.HttpPingBatch(http_requests: list[HttpRequest], *, retries: int = 3, backoff: float = 1.0)[source]

Executes a list of HttpRequests sequentially and returns a result per URL.

Uses the same retries and backoff for every request. If a request fails after all retries, its result includes an “error” key instead of “status_code”/”body”/”elapsed_seconds”. Execution continues with the remaining URLs regardless of individual failures.

run() list[dict[str, Any]][source]

Execute all requests and return one result dict per URL.