katana_public_api_client.katana_client¶
katana_public_api_client.katana_client
¶
KatanaClient - The pythonic Katana 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.
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 katana_public_api_client/katana_client.py
Functions¶
handle_async_request(request)
async
¶
Handle request and log detailed error information for 4xx responses.
Source code in katana_public_api_client/katana_client.py
KatanaClient(api_key=None, base_url=None, timeout=30.0, max_retries=5, max_pages=100, logger=None, **httpx_kwargs)
¶
Bases: AuthenticatedClient
The pythonic Katana API client with automatic resilience and pagination.
This client inherits from AuthenticatedClient and can be passed directly to generated API methods without needing the .client property.
Features: - Automatic retries on network errors and server errors (5xx) - Automatic rate limit handling with Retry-After header support - Auto-pagination ON by default for all GET requests (collects all pages automatically) - Rich logging and observability - Minimal configuration - just works out of the box
Auto-pagination behavior:
- ON by default for all GET requests
- Automatically detects paginated responses and collects all pages
- Disabled when ANY explicit page parameter is in URL (including page=1)
- Disabled per-request via extensions: extensions={"auto_pagination": False}
- Control max pages via max_pages constructor parameter
- Limit total items via extensions: extensions={"max_items": 200}
Usage
async with KatanaClient() as client: from katana_public_api_client.api.product import get_all_products
# Auto-pagination is ON by default - all pages collected automatically
response = await get_all_products.asyncio_detailed(
client=client, # Pass client directly - no .client needed!
limit=50 # Page size (all pages still collected)
)
# Get a specific page only (ANY explicit page param disables auto-pagination)
response = await get_all_products.asyncio_detailed(
client=client,
page=2, # Get page 2 only (page=1 also disables auto-pagination)
limit=50
)
# Limit total items collected (via httpx client)
httpx_client = client.get_async_httpx_client()
response = await httpx_client.get(
"/products",
params={"limit": 50}, # Page size
extensions={"max_items": 200} # Stop after 200 items
)
# Control max pages globally
client_limited = KatanaClient(max_pages=5) # Limit to 5 pages max
Parameters:
-
api_key(str | None, default:None) –Katana API key. If None, will try to load from KATANA_API_KEY env var, .env file, or ~/.netrc file (in that order).
-
base_url(str | None, default:None) –Base URL for the Katana API. Defaults to https://api.katanamrp.com/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) –Logger instance for capturing client operations. If None, creates a default 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, KATANA_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 KatanaClient() as client: ... # All API calls through client get automatic resilience ... response = await some_api_method.asyncio_detailed(client=client)
Source code in katana_public_api_client/katana_client.py
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 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 | |
Attributes¶
inventory
property
¶
Access inventory and stock operations.
Returns:
-
Inventory–Inventory instance for stock levels, movements, and adjustments.
Example
async with KatanaClient() as client: ... # Check stock levels ... stock = await client.inventory.check_stock("WIDGET-001") ... low_stock = await client.inventory.list_low_stock(threshold=10)
materials
property
¶
Access material catalog operations.
Returns:
-
Materials–Materials instance for material CRUD operations.
Example
async with KatanaClient() as client: ... materials = await client.materials.list() ... material = await client.materials.get(123)
products
property
¶
Access product catalog operations.
Returns:
-
Products–Products instance for product CRUD and search operations.
Example
async with KatanaClient() as client: ... # Product CRUD ... products = await client.products.list(is_sellable=True) ... product = await client.products.get(123) ... results = await client.products.search("widget")
services
property
¶
Access service catalog operations.
Returns:
-
Services–Services instance for service CRUD operations.
Example
async with KatanaClient() as client: ... services = await client.services.list() ... service = await client.services.get(123)
variants
property
¶
Access variant catalog operations.
Returns:
-
Variants–Variants instance for variant CRUD operations.
Example
async with KatanaClient() as client: ... variants = await client.variants.list() ... variant = await client.variants.get(123)
Functions¶
PaginationTransport(wrapped_transport=None, max_pages=100, logger=None, **kwargs)
¶
Bases: AsyncHTTPTransport
Transport layer that adds automatic pagination for GET requests.
This transport wraps another transport and automatically collects all pages for GET requests by default.
Auto-pagination behavior:
- ON by default for all GET requests (will paginate if response has pagination info)
- Disabled when explicit page parameter is in URL (e.g., ?page=2)
- Disabled when request has extensions={"auto_pagination": False}
- Only applies to GET requests (POST, PUT, etc. are never paginated)
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} stops after 200 items
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 katana_public_api_client/katana_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
- An explicit page parameter is in the URL (e.g., ?page=2)
Source code in katana_public_api_client/katana_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 katana_public_api_client/katana_client.py
Functions¶
increment()
¶
Return a new retry instance with the attempt count incremented.
Source code in katana_public_api_client/katana_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 katana_public_api_client/katana_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 katana_public_api_client/katana_client.py
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 katana_public_api_client/katana_client.py
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 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 | |