Skip to content

hopsworks.core.superset_api #

SupersetApi #

API for managing Superset datasets, charts, and dashboards.

This class provides methods to create, read, update, and delete Superset resources directly from within Hopsworks. Authentication is handled automatically using the project user's Superset credentials stored in Hopsworks secrets.

Example
import hopsworks
import json

project = hopsworks.login()
superset = project.get_superset_api()

# 1. List existing datasets in Superset
datasets = superset.list_datasets()

# 2. Create a dataset backed by an existing database table
dataset = superset.create_dataset(
    database_id=1,                       # ID of the Superset database connection
    table_name="transactions_1",         # table in the online feature store
    schema="myproject_onlinedb",         # schema (project's online DB name)
)
dataset_id = dataset["id"]

# 3. Create a chart that visualises the dataset
chart = superset.create_chart(
    slice_name="Transactions over time",
    viz_type="echarts_timeseries_line",  # Superset viz type
    datasource_id=dataset_id,
    params=json.dumps({                  # chart config as a JSON string
        "metrics": [{"label": "count", "expressionType": "SQL", "sqlExpression": "COUNT(*)"}],
        "groupby": [],
        "time_column": "event_time",
        "time_grain_sqla": "P1D",
        "row_limit": 1000,
    }),
)
chart_id = chart["id"]

# 4. Create a dashboard and add the chart to it
dashboard = superset.create_dashboard(
    dashboard_title="Feature Monitoring",
    published=True,
)
dashboard_id = dashboard["id"]

# Add the chart to the dashboard by updating the chart
superset.update_chart(chart_id, dashboards=[dashboard_id])

# 5. Clean up
superset.delete_chart(chart_id)
superset.delete_dataset(dataset_id)
superset.delete_dashboard(dashboard_id)

list_databases #

list_databases() -> dict

List all Superset database connections visible to the current user.

RETURNS DESCRIPTION
dict

A dict containing the list of databases under the "result" key.

create_dataset #

create_dataset(
    database_id: int,
    table_name: str,
    schema: str | None = None,
    sql: str | None = None,
    description: str | None = None,
    owners: list[int] | None = None,
) -> dict

Create a Superset dataset.

PARAMETER DESCRIPTION
database_id

ID of the Superset database connection.

TYPE: int

table_name

Name of the table (or virtual dataset).

TYPE: str

schema

Database schema name.

TYPE: str | None DEFAULT: None

sql

SQL expression for virtual datasets.

TYPE: str | None DEFAULT: None

description

Optional description.

TYPE: str | None DEFAULT: None

owners

Optional list of Superset user IDs as owners.

TYPE: list[int] | None DEFAULT: None

RETURNS DESCRIPTION
dict

The created dataset as a dict (Superset API response).

get_dataset #

get_dataset(dataset_id: int) -> dict

Get a Superset dataset by ID.

PARAMETER DESCRIPTION
dataset_id

The dataset ID.

TYPE: int

RETURNS DESCRIPTION
dict

The dataset as a dict.

list_datasets #

list_datasets() -> dict

List all Superset datasets visible to the current user.

RETURNS DESCRIPTION
dict

A dict containing the list of datasets under the "result" key.

update_dataset #

update_dataset(dataset_id: int, **kwargs: Any) -> dict

Update a Superset dataset.

Pass fields to update as keyword arguments (e.g., description, sql, table_name, owners).

PARAMETER DESCRIPTION
dataset_id

The dataset ID.

TYPE: int

RETURNS DESCRIPTION
dict

The updated dataset as a dict.

delete_dataset #

delete_dataset(dataset_id: int) -> dict

Delete a Superset dataset.

PARAMETER DESCRIPTION
dataset_id

The dataset ID.

TYPE: int

RETURNS DESCRIPTION
dict

Empty dict on success.

create_chart #

create_chart(
    slice_name: str,
    viz_type: str,
    datasource_id: int,
    params: str,
    datasource_type: str = "table",
    description: str | None = None,
    dashboards: list[int] | None = None,
    owners: list[int] | None = None,
) -> dict

