Welcome to the official documentation for the Supermetrics Python SDK – the Python client for Supermetrics API.
The Supermetrics Python SDK is a type-safe Python client that provides seamless integration with the Supermetrics API. It features:
from supermetrics import SupermetricsClient
# Initialize client
client = SupermetricsClient(api_key="your_api_key")
# Create login link
link = client.login_links.create(ds_id="GAWA", description="My Connection")
# Get login details
login = client.logins.get(login_id=link.login_id)
# List accounts
accounts = client.accounts.list(ds_id="GAWA", login_usernames=login.username)
# Execute query
result = client.queries.execute(
ds_id="GAWA",
ds_accounts=[accounts[0].account_id],
fields=["Date", "Sessions", "Users"],
start_date="2024-01-01",
end_date="2024-01-31"
)
All request and response models are fully typed using Pydantic v2:
link = client.login_links.create(ds_id="GAWA")
# link is typed as LoginLink with full IDE autocomplete
print(link.login_url) # Type-safe access
Choose the right client for your use case:
# Synchronous - for scripts and notebooks
from supermetrics import SupermetricsClient
client = SupermetricsClient(api_key="key")
accounts = client.accounts.list(ds_id="GAWA")
# Asynchronous - for production apps
from supermetrics import SupermetricsAsyncClient
async with SupermetricsAsyncClient(api_key="key") as client:
accounts = await client.accounts.list(ds_id="GAWA")
Specific exceptions for different error types:
from supermetrics import (
AuthenticationError,
ValidationError,
APIError,
NetworkError
)
try:
result = client.queries.execute(...)
except AuthenticationError:
# Handle auth errors
except ValidationError:
# Handle validation errors
except APIError as e:
# Handle API errors with status code
if e.status_code == 429:
# Handle rate limiting
Clean, intuitive API organized by resource type:
client.login_links.create(...)
client.login_links.get(...)
client.login_links.list()
client.login_links.close(...)
client.logins.get(...)
client.logins.list()
client.logins.get_by_username(...)
client.accounts.list(...)
client.queries.execute(...)
client.queries.get_results(...)
The SDK supports all Supermetrics data sources including:
See the User Guide for data source-specific examples.
This project is licensed under the Apache License v2. See the LICENSE file for details.