nemoguardrails.http.transport

View as Markdown

HTTPX transport adapter for the transport-neutral HTTP client contract.

Module Contents

Classes

NameDescription
HttpxHTTPClientAdapt an HTTPX asynchronous client to the neutral HTTP contract.

Functions

NameDescription
_sanitize_request_error-

Data

_DEFAULT_TIMEOUT_SECONDS

API

class nemoguardrails.http.transport.HttpxHTTPClient(
client: httpx.AsyncClient | None = None,
timeout: float | None = _DEFAULT_TIMEOUT_SECONDS,
limits: httpx.Limits | None = None,
follow_redirects: bool = False,
tls: nemoguardrails.http.types.HTTPTLSConfig | None = None
)

Adapt an HTTPX asynchronous client to the neutral HTTP contract.

A client created by this adapter is owned and closed by the adapter. An injected client remains owned by its caller. The configured timeout covers the complete request rather than each HTTPX timeout phase independently.

_client
_owns_client
= client is None
_timeout
= timeout if self._owns_client else None
async

Return this client from an asynchronous context manager.

nemoguardrails.http.transport.HttpxHTTPClient.__aexit__(
exc_type: object,
exc_value: object,
traceback: object
) -> None
async

Close owned resources when leaving an asynchronous context.

nemoguardrails.http.transport.HttpxHTTPClient.close() -> None
async

Close the owned HTTPX client at most once.

nemoguardrails.http.transport.HttpxHTTPClient.request(
method: str,
url: str,
headers: typing.Mapping[str, str] | None = None,
params: typing.Mapping[str, typing.Any] | None = None,
json: typing.Any = None,
content: bytes | str | None = None,
timeout: float | None = None
) -> nemoguardrails.http.types.HTTPResponse
async

Send one request and materialize the HTTPX response.

Parameters:

method
str

HTTP method.

url
str

Absolute request URL.

headers
Mapping[str, str] | NoneDefaults to None

Optional request headers.

params
Mapping[str, Any] | NoneDefaults to None

Optional query parameters.

json
AnyDefaults to None

Optional JSON-serializable request body.

content
bytes | str | NoneDefaults to None

Optional raw request body.

timeout
float | NoneDefaults to None

Optional per-request total timeout in seconds.

Returns: HTTPResponse

A neutral response containing copied headers and body bytes.

Raises:

  • HTTPTimeoutError: If the request exceeds its total timeout.
  • HTTPConnectionError: If HTTPX reports a request failure.
  • ValueError: If the per-request timeout is not positive.
nemoguardrails.http.transport._sanitize_request_error(
error: httpx.RequestError
) -> httpx.RequestError
nemoguardrails.http.transport._DEFAULT_TIMEOUT_SECONDS = 30.0