SDKs overview
Apache Superset, an open-source data exploration and visualization platform, is primarily built on Python and Flask. Consequently, its core SDK capabilities are deeply integrated with the Python ecosystem. While there isn't a single, monolithic SDK package that encapsulates all of Superset's functionalities for external consumption, developers interact with Superset programmatically through its Python backend, its REST API, and various community-driven libraries that extend its reach into other programming environments or specific use cases.
The architecture of Superset allows for extensive customization and integration. Its Pythonic backend facilitates direct script-based management of datasets, charts, and dashboards. The official documentation provides guidelines for interacting with Superset's components, including its database connection layer, visualization plugins, and security features. For developers looking to embed Superset's capabilities or automate its operations, understanding its internal Python modules and exposed APIs is key to leveraging its full potential.
The platform's design emphasizes extensibility, enabling developers to contribute custom visualization plugins, authentication methods, and database connectors. This plugin architecture, detailed in the Apache Superset documentation, serves as an indirect form of SDK, allowing developers to extend the core product's features using Python and JavaScript.
Official SDKs by language
Apache Superset's official SDK support is predominantly focused on Python, reflecting its backend implementation. The project does not offer distinct, language-specific SDKs for client-side interactions in languages like Java, Node.js, or Go. Instead, interaction from other languages is typically handled via Superset's REST API. The core Python packages provide the programmatic interfaces for managing Superset instances, defining data sources, creating charts, and orchestrating dashboards.
The primary 'SDK' for Apache Superset is effectively the Superset Python package itself, along with its dependencies. This package allows for:
- Programmatic Configuration: Setting up database connections, security roles, and user management.
- Data Source Management: Defining datasets, metrics, and dimensions directly from Python scripts.
- Dashboard and Chart Creation: Automating the generation and organization of visualizations.
- Extensibility: Developing custom plugins and integrations within the Superset framework.
The following table outlines the key Python packages that constitute the primary official means of programmatic interaction with Apache Superset:
| Language | Package | Description | Maturity |
|---|---|---|---|
| Python | apache-superset |
The core Superset application, offering programmatic access to its backend APIs and components for administration and content management. | Stable |
| Python | superset-ui |
Frontend visualization components and utilities for building custom charts within Superset. Primarily JavaScript, but Python tooling interacts with it. | Stable |
| Python | superset-frontend |
The React-based frontend application for Superset, enabling UI customization and embedding. Primarily JavaScript/TypeScript, with Python for backend integration. | Stable |
Installation
Installing Apache Superset and its associated Python packages typically involves using pip, the Python package installer. Before installing Superset, it is recommended to set up a Python virtual environment to manage dependencies locally and avoid conflicts with system-wide packages. The core installation process includes installing the apache-superset package and then initializing the database, creating an admin user, and loading example data.
A typical installation sequence involves these steps:
- Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate - Install Apache Superset:
pip install apache-supersetFor additional database drivers, specific packages must be installed. For example, to connect to PostgreSQL, you would install
psycopg2-binary:pip install apache-superset[postgresql]A full list of database connection options and their respective installation commands is available in the Superset installation guide.
- Initialize the database:
superset db upgrade - Create an admin user:
superset fab create-adminFollow the prompts to set username, email, and password.
- Load example data (optional):
superset load_examples - Initialize Superset:
superset init - Start the development web server:
superset run -p 8088 --with-threads --reload --debugger
This sequence sets up a basic Superset instance accessible via a web browser, allowing developers to explore its features and begin programmatic interactions through its Python environment or REST API.
Quickstart example
This quickstart example demonstrates how to programmatically connect to a database, create a dataset, and generate a simple chart using Apache Superset's Python capabilities. This requires a running Superset instance and an understanding of its internal API, which is primarily accessed by importing Superset's Python modules.
First, ensure your Python environment has sqlalchemy and the appropriate database driver installed (e.g., psycopg2-binary for PostgreSQL). This example assumes a PostgreSQL database named my_database exists and is accessible. The code below illustrates creating a database connection and a dataset from a CSV file (or a similar data source) within Superset.
from superset.models.core import Database
from superset.models.slice import Slice
from superset.models.dashboard import Dashboard
from superset import db
# Assuming Superset is running and configured to connect to a database
# This example demonstrates creating a database entry and a simple chart
# 1. Define a new database connection
db_name = "My Postgres Database"
db_uri = "postgresql+psycopg2://user:password@host:port/my_database"
# Check if database already exists to prevent duplicates
existing_db = db.session.query(Database).filter_by(database_name=db_name).first()
if not existing_db:
new_db = Database(
database_name=db_name,
sqlalchemy_uri=db_uri,
expose_in_sqllab=True,
allow_run_async=True,
)
db.session.add(new_db)
db.session.commit()
print(f"Database '{db_name}' added successfully.")
database = new_db
else:
print(f"Database '{db_name}' already exists.")
database = existing_db
# 2. Programmatically create a dataset (table metadata)
# This part often involves more complex interactions with `Table` and `SqlaTable` models.
# For simplicity, we assume a table 'sales_data' exists in 'my_database'.
# In a real scenario, you'd use `superset.models.SqlaTable` to define columns, metrics, etc.
# This requires a more intricate setup, often through the Superset UI or more advanced scripting.
# Example of creating a placeholder slice (chart) for demonstration
# A real chart requires specific visualization types and dataset IDs.
slice_name = "Sales Over Time"
existing_slice = db.session.query(Slice).filter_by(slice_name=slice_name).first()
if not existing_slice:
new_slice = Slice(
slice_name=slice_name,
viz_type="line", # Example visualization type
datasource_type="table",
datasource_id=None, # Replace with actual datasource ID later
params='{"x_axis_label": "Date", "y_axis_label": "Sales", "metric": "sum__sales"}' # Example params
)
# In a full setup, you'd associate this slice with a specific SqlaTable datasource
# new_slice.datasource = some_sqla_table_instance
db.session.add(new_slice)
db.session.commit()
print(f"Chart '{slice_name}' created successfully.")
else:
print(f"Chart '{slice_name}' already exists.")
print("Superset programmatic interaction example complete.")
This example primarily showcases interaction with Superset's SQLAlchemy models. For comprehensive automation, including dashboard creation and complex chart configurations, developers typically need to understand the structure of the Slice and Dashboard models and their associated JSON parameters, which define the visualization properties. More detailed programmatic control often involves using the Superset REST API for creating and managing assets, providing a language-agnostic way to interact with the platform.
Community libraries
The Apache Superset community has developed various libraries and tools to extend its functionality, integrate with other systems, or provide alternative programmatic interfaces. While not officially supported by the Apache Software Foundation, these contributions can be valuable for specific use cases.
-
Superset API Clients: Several community-driven efforts exist to create client libraries for Superset's REST API in different programming languages. These often aim to simplify authentication and request handling compared to making raw HTTP requests. For instance, there might be unofficial Python wrappers or JavaScript clients that abstract the API calls for easier integration into broader applications. Developers should search public repositories like GitHub for
superset api client pythonor similar queries to find these. - Embedding Libraries: For embedding Superset dashboards into other applications, the community sometimes provides helper libraries or frameworks. While Superset offers official embedding options, community tools might streamline the process for specific frontend frameworks (e.g., React, Vue) or provide additional customization layers. The Superset embedding documentation outlines the official methods, but community projects might offer supplementary utilities.
- Data Source Connectors: Beyond the officially supported database drivers, community members occasionally develop or maintain connectors for less common data sources or proprietary systems. These connectors typically extend Superset's SQLAlchemy-based data access layer, allowing it to query new types of databases or APIs.
- CI/CD and Automation Tools: Tools that help automate the deployment, configuration, and content migration of Superset instances are also present in the community. These might include Ansible playbooks, Docker Compose configurations, or custom Python scripts designed for managing Superset in a CI/CD pipeline. For example, some users leverage tools like Terraform for infrastructure as code to deploy and manage Superset instances on cloud platforms, though these are general DevOps tools, not Superset-specific libraries.
When using community libraries, it is important to verify their maintenance status, compatibility with the current Superset version, and security practices, as they do not undergo the same rigorous review as official Apache projects. Consulting the Apache Superset GitHub repository and community forums is a good starting point for discovering and evaluating these contributions.
These community efforts underscore Superset's flexibility and the active engagement of its user base in extending the platform's capabilities beyond its core offerings.