statuspro_public_api_client¶
statuspro_public_api_client
¶
StatusPro Public API Client — Python client for the StatusPro API.
Classes¶
APIError(message, status_code, error_response=None)
¶
AuthenticatedClient
¶
A Client which has been authenticated for use on secured endpoints
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
``cookies``: A dictionary of cookies to be sent with every request
``headers``: A dictionary of headers to be sent with every request
``timeout``: The maximum amount of a time a request can take. API functions will raise
httpx.TimeoutException if this is exceeded.
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
but can be set to False for testing purposes.
``follow_redirects``: Whether or not to follow redirects. Default value is False.
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
Functions¶
__aenter__()
async
¶
Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)
__aexit__(*args, **kwargs)
async
¶
Exit a context manager for underlying httpx.AsyncClient (see httpx docs)
__enter__()
¶
Enter a context manager for self.client—you cannot enter twice (see httpx docs)
__exit__(*args, **kwargs)
¶
Exit a context manager for internal httpx.Client (see httpx docs)
get_async_httpx_client()
¶
Get the underlying httpx.AsyncClient, constructing a new one if not previously set
Source code in statuspro_public_api_client/client.py
get_httpx_client()
¶
Get the underlying httpx.Client, constructing a new one if not previously set
Source code in statuspro_public_api_client/client.py
set_async_httpx_client(async_client)
¶
Manually set the underlying httpx.AsyncClient
NOTE: This will override any other settings on the client, including cookies, headers, and timeout.
Source code in statuspro_public_api_client/client.py
set_httpx_client(client)
¶
Manually set the underlying httpx.Client
NOTE: This will override any other settings on the client, including cookies, headers, and timeout.
Source code in statuspro_public_api_client/client.py
with_cookies(cookies)
¶
Get a new client matching this one with additional cookies
Source code in statuspro_public_api_client/client.py
with_headers(headers)
¶
Get a new client matching this one with additional headers
Source code in statuspro_public_api_client/client.py
with_timeout(timeout)
¶
Get a new client matching this one with a new timeout configuration
Source code in statuspro_public_api_client/client.py
AuthenticationError(message, status_code, error_response=None)
¶
Bases: APIError
Raised when authentication fails (401).
Source code in statuspro_public_api_client/utils.py
Client
¶
A class for keeping track of data related to the API
The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
``base_url``: The base URL for the API, all requests are made to a relative path to this URL
``cookies``: A dictionary of cookies to be sent with every request
``headers``: A dictionary of headers to be sent with every request
``timeout``: The maximum amount of a time a request can take. API functions will raise
httpx.TimeoutException if this is exceeded.
``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
but can be set to False for testing purposes.
``follow_redirects``: Whether or not to follow redirects. Default value is False.
``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
Functions¶
__aenter__()
async
¶
Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)
__aexit__(*args, **kwargs)
async
¶
Exit a context manager for underlying httpx.AsyncClient (see httpx docs)
__enter__()
¶
Enter a context manager for self.client—you cannot enter twice (see httpx docs)
__exit__(*args, **kwargs)
¶
Exit a context manager for internal httpx.Client (see httpx docs)
get_async_httpx_client()
¶
Get the underlying httpx.AsyncClient, constructing a new one if not previously set
Source code in statuspro_public_api_client/client.py
get_httpx_client()
¶
Get the underlying httpx.Client, constructing a new one if not previously set
Source code in statuspro_public_api_client/client.py
set_async_httpx_client(async_client)
¶
Manually set the underlying httpx.AsyncClient
NOTE: This will override any other settings on the client, including cookies, headers, and timeout.
Source code in statuspro_public_api_client/client.py
set_httpx_client(client)
¶
Manually set the underlying httpx.Client
NOTE: This will override any other settings on the client, including cookies, headers, and timeout.
Source code in statuspro_public_api_client/client.py
with_cookies(cookies)
¶
Get a new client matching this one with additional cookies
Source code in statuspro_public_api_client/client.py
with_headers(headers)
¶
Get a new client matching this one with additional headers
Source code in statuspro_public_api_client/client.py
with_timeout(timeout)
¶
Get a new client matching this one with a new timeout configuration
Source code in statuspro_public_api_client/client.py
RateLimitError(message, status_code, error_response=None)
¶
Bases: APIError
Raised when rate limit is exceeded (429).
Source code in statuspro_public_api_client/utils.py
ServerError(message, status_code, error_response=None)
¶
Bases: APIError
Raised when a server error occurs (5xx).
Source code in statuspro_public_api_client/utils.py
StatusProClient(api_key=None, base_url=None, timeout=30.0, max_retries=5, max_pages=100, logger=None, **httpx_kwargs)
¶
Bases: AuthenticatedClient
The pythonic StatusPro API client with automatic resilience and pagination.
Inherits from AuthenticatedClient and can be passed directly to
generated API methods without a .client property.
Features:
- Automatic retries on network errors and server errors (5xx)
- Automatic rate-limit handling (parses Retry-After, falls back to
exponential backoff on 429 since StatusPro doesn't emit the header)
- Auto-pagination for wrapped list endpoints ({"data": [...], "meta": {...}})
- Uses 100 items per page (StatusPro's max) by default
- Raw-array endpoints (/statuses, /orders/{id}/viable-statuses) are passed through
- Rich logging and observability
Auto-pagination behavior:
- ON by default for GET requests with no page parameter
- per_page defaults to 100; caller values are respected (capped at 100)
- ANY explicit page param disables auto-pagination
- Disabled per-request via extensions={"auto_pagination": False}
- max_pages constructor argument caps total pages collected
- extensions={"max_items": N} caps total items collected
Usage
async with StatusProClient() as client: from statuspro_public_api_client.api.orders import list_orders
response = await list_orders.asyncio_detailed(client=client)
# One specific page (disables auto-pagination)
response = await list_orders.asyncio_detailed(
client=client, page=2, per_page=25
)
Parameters:
-
api_key(str | None, default:None) –StatusPro API key. If None, will try to load from STATUSPRO_API_KEY env var, .env file, or ~/.netrc file (in that order).
-
base_url(str | None, default:None) –Base URL for the StatusPro API. Defaults to https://app.orderstatuspro.com/api/v1
-
timeout(float, default:30.0) –Request timeout in seconds. Defaults to 30.0.
-
max_retries(int, default:5) –Maximum number of retry attempts for failed requests. Defaults to 5.
-
max_pages(int, default:100) –Maximum number of pages to collect during auto-pagination. Defaults to 100.
-
logger(Logger | None, default:None) –Any object whose debug/info/warning/error methods accept (msg, *args, **kwargs) — the standard logging.Logger call convention (e.g. logging.Logger, structlog.BoundLogger). If None, creates a default stdlib logger.
-
**httpx_kwargs(Any, default:{}) –Additional arguments passed to the base AsyncHTTPTransport. Common parameters include: - http2 (bool): Enable HTTP/2 support - limits (httpx.Limits): Connection pool limits - verify (bool | str | ssl.SSLContext): SSL certificate verification - cert (str | tuple): Client-side certificates - trust_env (bool): Trust environment variables for proxy configuration - event_hooks (dict): Custom event hooks (will be merged with built-in hooks)
Raises:
-
ValueError–If no API key is provided via api_key param, STATUSPRO_API_KEY env var, .env file, or ~/.netrc file.
Note
Transport-related parameters (http2, limits, verify, etc.) are correctly passed to the innermost AsyncHTTPTransport layer, ensuring they take effect even with the layered transport architecture.
Example
async with StatusProClient() as client: ... # All API calls through client get automatic resilience ... response = await some_api_method.asyncio_detailed(client=client)
Source code in statuspro_public_api_client/statuspro_client.py
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 | |
ValidationError(message, status_code, error_response=None)
¶
Bases: APIError
Raised when request validation fails (422).
The validation_errors attribute is a dict[str, list[str]] mapping
field name to the list of human-readable error messages that StatusPro
returned for that field.
Source code in statuspro_public_api_client/utils.py
Functions¶
get_error_message(response)
¶
Extract message from an error response, if present.
Source code in statuspro_public_api_client/utils.py
handle_response(response, *, on_success=None, on_error=None, raise_on_error=False)
¶
Call on_success with parsed data for 2xx, on_error with an APIError otherwise.
Source code in statuspro_public_api_client/utils.py
is_error(response)
¶
is_success(response)
¶
unwrap(response, *, raise_on_error=True)
¶
Unwrap a Response and return parsed data, raising typed errors on failure.
Parameters:
-
response(Response[T]) –Response object from a generated API call.
-
raise_on_error(bool, default:True) –If True (default), raise an APIError subclass for non-2xx responses; if False, return None.
Returns:
-
T | None–The parsed response body.
Raises:
-
AuthenticationError–401
-
ValidationError–422
-
RateLimitError–429
-
ServerError–5xx
-
APIError–other non-2xx statuses
Source code in statuspro_public_api_client/utils.py
unwrap_as(response, expected_type, *, raise_on_error=True)
¶
Unwrap and assert the parsed body is of the expected type.
Source code in statuspro_public_api_client/utils.py
unwrap_data(response, *, raise_on_error=True, default=None)
¶
Unwrap a list response and extract the data array.
For StatusPro's wrapped list endpoints like GET /orders which return
{"data": [...], "meta": {...}}. For raw-array endpoints like
GET /statuses, use unwrap() directly — the parsed response is the
list itself.