SDK

High-level SDK for integrating Limitry usage tracking.

Limitry SDK

High-level SDK for integrating Limitry usage tracking and rate limiting.

class limitry.sdk.Client[source]

Bases: object

Main client for interacting with the Limitry API

__init__(api_key, base_url=None, timeout=None, headers=None)[source]

Initialize the Limitry client.

Parameters:

Example:

client = Client(api_key="your-api-key")
async __aenter__()[source]

Async context manager entry

async __aexit__(exc_type, exc_val, exc_tb)[source]

Async context manager exit

async close()[source]

Close the HTTP client

async request(method, path, params=None, json=None, headers=None)[source]

Make an HTTP request to the API.

Parameters:
Return type:

Any

Returns:

Response data (parsed JSON)

Raises:
class limitry.sdk.ClientConfig[source]

Bases: object

Configuration for the Limitry SDK client

__init__(api_key, base_url=None, timeout=None, headers=None)[source]

Initialize client configuration.

Parameters:
exception limitry.sdk.LimitryError[source]

Bases: Exception

Base exception for all Limitry SDK errors

__init__(message, cause=None)[source]
Parameters:
exception limitry.sdk.APIError[source]

Bases: LimitryError

Exception raised when an API request fails

__init__(message, status, status_text, response=None)[source]
Parameters:
exception limitry.sdk.AuthenticationError[source]

Bases: APIError

Exception raised when authentication fails (401/403)

__init__(message='Authentication failed. Please check your API key.', status=401, response=None)[source]
Parameters:
exception limitry.sdk.NetworkError[source]

Bases: LimitryError

Exception raised when a network error occurs

__init__(message, cause=None)[source]
Parameters:
class limitry.sdk.PaginatedResponse[source]

Bases: Generic[T]

Response from a paginated API endpoint

__init__(data, next_cursor=None, has_more=False)[source]

Initialize a paginated response.

Parameters:
  • data (list[TypeVar(T)]) – List of items in this page

  • next_cursor (Optional[str]) – Cursor for the next page (if available)

  • has_more (bool) – Whether there are more pages available

async limitry.sdk.paginate_all(fetch_page, initial_cursor=None)[source]

Iterator helper for auto-pagination.

Automatically fetches all pages using cursor-based pagination.

Parameters:
Yields:

Individual items from all pages

Return type:

AsyncGenerator[TypeVar(T), None]

Example:

async def fetch_events(cursor: Optional[str] = None):
    response = await client.request("GET", "/events", params={"cursor": cursor})
    return PaginatedResponse(
        data=response["data"],
        next_cursor=response.get("nextCursor"),
        has_more=response.get("hasMore", False),
    )

async for event in paginate_all(fetch_events):
    print(event.id)
async limitry.sdk.collect_all(fetch_page, initial_cursor=None)[source]

Collect all items from paginated endpoint into a list.

Parameters:
Return type:

list[TypeVar(T)]

Returns:

List of all items from all pages

Example:

async def fetch_events(cursor: Optional[str] = None):
    response = await client.request("GET", "/events", params={"cursor": cursor})
    return PaginatedResponse(
        data=response["data"],
        next_cursor=response.get("nextCursor"),
        has_more=response.get("hasMore", False),
    )

all_events = await collect_all(fetch_events)