Status & timing¶
A11's error and time types. Native failures cross the boundary as
StatusException with structured details
preserved.
Status¶
a11.status.Status
¶
Creates a status from a canonical code, message, and details list.
from_exception
staticmethod
¶
from_exception(exc: BaseException, casters: StatusExceptionCasters | None = None) -> Status
Convert an application exception to a transportable status.
Existing StatusException values retain their structured status;
registered casters handle framework-specific types, and unknown
exceptions become UNKNOWN.
from_http_exception
staticmethod
¶
from_http_exception(http_exception: HTTPException | HTTPStatusError) -> Status
Convert a FastAPI/httpx HTTP exception to an A11 status.
get_fastapi_response_dict_for_codes
staticmethod
¶
get_fastapi_response_dict_for_codes(*codes: StatusCode) -> dict[int, dict]
Build FastAPI response documentation for portable status codes.
get_fastapi_response_dict_for_http_codes
staticmethod
¶
Build FastAPI response documentation for explicit HTTP codes.
ok
staticmethod
¶
ok(message: str | None = None) -> Status
Create a successful status with an optional descriptive message.
parse_from_json
staticmethod
¶
Parse status JSON and return validation state without throwing.
to_exception
¶
to_exception() -> StatusException
Convert a non-OK status to its Python boundary exception.
a11.status.StatusCode
¶
Bases: IntEnum
Portable gRPC/Abseil outcome codes used throughout A11.
Pick the most specific code a caller can act on: for example,
INVALID_ARGUMENT for input that can never work,
FAILED_PRECONDITION for a lifecycle state that could change, and
UNAVAILABLE for a dependency worth retrying. The conversion methods
preserve that intent at HTTP and WebSocket boundaries.
from_http_code
staticmethod
¶
from_http_code(http_code: int) -> StatusCode
Map an HTTP response code to the nearest portable status code.
from_ws_code
staticmethod
¶
from_ws_code(code: int) -> StatusCode
Decode standard and A11-private WebSocket close codes.
a11.status.StatusException
¶
StatusException(status: Status)
Bases: Exception
Python exception carrying a structured non-OK A11 status.
Catch this at an action or service boundary when you want to inspect or
forward status.code, status.message, and status.details. A11's
native Python bindings raise this type consistently rather than exposing an
Abseil or pybind11-specific exception.
Timing¶
a11.timing.Duration
¶
Creates a duration from a whole number of nanoseconds.
microseconds
staticmethod
¶
microseconds(value: SupportsFloat | SupportsIndex | None) -> Duration
Creates a duration from microseconds; None or negative means infinite.
milliseconds
staticmethod
¶
milliseconds(value: SupportsFloat | SupportsIndex | None) -> Duration
Creates a duration from milliseconds; None or negative means infinite.
nanoseconds
staticmethod
¶
nanoseconds(value: SupportsInt | SupportsIndex | None) -> Duration
Creates a duration from nanoseconds; None or negative means infinite.
seconds
staticmethod
¶
seconds(value: SupportsFloat | SupportsIndex | None) -> Duration
Creates a duration from seconds; None or negative means infinite.
float_seconds
¶
Returns the duration in seconds as a float; infinity_value is returned for a positive-infinite duration.
a11.timing.Time
¶
Creates a time from nanoseconds since the Unix epoch.