michael-s-molina commented on code in PR #36005:
URL: https://github.com/apache/superset/pull/36005#discussion_r2495900695


##########
docs/developer_portal/extensions/quick-start.md:
##########
@@ -0,0 +1,362 @@
+---
+title: Quick Start
+sidebar_position: 2
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# Quick Start
+
+This guide walks you through creating your first Superset extension - a simple 
"Hello World" panel that displays a message fetched from a backend API 
endpoint. You'll learn the essential structure and patterns for building 
full-stack Superset extensions.
+
+## Prerequisites
+
+Before starting, ensure you have:
+- Node.js 18+ and npm installed
+- Python 3.9+ installed
+- A running Superset development environment
+- Basic knowledge of React, TypeScript, and Flask
+
+## Step 1: Install the Extensions CLI
+
+First, install the Apache Superset Extensions CLI:
+
+```bash
+pip install apache-superset-extensions-cli
+```
+
+## Step 2: Create a New Extension
+
+Use the CLI to scaffold a new extension project:
+
+```bash
+superset-extensions init
+```
+
+The CLI will prompt you for information:
+
+```
+Extension ID (unique identifier, alphanumeric only): hello_world
+Extension name (human-readable display name): Hello World
+Initial version [0.1.0]: 0.1.0
+License [Apache-2.0]: Apache-2.0
+Include frontend? [Y/n]: Y
+Include backend? [Y/n]: Y
+```
+
+This creates a complete project structure:
+
+```
+hello_world/
+├── extension.json           # Extension metadata and configuration
+├── backend/                 # Backend Python code
+│   ├── src/
+│   │   └── hello_world/
+│   │       ├── __init__.py
+│   │       └── entrypoint.py  # Backend registration
+│   └── pyproject.toml
+└── frontend/                # Frontend TypeScript/React code
+    ├── src/
+    │   └── index.tsx        # Frontend entry point
+    ├── package.json
+    ├── tsconfig.json
+    └── webpack.config.js
+```
+
+## Step 3: Configure Extension Metadata
+
+The generated `extension.json` contains basic metadata. Update it to register 
your panel in SQL Lab:
+
+```json
+{
+  "id": "hello_world",
+  "name": "Hello World",
+  "version": "0.1.0",
+  "license": "Apache-2.0",
+  "frontend": {
+    "contributions": {
+      "views": {
+        "sqllab.panels": [
+          {
+            "id": "hello_world.main",
+            "name": "Hello World"
+          }
+        ]
+      }
+    },
+    "moduleFederation": {
+      "exposes": ["./index"]
+    }
+  },
+  "backend": {
+    "entryPoints": ["hello_world.entrypoint"],
+    "files": ["backend/src/hello_world/**/*.py"]
+  },
+  "permissions": ["can_read"]
+}
+```
+
+**Key fields:**
+- `frontend.contributions.views.sqllab.panels`: Registers your panel in SQL Lab
+- `backend.entryPoints`: Python module to load when extension starts
+
+## Step 4: Create Backend API
+
+The CLI generated a basic `backend/src/hello_world/entrypoint.py`. We'll 
create an API endpoint.
+
+**Create `backend/src/hello_world/api.py`**
+
+```python
+from flask import Response
+from flask_appbuilder.api import expose, protect, safe
+from superset_core.api.types.rest_api import RestApi
+
+
+class HelloWorldAPI(RestApi):
+    resource_name = "hello_world"
+    openapi_spec_tag = "Hello World"
+    class_permission_name = "hello_world"
+
+    @expose("/message", methods=("GET",))
+    @protect()
+    @safe
+    def get_message(self) -> Response:
+        return self.response(
+            200,
+            result={"message": "Hello from the backend!"}
+        )
+```
+
+**Key points:**
+- Extends `RestApi` from `superset_core.api.types.rest_api`
+- Uses Flask-AppBuilder decorators (`@expose`, `@protect`, `@safe`)
+- Returns responses using `self.response(status_code, result=data)`
+- The endpoint will be accessible at `/extensions/hello_world/message`
+
+**Update `backend/src/hello_world/entrypoint.py`**
+
+Replace the generated print statement with API registration:
+
+```python
+from superset_core.api import rest_api
+
+from .api import HelloWorldAPI
+
+rest_api.add_extension_api(HelloWorldAPI)
+```
+
+This registers your API with Superset when the extension loads.
+
+## Step 5: Create Frontend Component
+
+The CLI generated boilerplate files. The webpack config and package.json are 
already properly configured with Module Federation.
+
+**Create `frontend/src/HelloWorldPanel.tsx`**
+
+Create a new file for the component implementation:
+
+```tsx
+import React, { useEffect, useState } from 'react';
+import { authentication } from '@apache-superset/core';
+
+const HelloWorldPanel: React.FC = () => {
+  const [message, setMessage] = useState<string>('');
+  const [loading, setLoading] = useState(true);
+  const [error, setError] = useState<string>('');
+
+  useEffect(() => {
+    const fetchMessage = async () => {
+      try {
+        const csrfToken = await authentication.getCSRFToken();
+        const response = await fetch('/extensions/hello_world/message', {
+          method: 'GET',
+          headers: {
+            'Content-Type': 'application/json',
+            'X-CSRFToken': csrfToken!,
+          },
+        });
+
+        if (!response.ok) {
+          throw new Error(`Server returned ${response.status}`);
+        }
+
+        const data = await response.json();
+        setMessage(data.result.message);
+      } catch (err) {
+        setError(err instanceof Error ? err.message : 'An error occurred');
+      } finally {
+        setLoading(false);
+      }
+    };
+
+    fetchMessage();
+  }, []);
+
+  if (loading) {
+    return (
+      <div style={{ padding: '20px', textAlign: 'center' }}>
+        <p>Loading...</p>
+      </div>
+    );
+  }
+
+  if (error) {
+    return (
+      <div style={{ padding: '20px', color: 'red' }}>
+        <strong>Error:</strong> {error}
+      </div>
+    );
+  }
+
+  return (
+    <div style={{ padding: '20px' }}>
+      <h3>Hello World Extension</h3>
+      <div style={{
+        padding: '16px',
+        backgroundColor: '#f6ffed',
+        border: '1px solid #b7eb8f',
+        borderRadius: '4px',
+        marginBottom: '16px'
+      }}>
+        <strong>{message}</strong>
+      </div>
+      <p>This message was fetched from the backend API! 🎉</p>
+    </div>
+  );
+};
+
+export default HelloWorldPanel;
+```
+
+**Update `frontend/src/index.tsx`**
+
+Replace the generated code with the extension entry point:
+
+```tsx
+import React from 'react';
+import { core } from '@apache-superset/core';
+import HelloWorldPanel from './HelloWorldPanel';
+
+export const activate = (context: core.ExtensionContext) => {
+  context.disposables.push(
+    core.registerViewProvider('hello_world.main', () => <HelloWorldPanel />),
+  );
+};
+
+export const deactivate = () => {};
+```
+
+**Key patterns:**
+- `activate` function is called when the extension loads
+- `core.registerViewProvider` registers the component with ID 
`hello_world.main` (matching `extension.json`)
+- `authentication.getCSRFToken()` retrieves the CSRF token for API calls
+- Fetch calls to `/extensions/{extension_id}/{endpoint}` reach your backend API
+- `context.disposables.push()` ensures proper cleanup
+
+## Step 6: Install Dependencies
+
+Install the frontend dependencies:
+
+```bash
+cd frontend
+npm install
+cd ..
+```
+
+## Step 7: Package the Extension
+
+Create a `.supx` bundle for deployment:
+
+```bash
+superset-extensions bundle
+```
+
+This command automatically:
+- Builds frontend assets using Webpack with Module Federation
+- Collects backend Python source files
+- Creates a `dist/` directory with:
+  - `manifest.json` - Build metadata and asset references
+  - `frontend/dist/` - Built frontend assets (remoteEntry.js, chunks)
+  - `backend/` - Python source files
+- Packages everything into `hello_world-0.1.0.supx` - a zip archive with the 
specific structure required by Superset
+
+## Step 8: Deploy to Superset
+
+To deploy your extension, configure Superset to load it from a directory 
accessible to the Superset instance.
+
+**Configure Extensions Path**
+
+Add to your `superset_config.py`:
+
+```python
+EXTENSIONS_PATH = "/path/to/extensions/folder"

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to