Create a Superset chart.

PARAMETER DESCRIPTION
slice_name

Display name of the chart.

TYPE: str

viz_type

Visualization type (e.g., "table", "big_number", "echarts_timeseries").

TYPE: str

datasource_id

ID of the dataset to use as data source.

TYPE: int

params

JSON string of chart configuration parameters.

TYPE: str

datasource_type

Type of datasource (default "table").

TYPE: str DEFAULT: 'table'

description

Optional description.

TYPE: str | None DEFAULT: None

dashboards

Optional list of dashboard IDs to add this chart to.

TYPE: list[int] | None DEFAULT: None

owners

Optional list of Superset user IDs as owners.

TYPE: list[int] | None DEFAULT: None

RETURNS DESCRIPTION
dict

The created chart as a dict.

get_chart #

get_chart(chart_id: int) -> dict

Get a Superset chart by ID.

PARAMETER DESCRIPTION
chart_id

The chart ID.

TYPE: int

RETURNS DESCRIPTION
dict

The chart as a dict.

list_charts #

list_charts() -> dict

List all Superset charts visible to the current user.

RETURNS DESCRIPTION
dict

A dict containing the list of charts under the "result" key.

update_chart #

update_chart(chart_id: int, **kwargs: Any) -> dict

Update a Superset chart.

Pass fields to update as keyword arguments (e.g., slice_name, viz_type, params, owners).

PARAMETER DESCRIPTION
chart_id

The chart ID.

TYPE: int

RETURNS DESCRIPTION
dict

The updated chart as a dict.

delete_chart #

delete_chart(chart_id: int) -> dict

Delete a Superset chart.

PARAMETER DESCRIPTION
chart_id

The chart ID.

TYPE: int

RETURNS DESCRIPTION
dict

Empty dict on success.

create_dashboard #

create_dashboard(
    dashboard_title: str,
    published: bool = False,
    slug: str | None = None,
    position_json: str | None = None,
    json_metadata: str | None = None,
    css: str | None = None,
    owners: list[int] | None = None,
) -> dict

Create a Superset dashboard.

PARAMETER DESCRIPTION
dashboard_title

Display title of the dashboard.

TYPE: str

published

Whether the dashboard is published.

TYPE: bool DEFAULT: False

slug

Optional URL slug.

TYPE: str | None DEFAULT: None

position_json

Optional JSON string defining the layout.

TYPE: str | None DEFAULT: None

json_metadata

Optional JSON string with dashboard metadata.

TYPE: str | None DEFAULT: None

css

Optional custom CSS.

TYPE: str | None DEFAULT: None

owners

Optional list of Superset user IDs as owners.

TYPE: list[int] | None DEFAULT: None

RETURNS DESCRIPTION
dict

The created dashboard as a dict.

get_dashboard #

get_dashboard(dashboard_id: int) -> dict

Get a Superset dashboard by ID.

PARAMETER DESCRIPTION
dashboard_id

The dashboard ID.

TYPE: int

RETURNS DESCRIPTION
dict

The dashboard as a dict.

list_dashboards #

list_dashboards() -> dict

List all Superset dashboards visible to the current user.

RETURNS DESCRIPTION
dict

A dict containing the list of dashboards under the "result" key.

update_dashboard #

update_dashboard(dashboard_id: int, **kwargs: Any) -> dict

Update a Superset dashboard.

Pass fields to update as keyword arguments (e.g., dashboard_title, published, position_json, json_metadata, css, owners).

PARAMETER DESCRIPTION
dashboard_id

The dashboard ID.

TYPE: int

RETURNS DESCRIPTION
dict

The updated dashboard as a dict.

delete_dashboard #

delete_dashboard(dashboard_id: int) -> dict

Delete a Superset dashboard.

PARAMETER DESCRIPTION
dashboard_id

The dashboard ID.

TYPE: int

RETURNS DESCRIPTION
dict

Empty dict on success.