Http client

Asynchronous HTTP client wrapper used internally by Norman services.

The HttpClient class provides coroutine-based convenience methods (get, post, put, patch, delete, post_multipart) that wrap an underlying httpx.AsyncClient. It supports automatic base URL resolution, timeout configuration, request header management, and multiple response decoding modes (JSON, Bytes, Text, Iterator).

All requests use Bearer-token authorization with the Sensitive[str] security wrapper for secure credential handling.

⚠️ Important: Before making any API calls, you must open the client using await client.open() and close it using await client.close() once done — or simply use it as an async context manager:

python async with HttpClient() as client: response = await client.get("persist/models/get", token=my_token) print(response)

Using the context manager is the recommended pattern, as it ensures proper session lifecycle management and automatic cleanup of resources.

close() async

Coroutine

Close the internal httpx.AsyncClient session.

Raises an exception if called without a matching open.

get(endpoint, token=None, *, response_encoding=ResponseEncoding.Json, **kwargs) async

Coroutine

Send an HTTP GET request to the given endpoint.

This is a convenience wrapper for:

await self.request("GET", endpoint, ...)
Parameters
  • endpoint (str) — API path relative to the base URL.

  • token (Optional[Sensitive[str]]) — Optional bearer token for authorization.

  • response_encoding (ResponseEncoding) — Determines how the response body is decoded: Json, Text, Bytes, or Iterator.

  • kwargs (RequestKwargs) — Additional parameters forwarded to httpx, such as:

  • params (dict) — Query parameters

  • headers (dict) — Extra headers

  • timeout (float)

  • json, data inputs, etc.

Returns
  • Parsed response according to response_encoding:

  • Jsondict or list

  • Textstr

  • Bytesbytes

  • Iterator(headers, async iterator over bytes)

Example
async with HttpClient() as client:
    models = await client.get("models/list", token=my_token)


delete(endpoint, token=None, *, response_encoding=ResponseEncoding.Json, **kwargs) async

Coroutine

Send an HTTP DELETE request to remove a resource.

Parameters
  • endpoint (str) — Resource path to delete.

  • token (Optional[Sensitive[str]]) — Authorization token.

  • response_encoding (ResponseEncoding) — How to decode the response.

  • kwargs (RequestKwargs) — Additional supported HTTP arguments.

Returns
  • Parsed response (typically JSON or text).

Example
async with HttpClient() as client:
    resp = await client.delete("models/123", token=my_token)


get(endpoint, token=None, *, response_encoding=ResponseEncoding.Json, **kwargs) async

Coroutine

Send an HTTP GET request to the given endpoint.

This is a convenience wrapper for:

await self.request("GET", endpoint, ...)
Parameters
  • endpoint (str) — API path relative to the base URL.

  • token (Optional[Sensitive[str]]) — Optional bearer token for authorization.

  • response_encoding (ResponseEncoding) — Determines how the response body is decoded: Json, Text, Bytes, or Iterator.

  • kwargs (RequestKwargs) — Additional parameters forwarded to httpx, such as:

  • params (dict) — Query parameters

  • headers (dict) — Extra headers

  • timeout (float)

  • json, data inputs, etc.

Returns
  • Parsed response according to response_encoding:

  • Jsondict or list

  • Textstr

  • Bytesbytes

  • Iterator(headers, async iterator over bytes)

Example
async with HttpClient() as client:
    models = await client.get("models/list", token=my_token)


open() async

Coroutine

Open an internal httpx.AsyncClient session if not already open. This is automatically handled during context manager entry.

patch(endpoint, token=None, *, response_encoding=ResponseEncoding.Json, **kwargs) async

Coroutine

Send an HTTP PATCH request to modify fields of an existing resource.

Parameters
  • endpoint (str) — Endpoint relative to the base URL.

  • token (Optional[Sensitive[str]]) — Bearer token for authentication.

  • response_encoding (ResponseEncoding) — Output decoding mode.

  • kwargs (RequestKwargs) — Additional keyword arguments such as:

  • json — Patch body

  • params — Query parameters

Returns
  • Decoded server response.

Example
patch_data = {"description": "Updated text"}
async with HttpClient() as client:
    resp = await client.patch("models/modify/123", json=patch_data, token=my_token)


post(endpoint, token=None, *, response_encoding=ResponseEncoding.Json, **kwargs) async

Coroutine

Send an HTTP POST request to the given endpoint.

This is a convenience wrapper around:

await self.request("POST", endpoint, ...)
Parameters
  • endpoint (str) — API path relative to the base URL.

  • token (Optional[Sensitive[str]]) — Authorization token.

  • response_encoding (ResponseEncoding) — Response decoding mode.

  • kwargs (RequestKwargs) — Additional request arguments such as:

  • json (Any) — JSON request body

  • data (dict) — Form data

  • params (dict) — URL query parameters

Returns
  • The decoded server response according to response_encoding.

Example
payload = {"name": "test"}
async with HttpClient() as client:
    created = await client.post("models/create", json=payload, token=my_token)


post_multipart(endpoint, token, *, response_encoding=ResponseEncoding.Json, **kwargs) async

Coroutine

Send a multipart form-data POST request for file uploads.

Parameters
  • endpoint (str) — API endpoint relative to the base URL.

  • token (Sensitive[str]) — Bearer token used for authorization.

  • response_encoding (ResponseEncoding) — Determines how to parse the response. Defaults to JSON.

  • kwargs — Additional request arguments:

  • data (dict) — Form fields to include.

  • files (dict) — File-like objects to upload.

Response Structure
  • response (Any) — Decoded server response, typically a parsed JSON object.

Example Usage:
files = {"file": open("weights.pt", "rb")}
async with HttpClient() as client:
    response = await client.post_multipart("upload/model", token=my_token, files=files)
    print(response)

put(endpoint, token=None, *, response_encoding=ResponseEncoding.Json, **kwargs) async

Coroutine

Send an HTTP PUT request to the given endpoint.

Parameters
  • endpoint (str) — Target API path.

  • token (Optional[Sensitive[str]]) — Optional bearer token.

  • response_encoding (ResponseEncoding) — Response parsing strategy.

  • kwargs (RequestKwargs) — Extra arguments passed directly to httpx.

Returns
  • Parsed response according to the selected response_encoding.

Example
update = {"enabled": True}
async with HttpClient() as client:
    resp = await client.put("models/update/123", json=update, token=my_token)

request(method, endpoint, token=None, *, response_encoding=ResponseEncoding.Json, **kwargs) async

Coroutine

Send an HTTP request with the given method and endpoint.

Parameters
  • method (str) — HTTP method (e.g., "GET", "POST", "PATCH", "DELETE").

  • endpoint (str) — API endpoint relative to the configured base URL.

  • token (Optional[Sensitive[str]]) — Optional bearer token used for authorization.

  • response_encoding (ResponseEncoding) — Determines how the response is parsed. Options include: Json, Text, Bytes, Iterator.

  • kwargs (RequestKwargs) — Additional keyword arguments supported by httpx, such as json, params, or data.

Response Structure
  • response (Any) — Decoded response object according to the selected encoding:

  • Json → Parsed JSON (dict or list)

  • Text → String response body

  • Bytes → Raw bytes

  • Iterator → Tuple of (headers, AsyncIterator[bytes]) for streamed data

Example Usage:
async with HttpClient() as client:
    response = await client.request("GET", "models", token=my_token)
    print(response)

·

©

2026

·

©

2026

·

©

2026

·

©

2026