0
# Apache Superset
1
2
Apache Superset is a modern, enterprise-ready business intelligence web application that enables data exploration and visualization. Built with Python and React, it provides rich visualizations, interactive dashboards, SQL Lab for data analysis, and enterprise-grade security features.
3
4
## Package Information
5
6
- **Package Name**: apache-superset
7
- **Package Type**: PyPI
8
- **Language**: Python
9
- **Installation**: `pip install apache-superset`
10
11
## Core Imports
12
13
```python
14
import superset
15
from superset import app, db, cache, security_manager
16
```
17
18
Application factory pattern:
19
20
```python
21
from superset.app import create_app
22
app = create_app()
23
```
24
25
## Basic Usage
26
27
```python
28
# Initialize Superset application
29
from superset.app import create_app
30
31
# Create app instance
32
app = create_app()
33
34
# Initialize database and permissions
35
with app.app_context():
36
from superset import cli
37
cli.init()
38
39
# Run development server
40
if __name__ == '__main__':
41
app.run(debug=True, host='0.0.0.0', port=8088)
42
```
43
44
Command-line usage:
45
46
```bash
47
# Initialize Superset
48
superset init
49
50
# Create admin user
51
superset fab create-admin
52
53
# Load example data
54
superset load-examples
55
56
# Run development server
57
superset run -h 0.0.0.0 -p 8088 --with-threads --reload --debugger
58
```
59
60
## Architecture
61
62
Apache Superset follows a layered architecture:
63
64
- **Web Layer**: Flask-based web application with RESTful APIs
65
- **Security Layer**: Role-based access control with Flask-AppBuilder
66
- **Data Layer**: SQLAlchemy ORM with pluggable database engines
67
- **Visualization Layer**: Rich chart library with D3.js and custom components
68
- **Cache Layer**: Multi-tier caching with Redis/Memcached support
69
- **Task Layer**: Celery-based background processing for async operations
70
71
## Capabilities
72
73
### Command Line Interface
74
75
Comprehensive CLI for application management, data loading, user administration, and development tasks.
76
77
```python { .api }
78
def superset() -> None:
79
"""Management script for the Superset application."""
80
81
def init() -> None:
82
"""Initialize the Superset application."""
83
84
def version(verbose: bool) -> None:
85
"""Print current version number."""
86
87
def load_examples() -> None:
88
"""Load example data and dashboards."""
89
```
90
91
[CLI Commands](./cli-commands.md)
92
93
### REST API
94
95
Full REST API for programmatic access to dashboards, charts, datasets, and administrative functions.
96
97
```python { .api }
98
# Chart API endpoints
99
class ChartRestApi(BaseSupersetModelRestApi):
100
def get(self, pk: int) -> Response:
101
"""Get chart by ID."""
102
103
def post(self) -> Response:
104
"""Create new chart."""
105
106
def put(self, pk: int) -> Response:
107
"""Update chart."""
108
109
def delete(self, pk: int) -> Response:
110
"""Delete chart."""
111
112
# Dashboard API endpoints
113
class DashboardRestApi(BaseSupersetModelRestApi):
114
def get(self, pk: int) -> Response:
115
"""Get dashboard by ID."""
116
117
def export(self) -> Response:
118
"""Export dashboards."""
119
```
120
121
[REST API](./rest-api.md)
122
123
### Application Configuration
124
125
Comprehensive configuration system for databases, security, caching, and feature flags.
126
127
```python { .api }
128
# Core configuration classes
129
class SupersetConfig:
130
SECRET_KEY: str
131
SQLALCHEMY_DATABASE_URI: str
132
WTF_CSRF_ENABLED: bool
133
FEATURE_FLAGS: Dict[str, bool]
134
135
# Database configuration
136
DATABASES: Dict[str, Dict[str, Any]]
137
138
# Cache configuration
139
CACHE_CONFIG: Dict[str, Any]
140
DATA_CACHE_CONFIG: Dict[str, Any]
141
142
# Security configuration
143
CUSTOM_SECURITY_MANAGER: Optional[Type[SupersetSecurityManager]]
144
AUTH_TYPE: int
145
AUTH_ROLE_ADMIN: str
146
AUTH_ROLE_PUBLIC: str
147
```
148
149
[Configuration](./configuration.md)
150
151
### Database Models and ORM
152
153
SQLAlchemy-based models for dashboards, charts, datasets, users, and metadata management.
154
155
```python { .api }
156
# Core models
157
class Dashboard(Model, AuditMixinNullable):
158
id: int
159
dashboard_title: str
160
position_json: str
161
slices: List[Slice]
162
163
class Slice(Model, AuditMixinNullable):
164
id: int
165
slice_name: str
166
viz_type: str
167
params: str
168
datasource: BaseDatasource
169
170
class Database(Model, AuditMixinNullable):
171
id: int
172
database_name: str
173
sqlalchemy_uri: str
174
engine: str
175
```
176
177
[Models and Database](./models-database.md)
178
179
### Security and Authentication
180
181
Enterprise-grade security with role-based access control, row-level security, and OAuth integration.
182
183
```python { .api }
184
class SupersetSecurityManager(SecurityManager):
185
def get_user_menu_access(self, menu_names: List[str]) -> Set[str]:
186
"""Get user's menu access permissions."""
187
188
def can_access(self, permission_name: str, view_name: str) -> bool:
189
"""Check if user has permission."""
190
191
def get_rls_filters(self, table: BaseDatasource) -> List[SqlaQuery]:
192
"""Get row-level security filters."""
193
194
# Permission model
195
class Permission(Model):
196
name: str
197
view_menu: ViewMenu
198
199
# Role model
200
class Role(Model):
201
name: str
202
permissions: List[Permission]
203
```
204
205
[Security and Authentication](./security-auth.md)
206
207
### Visualization System
208
209
Extensible visualization system with 40+ chart types and custom plugin support.
210
211
```python { .api }
212
class BaseViz:
213
viz_type: str
214
verbose_name: str
215
is_timeseries: bool
216
217
def get_query_object(self) -> QueryObject:
218
"""Build query object from form data."""
219
220
def get_data(self, df: pd.DataFrame) -> VizData:
221
"""Process data for visualization."""
222
223
# Chart plugin registry
224
viz_types: Dict[str, Type[BaseViz]]
225
226
# Query object for data retrieval
227
class QueryObject:
228
datasource: BaseDatasource
229
metrics: List[str]
230
groupby: List[str]
231
filters: List[Dict[str, Any]]
232
```
233
234
[Visualization System](./visualization.md)
235
236
## Types
237
238
```python { .api }
239
# Core application types
240
from typing import Dict, List, Optional, Any, Union
241
from flask import Flask
242
from pandas import DataFrame
243
244
# Configuration types
245
ConfigDict = Dict[str, Any]
246
FeatureFlags = Dict[str, bool]
247
248
# Data types
249
VizData = Dict[str, Any]
250
QueryResult = Dict[str, Any]
251
ChartData = Dict[str, Any]
252
253
# Security types
254
Permission = str
255
Role = str
256
User = Dict[str, Any]
257
258
# Database types
259
DatabaseEngine = str
260
ConnectionString = str
261
QueryObject = Dict[str, Any]
262
```