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)
Returned by
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: |
table_name | Name of the table (or virtual dataset). TYPE: |
schema | Database schema name. TYPE: |
sql | SQL expression for virtual datasets. TYPE: |
description | Optional description. TYPE: |
owners | Optional list of Superset user IDs as owners. |
| RETURNS | DESCRIPTION |
|---|---|
dict | The created dataset as a dict (Superset API response). |
get_dataset #
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 #
delete_dataset #
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: |
viz_type | Visualization type (e.g., "table", "big_number", "echarts_timeseries"). TYPE: |
datasource_id | ID of the dataset to use as data source. TYPE: |
params | JSON string of chart configuration parameters. TYPE: |
datasource_type | Type of datasource (default "table"). TYPE: |
description | Optional description. TYPE: |
dashboards | Optional list of dashboard IDs to add this chart to. |
owners | Optional list of Superset user IDs as owners. |
| RETURNS | DESCRIPTION |
|---|---|
dict | The created chart as a dict. |
get_chart #
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 #
delete_chart #
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: |
published | Whether the dashboard is published. TYPE: |
slug | Optional URL slug. TYPE: |
position_json | Optional JSON string defining the layout. TYPE: |
json_metadata | Optional JSON string with dashboard metadata. TYPE: |
css | Optional custom CSS. TYPE: |
owners | Optional list of Superset user IDs as owners. |
| RETURNS | DESCRIPTION |
|---|---|
dict | The created dashboard as a dict. |
get_dashboard #
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. |