Source code for limitry.client.resources.customers
"""Auto-generated operation classes.
This file is auto-generated by the operators generator.
Do not edit this file manually.
"""
from typing import TYPE_CHECKING, Any, Dict, List, Optional
from limitry.client.types import (
CustomerUsageResponse
)
from limitry.client.utils.pagination import PaginatedResponse
if TYPE_CHECKING:
from limitry.client.client import Client
[docs]
class Customers:
"""Operations for customers."""
[docs]
def __init__(self, client: "Client") -> None:
"""Initialize Customers operations.
Args:
client: The Limitry client instance
"""
self._client = client
[docs]
async def get_usage(
self,
customer_id: str,
start_date: str,
end_date: str
) -> CustomerUsageResponse:
"""Get customer usage.
Retrieve usage summary for a specific customer within a date range.
This endpoint provides aggregated metrics for a single customer, making it ideal for:
- Customer billing and invoicing
- Per-tenant usage dashboards
- Customer-specific analytics
- Usage-based pricing calculations.
Args:
customer_id: Customer identifier to get usage for (min length: 1)
start_date: Start of the date range (ISO 8601 format) (ISO 8601 format, e.g., "2024-01-01T00:00:00Z")
end_date: End of the date range (ISO 8601 format) (ISO 8601 format, e.g., "2024-01-01T00:00:00Z")
Returns:
CustomerUsageResponse: Customer usage summary
Example::
result = await client.customers.get_usage(
"customerid_123",
start_date="2024-01-01T00:00:00Z",
end_date="2024-01-01T00:00:00Z"
)
print(result)
Raises:
APIError: Invalid query parameters
AuthenticationError: Unauthorized - Invalid or missing API key
NetworkError: If a network error occurs"""
params = {
"startDate": start_date,
"endDate": end_date,
}
params = {k: v for k, v in params.items() if v is not None}
response = await self._client.request("GET", f"/customers/{customer_id}/usage", params=params)
return CustomerUsageResponse(**response)