Professional toolkit for Superset API automation - datasets, charts, and dashboards
Project description
๐ Superset Toolkit
Production-grade SDK for Apache Superset API automation with professional patterns.
โจ Key Features
- ๐ฏ Client-Centric Design: No more repetitive
(session, base_url)parameters - ๐ค Username-Aware Operations: Work with usernames directly, no manual ID resolution
- ๐ง JWT-Based Authentication: Robust user ID extraction from tokens (works for any user)
- ๐ Composite Workflows: Complete operations in single function calls
- ๐ฆ Batch Operations: Efficient bulk chart/dashboard management
- ๐งน Resource Lifecycle: Context managers with automatic cleanup
- ๐ก๏ธ Professional Error Handling: Graceful fallbacks and detailed logging
- ๐ Full Chart Support: Table, pie, histogram, area charts with username support
Installation
Basic Installation
pip install -e .
With CLI Support
pip install -e ".[cli]"
Development Installation
pip install -e ".[dev]"
๐ Quick Start
Professional Client-Centric Usage (Recommended)
from superset_toolkit import SupersetClient
from superset_toolkit.config import Config
# Configure connection
config = Config(
superset_url="https://your-superset-instance.com",
username="your-username",
password="your-secure-password",
schema="your-schema",
database_name="your-database"
)
# Context manager with automatic cleanup
with SupersetClient(config=config) as client:
# Create chart (all complexity hidden)
chart_id = client.create_table_chart(
name="Sales Report",
table="sales_data",
owner="analyst" # Just username - no ID resolution needed!
)
# Create dashboard with automatic chart linking
dashboard_id = client.create_dashboard(
title="Sales Dashboard",
slug="sales-dashboard",
owner="analyst",
charts=["Sales Report"] # Auto-links existing charts
)
# Query resources by owner
user_charts = client.get_charts(owner="analyst")
user_dashboards = client.get_dashboards(owner="analyst")
# Get comprehensive user summary
summary = client.get_user_summary("analyst")
print(f"User has: {summary['summary']}")
# Clean up everything for a user
client.cleanup_user("temp_user", dry_run=False)
Batch & Composite Operations
# Create dashboard with multiple charts in one operation
result = client.create_dashboard_with_charts(
dashboard_title="Analytics Dashboard",
slug="analytics-dash",
chart_configs=[
{"name": "Sales Chart", "table": "sales", "columns": ["region", "amount"]},
{"name": "Revenue Chart", "table": "revenue", "columns": ["month", "total"]}
],
owner="analytics_team"
)
# Create multiple charts efficiently
chart_ids = client.create_charts_batch([
{"name": "Chart 1", "table": "data1"},
{"name": "Chart 2", "table": "data2"},
{"name": "Chart 3", "table": "data3"}
], owner="data_team")
Enhanced Standalone Functions (For Advanced Use Cases)
from superset_toolkit.charts import create_table_chart
from superset_toolkit.queries import get_charts_by_username
client = SupersetClient()
# Enhanced standalone functions now support username parameter
chart_id = create_table_chart(
client.session, client.base_url,
"Advanced Chart", dataset_id,
username="data_analyst" # No manual user ID resolution!
)
# Direct function calls for specific operations
charts = get_charts_by_username(client.session, client.base_url, "data_analyst")
Environment Variables (Optional)
export SUPERSET_URL="https://your-superset-instance.com"
export SUPERSET_USERNAME="your-username"
export SUPERSET_PASSWORD="your-password"
export SUPERSET_SCHEMA="your_schema" # Optional, defaults to 'reports'
export SUPERSET_DATABASE_NAME="YourDatabase" # Optional, defaults to 'Trino'
Module Organization:
client.py: Enhanced SupersetClient with professional methodsauth.py: JWT-based authentication with permission-aware fallbackscharts.py: Username-aware chart creation (table, pie, histogram, area)dashboard.py: Dashboard creation with automatic chart linkingqueries.py: Resource filtering and querying by owner/datasetdatasets.py: Dataset management with permission handling
๐ Advanced Usage Examples
Multiple Chart Types with Username Support
with SupersetClient() as client:
# Table chart
table_chart = client.create_chart_from_table(
chart_name="Sales Data",
table="sales",
owner="analyst",
chart_type="table",
columns=["region", "amount", "date"]
)
# Pie chart
pie_chart = client.create_chart_from_table(
chart_name="Sales by Region",
table="sales",
owner="analyst",
chart_type="pie",
metric={"aggregate": "SUM", "column": {"column_name": "amount"}},
groupby=["region"]
)
# Histogram
hist_chart = client.create_chart_from_table(
chart_name="Amount Distribution",
table="sales",
owner="analyst",
chart_type="histogram",
all_columns_x=["amount"],
bins=10
)
Resource Management & Migration
with SupersetClient() as client:
# Get comprehensive user summary
summary = client.get_user_summary("data_analyst")
print(f"User has: {summary['summary']}")
# Migrate resources between users
result = client.migrate_user_resources(
from_user="old_analyst",
to_user="new_analyst",
dry_run=False
)
# Clean up user resources
cleanup = client.cleanup_user("temp_user", dry_run=False)
print(f"Deleted: {len(cleanup['chart_ids'])} charts, {len(cleanup['dashboard_ids'])} dashboards")
Dataset Ownership Management
from superset_toolkit import SupersetClient
from superset_toolkit.datasets import add_dataset_owner, refresh_dataset_metadata
from superset_toolkit.ensure import get_dataset_id
# Login as admin (with privileges to modify ownership)
client = SupersetClient()
# Get dataset ID
dataset_id = get_dataset_id(client.session, client.base_url, "sales_data", "public")
# Refresh dataset metadata (update columns from database)
refresh_dataset_metadata(client.session, client.base_url, dataset_id)
# Add an owner to the dataset without removing existing owners
# Admin logs in, but adds other users as owners for collaboration
add_dataset_owner(
client.session,
client.base_url,
dataset_id,
username="data_analyst" # Add this user as owner
)
# Add multiple owners
for username in ["analyst1", "analyst2", "analyst3"]:
add_dataset_owner(client.session, client.base_url, dataset_id, username)
Key Features:
- โ Preserves existing owners - doesn't remove anyone
- โ Admin authentication - login as admin, add others as owners
- โ Idempotent - won't duplicate if user is already an owner
- โ Collaboration-friendly - enable team access to datasets
๐ง Installation & Setup
# Install the toolkit
pip install -e .
# Optional: Install with CLI support
pip install -e ".[cli]"
๐ฏ Why Choose This SDK?
Before (Traditional Approach):
# Manual user ID resolution, parameter repetition, fragmented operations
user_id = get_user_id_by_username(session, base_url, "john")
dataset_id = ensure_dataset(session, base_url, db_id, schema, table)
chart_id = create_table_chart(session, base_url, name, dataset_id, user_id)
dashboard_id = ensure_dashboard(session, base_url, title, slug)
link_chart_to_dashboard(session, base_url, chart_id, dashboard_id)
After (Professional SDK):
# Clean, username-first, composite operations
with SupersetClient() as client:
chart_id = client.create_table_chart("Report", table="sales", owner="analyst")
dashboard_id = client.create_dashboard("Dashboard", "dashboard", charts=["Report"])
๐ Documentation
- ๐ Full Documentation - Comprehensive guides and API reference
- ๐ฏ Examples - Ready-to-run examples for common patterns
- ๐ง Configuration Guide - Setup and customization
- ๐ค User Management - Username-aware operations
๐ฏ Supported Chart Types
| Chart Type | Client Method | Standalone Function | Username Support |
|---|---|---|---|
| Table | client.create_table_chart() |
create_table_chart() |
โ |
| Pie | client.create_chart_from_table(type="pie") |
create_pie_chart() |
โ |
| Histogram | client.create_chart_from_table(type="histogram") |
create_histogram_chart() |
โ |
| Area | client.create_chart_from_table(type="area") |
create_area_chart() |
โ |
| Pivot | Available via standalone function | create_pivot_table_chart() |
โ |
๐ก๏ธ Error Handling & Permissions
The SDK gracefully handles permission restrictions:
- JWT Token Extraction: Gets user ID without requiring admin permissions
- 403 Fallback Logic: Smart fallbacks for non-admin users
- Professional Exceptions: Clear error messages with context
# Robust error handling
try:
chart_id = client.create_table_chart("Report", table="sales", owner="user")
except AuthenticationError as e:
print(f"Auth issue: {e}")
except SupersetToolkitError as e:
print(f"Operation failed: {e}")
๐ Project Structure
superset_toolkit/
โโโ ๐ docs/ # Comprehensive documentation
โโโ ๐ฏ examples/ # Ready-to-run examples
โโโ ๐ง src/superset_toolkit/
โ โโโ client.py # Professional SupersetClient class
โ โโโ auth.py # JWT + permission-aware authentication
โ โโโ charts.py # Username-aware chart creation
โ โโโ dashboard.py # Dashboard management
โ โโโ queries.py # Resource filtering and queries
โ โโโ utils/ # Utilities (metrics, etc.)
โโโ ๐งช src/superset-api-test/ # Test scripts
๐ Getting Started
- Install:
pip install -e . - Configure: Set up credentials (Config class or env vars)
- Explore: Check
examples/for common patterns - Read Docs: Review
docs/for comprehensive guides
๐ License & Contributing
MIT License - Open source project for the Superset community.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file superset_toolkit-0.2.2.tar.gz.
File metadata
- Download URL: superset_toolkit-0.2.2.tar.gz
- Upload date:
- Size: 33.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed362c65867e90651d636913a2ea48532202d5583a4de22bccfd3aad3ff64bb1
|
|
| MD5 |
2d7f79101b34a38e933e146772aab702
|
|
| BLAKE2b-256 |
a792fe3e454dd89c6bfcb3277bad6219e6f927dce8c9a8387208619851b0c8f6
|
Provenance
The following attestation bundles were made for superset_toolkit-0.2.2.tar.gz:
Publisher:
publish-to-pypi.yml on daviddallakyan2005/superset-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
superset_toolkit-0.2.2.tar.gz -
Subject digest:
ed362c65867e90651d636913a2ea48532202d5583a4de22bccfd3aad3ff64bb1 - Sigstore transparency entry: 627799427
- Sigstore integration time:
-
Permalink:
daviddallakyan2005/superset-toolkit@7d09d30782d22484d5f5f07c136d0be800c5f3ef -
Branch / Tag:
refs/heads/master - Owner: https://github.com/daviddallakyan2005
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@7d09d30782d22484d5f5f07c136d0be800c5f3ef -
Trigger Event:
push
-
Statement type:
File details
Details for the file superset_toolkit-0.2.2-py3-none-any.whl.
File metadata
- Download URL: superset_toolkit-0.2.2-py3-none-any.whl
- Upload date:
- Size: 33.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e91f796acc9c564d0ea9bdd06e80f7f54596251d6abf0f4ad795a1e94987e1f
|
|
| MD5 |
c004e50f03a573a49ed9522cba082f39
|
|
| BLAKE2b-256 |
03869a0cfd88e38d670d956ce4500a2841ebe26c21bbdb3a0aba2a0f9cee04af
|
Provenance
The following attestation bundles were made for superset_toolkit-0.2.2-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on daviddallakyan2005/superset-toolkit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
superset_toolkit-0.2.2-py3-none-any.whl -
Subject digest:
4e91f796acc9c564d0ea9bdd06e80f7f54596251d6abf0f4ad795a1e94987e1f - Sigstore transparency entry: 627799447
- Sigstore integration time:
-
Permalink:
daviddallakyan2005/superset-toolkit@7d09d30782d22484d5f5f07c136d0be800c5f3ef -
Branch / Tag:
refs/heads/master - Owner: https://github.com/daviddallakyan2005
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@7d09d30782d22484d5f5f07c136d0be800c5f3ef -
Trigger Event:
push
-
Statement type: