Handlers¶
Response handler factories. See the Response handlers guide for usage.
asyncly.client.handlers.json.parse_json
¶
parse_json(
parser: Callable, loads: Callable = loads
) -> Callable[[ClientResponse], Awaitable[Any]]
Build a response handler that decodes JSON and passes it to parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parser
|
Callable
|
Callable applied to the decoded JSON. May be sync or async.
Use |
required |
loads
|
Callable
|
JSON loader. Defaults to |
loads
|
Returns:
| Type | Description |
|---|---|
Callable[[ClientResponse], Awaitable[Any]]
|
An async handler usable as a value in a response-handlers mapping. |
Source code in asyncly/client/handlers/json.py
asyncly.client.handlers.pydantic.parse_model
¶
Build a response handler that validates the body into a Pydantic model.
Requires the pydantic extra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
type[T]
|
The |
required |
Returns:
| Type | Description |
|---|---|
Callable[[ClientResponse], Awaitable[T]]
|
An async handler usable as a value in a response-handlers mapping. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the body does not match the model. |
Source code in asyncly/client/handlers/pydantic.py
asyncly.client.handlers.msgspec.parse_struct
¶
parse_struct(
struct: type[T],
data_format: DataFormat = "json",
strict: bool = True,
) -> Callable[[ClientResponse], Awaitable[T]]
Build a response handler that decodes the body into a msgspec struct.
Requires the msgspec extra.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
struct
|
type[T]
|
The |
required |
data_format
|
DataFormat
|
Wire format of the body: |
'json'
|
strict
|
bool
|
Pass-through to msgspec strict decoding (no implicit coercion). |
True
|
Returns:
| Type | Description |
|---|---|
Callable[[ClientResponse], Awaitable[T]]
|
An async handler usable as a value in a response-handlers mapping. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the payload does not match |
Source code in asyncly/client/handlers/msgspec.py
Exceptions¶
asyncly.client.handlers.exceptions.UnhandledStatusException
¶
Bases: BaseHttpClientException, KeyError
Raised when a response status has no matching handler.
Attributes:
| Name | Type | Description |
|---|---|---|
status |
int
|
The unmatched response status code. |
url |
URL
|
The request URL. |
client_name |
str | None
|
The originating client's name, if known. |
Source code in asyncly/client/handlers/exceptions.py
asyncly.client.handlers.exceptions.BaseHttpClientException
¶
Bases: ClientError
Base class for exceptions raised by BaseHttpClient.