supermetrics-python-sdk

Supermetrics Python SDK Documentation

Welcome to the official documentation for the Supermetrics Python SDK – the Python client for Supermetrics API.

What is the Supermetrics Python SDK?

The Supermetrics Python SDK is a type-safe Python client that provides seamless integration with the Supermetrics API. It features:

Quick Start

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"
)

Documentation Contents

Getting Started

Guides

Additional Resources

Key Features

Type Safety

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

Dual Sync/Async Support

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")

Comprehensive Error Handling

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

Resource-Based Organization

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(...)

Supported Data Sources

The SDK supports all Supermetrics data sources including:

See the User Guide for data source-specific examples.

Getting Help

License

This project is licensed under the Apache License v2. See the LICENSE file for details.