Environment Variables
Relevant source files
The following files were used as context for generating this wiki page:
The superset-ext utility uses environment variables as the primary mechanism for configuration and state management within a Meltano project. These variables facilitate the mapping of Meltano settings to Apache Superset's configuration requirements, enabling automated initialization, database migrations, and administrative setup.
Environment variables are used to define critical paths (such as the project root and configuration file locations), security credentials, and database connection strings. The extension specifically looks for variables prefixed with SUPERSET_ to derive its internal configuration dictionary.
Sources: superset_ext/extension.py:27-30, superset_ext/utils.py:48-52, README.md:27-37
Configuration Loading and Transformation
The extension implements a specific logic for loading environment variables, filtering them by prefix, and transforming them into a format compatible with Superset's internal configuration.
Prefix Handling
The system uses the ENV_PREFIX = "SUPERSET_" to identify relevant variables. The load_config_from_env function filters the global environment for keys starting with this prefix. If trimmed=True is passed, the prefix is removed from the resulting dictionary keys to create standard Superset configuration keys.
Sources: superset_ext/extension.py:25, superset_ext/utils.py:31-45, tests/test_superset_ext_utils.py:22-26
Environment Preparation Flow
The prepared_env function acts as the central orchestrator for environment setup. It handles path resolution and sets default values for mandatory Superset variables if they are missing.
The diagram shows how the extension resolves paths relative to MELTANO_PROJECT_ROOT and ensures essential Flask/Superset variables are populated.
Sources: superset_ext/utils.py:48-93
Key Environment Variables
The following table details the primary environment variables used by the extension and their roles:
| Variable | Source Key (Trimmed) | Default / Calculated Value | Description |
|---|---|---|---|
MELTANO_PROJECT_ROOT | N/A | Provided by Meltano | Base directory for path resolution. |
SUPERSET_HOME | HOME | $MELTANO_PROJECT_ROOT/.meltano/utilities/superset | Directory for Superset data and local files. |
SUPERSET_CONFIG_PATH | CONFIG_PATH | analyze/superset/superset_config.py | Path where the generated Superset config is stored. |
SUPERSET_SQLALCHEMY_DATABASE_URI | SQLALCHEMY_DATABASE_URI | sqlite:///{HOME}/superset.db | Connection string for the Superset metadata database. |
FLASK_APP | FLASK_APP | superset | Required entry point for the Flask-based application. |
SUPERSET_SECRET_KEY | SECRET_KEY | None (Must be set) | Cryptographic key for session signing and security. |
Sources: superset_ext/utils.py:65-87, README.md:27-37, superset_ext/extension.py:42-47
Config File Generation Logic
The environment variables are eventually persisted into a Python configuration file (superset_config.py). This allows Superset to read the environment-derived settings during its standard initialization process.
- Filtering: The extension filters out keys starting with
EXT_to avoid passing extension-specific metadata into Superset. - Case Sensitivity: When writing the file, only keys that are entirely uppercase are set as attributes on the module.
- Persistence: The
write_configutility creates the necessary directories and writes a Python script that injects the dictionary into the global scope.
# Implementation of config injection logic
config_script_lines = [
"import sys",
"module = sys.modules[__name__]",
f"config = {superset_config!r}",
"for key, value in config.items():",
" if key.isupper():",
" setattr(module, key, value)",
]
Sources: superset_ext/utils.py:118-124, superset_ext/extension.py:34-38
CLI and Logging Configuration
The extension also consumes environment variables for managing its own execution behavior via the typer application.
| CLI Option | Environment Variable | Default | Description |
|---|---|---|---|
--log-level | LOG_LEVEL | INFO | Severity level for logs (DEBUG, INFO, etc.). |
--log-timestamps | LOG_TIMESTAMPS | False | Whether to include timestamps in log output. |
--log-levels | LOG_LEVELS | False | Whether to show log levels in output. |
--meltano-log-json | MELTANO_LOG_JSON | False | Use Meltano-compatible JSON log format. |
Sources: superset_ext/main.py:101-118
Conclusion
Environment variables in superset-ext bridge the gap between Meltano's configuration layer and Superset's Python-based configuration requirements. By using a prefixed approach and automated path resolution based on MELTANO_PROJECT_ROOT, the extension ensures that Superset can be managed as a portable utility while maintaining access to all necessary infrastructure settings.