statuspro_public_api_client.statuspro_client¶
statuspro_public_api_client.statuspro_client
¶
StatusProClient - The pythonic StatusPro API client with automatic resilience.
This client uses httpx's native transport layer to provide automatic retries, rate limiting, error handling, and pagination for all API calls without any decorators or wrapper methods needed.
Attributes¶
Classes¶
ErrorLoggingTransport(wrapped_transport=None, logger=None, **kwargs)
¶
Bases: AsyncHTTPTransport
Transport layer that adds detailed error logging for 4xx client errors.
This transport wraps another AsyncHTTPTransport and intercepts responses to log detailed error information using the generated error models.
Parameters:
-
wrapped_transport(AsyncHTTPTransport | None, default:None) –The transport to wrap. If None, creates a new AsyncHTTPTransport.
-
logger(Logger | None, default:None) –Logger instance for capturing error details. If None, creates a default logger.
-
**kwargs(Any, default:{}) –Additional arguments passed to AsyncHTTPTransport if wrapped_transport is None.
Source code in statuspro_public_api_client/statuspro_client.py
Functions¶
handle_async_request(request)
async
¶
Handle request and log detailed error information for 4xx responses.
Source code in statuspro_public_api_client/statuspro_client.py
PaginationTransport(wrapped_transport=None, max_pages=100, logger=None, **kwargs)
¶
Bases: AsyncHTTPTransport
Transport layer that adds automatic pagination for GET requests.
Auto-pagination behavior (for StatusPro's page/per_page scheme):
- ON by default for GET requests with NO page parameter in URL
- Uses 100 items per page (StatusPro's max) when no per_page is specified
- If caller specifies per_page, that value is respected
- ANY explicit page parameter disables auto-pagination
- Disabled when request has extensions={"auto_pagination": False}
- Only applies to GET requests
- Only applies to wrapped list responses ({"data": [...], "meta": {...}});
raw-array responses like /statuses are passed through unchanged.
Controlling pagination limits:
- max_pages (constructor): Maximum number of pages to fetch
- max_items (extension): Maximum total items to collect, e.g.,
extensions={"max_items": 200}
Parameters:
-
wrapped_transport(AsyncHTTPTransport | None, default:None) –The transport to wrap. If None, creates a new AsyncHTTPTransport.
-
max_pages(int, default:100) –Maximum number of pages to collect during auto-pagination. Defaults to 100.
-
logger(Logger | None, default:None) –Logger instance for capturing pagination operations. If None, creates a default logger.
-
**kwargs(Any, default:{}) –Additional arguments passed to AsyncHTTPTransport if wrapped_transport is None.
Source code in statuspro_public_api_client/statuspro_client.py
Functions¶
handle_async_request(request)
async
¶
Handle request with automatic pagination for GET requests.
Auto-pagination is ON by default for GET requests. It is disabled when:
- extensions={"auto_pagination": False} is set, OR
- ANY explicit page parameter is in the URL (e.g., ?page=1 or ?page=2)
To get auto-pagination, simply don't pass a page parameter. The transport will automatically use 100 items per page (StatusPro's max) unless you specify a limit, in which case your limit will be respected.
Source code in statuspro_public_api_client/statuspro_client.py
RateLimitAwareRetry(*args, **kwargs)
¶
Bases: Retry
Custom Retry class that allows non-idempotent methods (POST, PATCH) to be retried ONLY when receiving a 429 (Too Many Requests) status code.
For all other retryable status codes (502, 503, 504), only idempotent methods (HEAD, GET, PUT, DELETE, OPTIONS, TRACE) will be retried.
This ensures we don't accidentally retry non-idempotent operations after server errors, but we DO retry them when we're being rate-limited.
Source code in statuspro_public_api_client/statuspro_client.py
Functions¶
increment()
¶
Return a new retry instance with the attempt count incremented.
Source code in statuspro_public_api_client/statuspro_client.py
is_retryable_method(method)
¶
Allow all methods to pass through the initial check.
Store the method for later use in is_retryable_status_code.
Source code in statuspro_public_api_client/statuspro_client.py
is_retryable_status_code(status_code)
¶
Check if a status code is retryable for the current method.
For 429 (rate limiting), allow all methods. For other errors (502, 503, 504), only allow idempotent methods.
Source code in statuspro_public_api_client/statuspro_client.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 | |
Functions¶
ResilientAsyncTransport(max_retries=5, max_pages=100, logger=None, **kwargs)
¶
Factory function that creates a chained transport with error logging, pagination, and retry capabilities.
This function chains multiple transport layers: 1. AsyncHTTPTransport (base HTTP transport) 2. ErrorLoggingTransport (logs detailed 4xx errors) 3. PaginationTransport (auto-collects paginated responses) 4. RetryTransport (handles retries with Retry-After header support)
Parameters:
-
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) –Logger instance for capturing operations. If None, creates a default logger.
-
**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
Returns:
-
RetryTransport–A RetryTransport instance wrapping all the layered transports.
Note
When using a custom transport, parameters like http2, limits, and verify must be passed to this factory function (which passes them to the base AsyncHTTPTransport), not to the httpx.Client/AsyncClient constructor.
Example
Source code in statuspro_public_api_client/statuspro_client.py
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 | |