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 usingawait 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.
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
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:
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, orIterator.kwargs (
RequestKwargs) — Additional parameters forwarded tohttpx, such as:params(dict) — Query parametersheaders(dict) — Extra headerstimeout(float)json,datainputs, etc.
Returns
Parsed response according to
response_encoding:Json→dictorlistText→strBytes→bytesIterator→(headers, async iterator over bytes)
Example
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 bodyparams— Query parameters
Returns
Decoded server response.
Example
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:
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 bodydata(dict) — Form dataparams(dict) — URL query parameters
Returns
The decoded server response according to
response_encoding.
Example
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:
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 tohttpx.
Returns
Parsed response according to the selected
response_encoding.
Example
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 byhttpx, such asjson,params, ordata.
Response Structure
response (
Any) — Decoded response object according to the selected encoding:Json→ Parsed JSON (dictorlist)Text→ String response bodyBytes→ Raw bytesIterator→ Tuple of(headers, AsyncIterator[bytes])for streamed data