assets_guardian.core.clients.http_client

Classes

HttpClient([base_url,Β headers,Β timeout,Β ...])

Generic HTTP client with retry logic, exponential backoff, and 429 handling.

class assets_guardian.core.clients.http_client.HttpClient(base_url: str = '', headers: dict[str, str] | None = None, timeout: int = 30, max_retries: int = 3)[source]

Bases: object

Generic HTTP client with retry logic, exponential backoff, and 429 handling.

Parameters:
  • base_url – The base URL for all requests.

  • headers – Headers to include in each request.

  • timeout – The default timeout in seconds.

  • max_retries – The maximum number of attempts for 429 and 500+ errors.

Initializes the HttpClient.

delete(url: str, **kwargs: Any) Response[source]

Sends a DELETE request.

Parameters:
  • url – The URL or path (appended to base_url).

  • **kwargs – Extra arguments for requests.request.

Returns:

The HTTP response.

Return type:

requests.Response

Raises:
  • HTTPError – If the request fails after the maximum number of attempts.

  • RequestException – For other errors related to the request.

get(url: str, **kwargs: Any) Response[source]

Sends a GET request.

Parameters:
  • url – The URL or path (appended to base_url).

  • **kwargs – Extra arguments for requests.request.

Returns:

The HTTP response.

Return type:

requests.Response

Raises:
  • HTTPError – If the request fails after the maximum number of attempts.

  • RequestException – For other errors related to the request.

patch(url: str, **kwargs: Any) Response[source]

Sends a PATCH request.

Parameters:
  • url – The URL or path (appended to base_url).

  • **kwargs – Extra arguments for requests.request.

Returns:

The HTTP response.

Return type:

requests.Response

Raises:
  • HTTPError – If the request fails after the maximum number of attempts.

  • RequestException – For other errors related to the request.

post(url: str, **kwargs: Any) Response[source]

Sends a POST request.

Parameters:
  • url – The URL or path (appended to base_url).

  • **kwargs – Extra arguments for requests.request.

Returns:

The HTTP response.

Return type:

requests.Response

Raises:
  • HTTPError – If the request fails after the maximum number of attempts.

  • RequestException – For other errors related to the request.

put(url: str, **kwargs: Any) Response[source]

Sends a PUT request.

Parameters:
  • url – The URL or path (appended to base_url).

  • **kwargs – Extra arguments for requests.request.

Returns:

The HTTP response.

Return type:

requests.Response

Raises:
  • HTTPError – If the request fails after the maximum number of attempts.

  • RequestException – For other errors related to the request.

request(method: str, url: str, **kwargs: Any) Response[source]

Sends an HTTP request with retry logic.

Parameters:
  • method – The HTTP method (GET, POST, etc.).

  • url – The URL or path (appended to base_url).

  • **kwargs – Extra arguments for requests.request.

Returns:

The HTTP response.

Return type:

requests.Response

Raises:
  • HTTPError – If the request fails after the maximum number of attempts.

  • RequestException – For other errors related to the request.