etlplus.api
etlplus.api package.
High-level helpers for building REST API clients with pagination, retry, rate limiting, and transport configuration.
Summary
Use etlplus.api.EndpointClient to register relative endpoint paths
under a base URL and paginate responses. The client can apply rate limits
between requests and perform exponential-backoff retries with full jitter.
Examples
Page-based pagination
>>> from etlplus.api import EndpointClient
>>> client = EndpointClient(
... base_url="https://api.example.com/v1",
... endpoints={"list_users": "/users"},
... )
>>> page_cfg = {
... "type": "page", # or "offset"
... "records_path": "data.items", # dotted path into payload
... "page_param": "page",
... "size_param": "per_page",
... "start_page": 1,
... "page_size": 100,
... }
>>> rows = client.paginate(
... "list_users",
... query_parameters={"active": "true"},
... pagination=page_cfg,
... )
Retries and network errors
>>> client = EndpointClient(
... base_url="https://api.example.com/v1",
... endpoints={"list": "/items"},
... retry={"max_attempts": 5, "backoff": 0.5, "retry_on": [429, 503]},
... retry_network_errors=True,
... )
>>> items = client.paginate(
... "list", pagination={"type": "page", "page_size": 50}
... )
Absolute URLs
Use EndpointClient.paginate_url() for an already composed absolute URL.
It accepts the same pagination config and returns either the raw JSON object
(no pagination) or a list of record dicts aggregated across pages.
Notes
EndpointClient.endpointsis read-only at runtime.- Pagination defaults are centralized on the client (
page,per_page, cursor,limit; start page1; page size100).
- Pagination defaults are centralized on the client (
Retries are opt-in via the
retryparameter; backoff uses jitter.Use
retry_network_errors=Trueto also retry timeouts/connection errors.- Prefer
JSONRecords(list ofJSONDict) for paginated responses; scalar/record aliases are exported for convenience.
- Prefer
- The underlying
Paginatoris exported for advanced scenarios that need to stream pages manually.
- The underlying
See also
-mod:etlplus.api.pagination for pagination helpers and config shapes
-mod:etlplus.api.rate_limiting for rate-limit helpers and config shapes
-mod:etlplus.api._errors for API error exceptions
-mod:etlplus.api._retry_manager for retry policies
-mod:etlplus.api._transport for HTTPAdapter helpers
-, error, and
Functions
|
Build a requests |
|
Mount adapters described by adapters_cfg onto a new session. |
|
Compose the API request environment. |
|
Compose the API target environment. |
|
Paginate using the given client. |
|
Resolve a request callable and effective timeout for an HTTP method. |
Classes
|
Immutable registry of endpoint path templates rooted at a base URL. |
|
Bearer token authentication via the OAuth2 Client Credentials flow. |
|
Centralized retry logic for HTTP requests. |
|
Configuration for a REST API service. |
|
Profile configuration for a REST API service. |
|
Configuration for a single API endpoint. |
|
Immutable snapshot of per-request options. |
|
Normalized retry settings derived from a |
|
Supported HTTP verbs with a helper for request-body allowance. |
|
Top-level API config shape for |
|
Shape accepted for one API profile entry. |
|
Defaults block available under a profile (all keys optional). |
|
Shape accepted by |
|
Configuration mapping for mounting an |
|
Retry configuration for urllib3 |
|
Optional retry policy for HTTP requests. |
Exceptions
|
Authentication/authorization failure (e.g., 401/403). |
|
Base error for API request failures with rich context. |
|
Error raised during pagination with page context. |