tree: 811f1b2478418df2d165f7c77352009e90e42037 [path history] [tgz]
  1. src/
  2. .gitignore
  3. CHANGELOG.md
  4. LICENSE.txt
  5. pyproject.toml
  6. README.md
superset-core/README.md

apache-superset-core

PyPI version License Python 3.10+

The official core package for building Apache Superset backend extensions and integrations. This package provides essential building blocks including base classes, API utilities, type definitions, and decorators for both the host application and extensions.

📦 Installation

pip install apache-superset-core

🏗️ Architecture

The package is organized into logical modules, each providing specific functionality:

  • api - REST API base classes, models access, query utilities, and registration
  • api.models - Access to Superset's database models (datasets, databases, etc.)
  • api.query - Database query utilities and SQL dialect handling
  • api.rest_api - Extension API registration and management
  • api.types.rest_api - REST API base classes and type definitions

🚀 Quick Start

Basic Extension Structure

from flask import request, Response
from flask_appbuilder.api import expose, permission_name, protect, safe
from superset_core.api import models, query, rest_api
from superset_core.api.types.rest_api import RestApi

class DatasetReferencesAPI(RestApi):
    """Example extension API demonstrating core functionality."""

    resource_name = "dataset_references"
    openapi_spec_tag = "Dataset references"
    class_permission_name = "dataset_references"

    @expose("/metadata", methods=("POST",))
    @protect()
    @safe
    @permission_name("read")
    def metadata(self) -> Response:
        """Get dataset metadata for tables referenced in SQL."""
        sql: str = request.json.get("sql")
        database_id: int = request.json.get("databaseId")

        # Access Superset's models using core APIs
        databases = models.get_databases(id=database_id)
        if not databases:
            return self.response_404()

        database = databases[0]
        dialect = query.get_sqlglot_dialect(database)

        # Access datasets to get owner information
        datasets = models.get_datasets()
        owners_map = {
            dataset.table_name: [
                f"{owner.first_name} {owner.last_name}"
                for owner in dataset.owners
            ]
            for dataset in datasets
        }

        # Process SQL and return dataset metadata
        return self.response(200, result=owners_map)

# Register the extension API
rest_api.add_extension_api(DatasetReferencesAPI)

🤝 Contributing

We welcome contributions! Please see the Contributing Guide for details.

📄 License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

🔗 Links


Note: This package is currently in release candidate status. APIs may change before the 1.0.0 release. Please check the changelog for breaking changes between versions.