Skip to main content

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 methods
  • auth.py: JWT-based authentication with permission-aware fallbacks
  • charts.py: Username-aware chart creation (table, pie, histogram, area)
  • dashboard.py: Dashboard creation with automatic chart linking
  • queries.py: Resource filtering and querying by owner/dataset
  • datasets.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

๐ŸŽฏ 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

  1. Install: pip install -e .
  2. Configure: Set up credentials (Config class or env vars)
  3. Explore: Check examples/ for common patterns
  4. Read Docs: Review docs/ for comprehensive guides

๐Ÿ“ License & Contributing

MIT License - Open source project for the Superset community.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

superset_toolkit-0.2.2.tar.gz (33.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

superset_toolkit-0.2.2-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

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

Hashes for superset_toolkit-0.2.2.tar.gz
Algorithm Hash digest
SHA256 ed362c65867e90651d636913a2ea48532202d5583a4de22bccfd3aad3ff64bb1
MD5 2d7f79101b34a38e933e146772aab702
BLAKE2b-256 a792fe3e454dd89c6bfcb3277bad6219e6f927dce8c9a8387208619851b0c8f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for superset_toolkit-0.2.2.tar.gz:

Publisher: publish-to-pypi.yml on daviddallakyan2005/superset-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file superset_toolkit-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for superset_toolkit-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4e91f796acc9c564d0ea9bdd06e80f7f54596251d6abf0f4ad795a1e94987e1f
MD5 c004e50f03a573a49ed9522cba082f39
BLAKE2b-256 03869a0cfd88e38d670d956ce4500a2841ebe26c21bbdb3a0aba2a0f9cee04af

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page