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

๐Ÿ”ง 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.1.tar.gz (31.7 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.1-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file superset_toolkit-0.2.1.tar.gz.

File metadata

  • Download URL: superset_toolkit-0.2.1.tar.gz
  • Upload date:
  • Size: 31.7 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.1.tar.gz
Algorithm Hash digest
SHA256 92cae8ef901ccd83cfa644af5922c1da4076d8a7c65cdbb6ff127762c9d4f25f
MD5 5afb9683279ced8782503595b0d2088c
BLAKE2b-256 f53a4a9394906cdb2ca32c6d3ab3eae1ba4db68525d51774d0469c1241a22bcd

See more details on using hashes here.

Provenance

The following attestation bundles were made for superset_toolkit-0.2.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for superset_toolkit-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1781f3444143117f2b30667b4afeb45e379d9efbbde6d8fa60fe7384b99f9a0a
MD5 39e6d803f4b44cae08011ef7a5b8d819
BLAKE2b-256 5d066e04c7a22b98ec779bcdc59b54935bad0e192547ac2eb0bdf8573a0ad3f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for superset_toolkit-0.2.1-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