This guide will walk you through creating, developing, and deploying your first Superset extension.
Before you begin, make sure you have:
First, install the Superset Extensions CLI globally:
pip install apache-superset-extensions-cli
Use the CLI to scaffold a new extension project:
superset-extensions init my-first-extension cd my-first-extension
This creates the following structure:
my-first-extension/ ├── extension.json # Extension metadata ├── frontend/ # Frontend code │ ├── src/ │ │ └── index.tsx # Main entry point │ ├── package.json │ └── webpack.config.js ├── backend/ # Backend code (optional) │ ├── src/ │ └── requirements.txt └── README.md
Edit extension.json
to define your extension's capabilities:
{ "name": "my-first-extension", "version": "1.0.0", "description": "My first Superset extension", "author": "Your Name", "frontend": { "contributions": { "views": { "sqllab.panels": [ { "id": "my-extension.main", "name": "My Panel", "icon": "ToolOutlined" } ] } } } }
Edit frontend/src/index.tsx
to implement your extension:
import React from 'react'; import { ExtensionContext } from '@apache-superset/core'; export function activate(context: ExtensionContext) { // Register your panel component const panel = context.core.registerView('my-extension.main', () => ( <div style={{ padding: 20 }}> <h2>Hello from My Extension!</h2> <p>This is my first Superset extension.</p> </div> )); // Clean up on deactivation context.subscriptions.push(panel); } export function deactivate() { // Cleanup code if needed }
Enable development mode in your Superset configuration:
# superset_config.py ENABLE_EXTENSIONS = True LOCAL_EXTENSIONS = [ "/path/to/my-first-extension" ]
Run the development server:
# In your extension directory superset-extensions dev # In a separate terminal, start Superset superset run -p 8088 --with-threads --reload
Your extension will now appear in SQL Lab!
When ready to distribute your extension:
superset-extensions build superset-extensions bundle
This creates a my-first-extension-1.0.0.supx
file that can be uploaded to any Superset instance.
Upload your extension via the Superset UI or API:
curl -X POST http://localhost:8088/api/v1/extensions/import/ \ -H "Authorization: Bearer YOUR_TOKEN" \ -F "file=@my-first-extension-1.0.0.supx"
Now that you have a basic extension working, explore:
const panel = context.core.registerView('my-extension.panel', () => ( <MyPanelComponent /> ));
const command = context.commands.registerCommand('my-extension.run', { title: 'Run My Command', execute: () => { // Command logic } });
const listener = context.sqlLab.onDidQueryRun((query) => { console.log('Query executed:', query); });
{ "menus": { "sqllab.editor": { "primary": [{ "command": "my-extension.run", "when": "editorHasSelection" }] } } }
ENABLE_EXTENSIONS = True
in your configLOCAL_EXTENSIONS
npm install
in the frontend directory@apache-superset/core
is properly externalized