Auth Module¶
The auth module provides credential management and configuration.
Explore on DeepWiki
Ask questions about credential management, ConfigManager, or account configuration.
Overview¶
from mixpanel_data.auth import ConfigManager, Credentials, AccountInfo
# Manage accounts
config = ConfigManager()
config.add_account("production", username="...", secret="...", project_id="...", region="us")
accounts = config.list_accounts()
# Resolve credentials
creds = config.resolve_credentials(account="production")
ConfigManager¶
Manages accounts stored in the TOML config file (~/.mp/config.toml).
mixpanel_data.auth.ConfigManager
¶
Manages Mixpanel project credentials and configuration.
Handles: - Adding, removing, and listing project accounts - Setting the default account - Resolving credentials from environment variables or config file
Config file location (in priority order): 1. Explicit config_path parameter 2. MP_CONFIG_PATH environment variable 3. Default: ~/.mp/config.toml
Initialize ConfigManager.
| PARAMETER | DESCRIPTION |
|---|---|
config_path
|
Override config file location. Default: ~/.mp/config.toml
TYPE:
|
Source code in src/mixpanel_data/_internal/config.py
resolve_credentials
¶
Resolve credentials using priority order.
Resolution order: 1. Environment variables (MP_USERNAME, MP_SECRET, MP_PROJECT_ID, MP_REGION) 2. Named account from config file (if account parameter provided) 3. Default account from config file
| PARAMETER | DESCRIPTION |
|---|---|
account
|
Optional account name to use instead of default.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Credentials
|
Immutable Credentials object. |
| RAISES | DESCRIPTION |
|---|---|
ConfigError
|
If no credentials can be resolved. |
AccountNotFoundError
|
If named account doesn't exist. |
Source code in src/mixpanel_data/_internal/config.py
list_accounts
¶
List all configured accounts.
| RETURNS | DESCRIPTION |
|---|---|
list[AccountInfo]
|
List of AccountInfo objects (secrets not included). |
Source code in src/mixpanel_data/_internal/config.py
add_account
¶
Add a new account configuration.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Display name for the account.
TYPE:
|
username
|
Service account username.
TYPE:
|
secret
|
Service account secret.
TYPE:
|
project_id
|
Mixpanel project ID.
TYPE:
|
region
|
Data residency region (us, eu, in).
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
AccountExistsError
|
If account name already exists. |
ValueError
|
If region is invalid. |
Source code in src/mixpanel_data/_internal/config.py
remove_account
¶
Remove an account configuration.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Account name to remove.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
AccountNotFoundError
|
If account doesn't exist. |
Source code in src/mixpanel_data/_internal/config.py
set_default
¶
Set the default account.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Account name to set as default.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
AccountNotFoundError
|
If account doesn't exist. |
Source code in src/mixpanel_data/_internal/config.py
get_account
¶
Get information about a specific account.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Account name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AccountInfo
|
AccountInfo object (secret not included). |
| RAISES | DESCRIPTION |
|---|---|
AccountNotFoundError
|
If account doesn't exist. |
Source code in src/mixpanel_data/_internal/config.py
Credentials¶
Immutable container for authentication credentials.
mixpanel_data.auth.Credentials
¶
Bases: BaseModel
Immutable credentials for Mixpanel API authentication.
This is a frozen Pydantic model that ensures: - All fields are validated on construction - The secret is never exposed in repr/str output - The object cannot be modified after creation
validate_region
classmethod
¶
Validate and normalize region to lowercase.
Source code in src/mixpanel_data/_internal/config.py
validate_non_empty
classmethod
¶
Validate string fields are non-empty.
__repr__
¶
Return string representation with redacted secret.
AccountInfo¶
Account metadata (without the secret).
mixpanel_data.auth.AccountInfo
dataclass
¶
Information about a configured account (without secret).
Used for listing accounts without exposing sensitive credentials.