Database Driver Integration#
Superset connects to external databases through two complementary layers: DB engine specs (Python classes that encode SQL dialect knowledge) and SQLAlchemy drivers (Python packages that provide the actual network connectivity). Both must be present for a database connection to work.
DB Engine Specs#
Every supported database has a corresponding engine spec class in superset/db_engine_specs/. 50+ specs ship with Superset. Each inherits from BaseEngineSpec and overrides dialect-specific behavior.
Key class-level attributes on BaseEngineSpec:
| Attribute | Purpose |
|---|---|
engine | SQLAlchemy backend name (matches URL scheme, e.g. "oracle") |
engine_aliases | Alternate backend names for the same spec (e.g. {"postgres"}) |
drivers / default_driver | Dict of supported DBAPI drivers + which to use by default |
max_column_name_length | Database-specific identifier length limit |
force_column_alias_quotes | Whether to force quoting on column aliases |
_time_grain_expressions | SQL templates for each TimeGrain constant |
Key methods that subclasses override:
convert_dttm()— converts a Pythondatetimeto a database-appropriate SQL literalepoch_to_dttm()/epoch_ms_to_dttm()— epoch → datetime SQL expressionsfetch_data()— post-processes cursor results (e.g. Oracle returns empty[]whencursor.descriptionis falsy)adjust_engine_params()— modifies the SQLAlchemy URL and connect args for schema/catalog selection
Oracle Engine Spec Example#
OracleEngineSpec illustrates a typical minimal spec:
engine = "oracle",engine_name = "Oracle"force_column_alias_quotes = True,max_column_name_length = 30— enforces Oracle's 30-character identifier limit_time_grain_expressionsuses OracleTRUNC()andCAST()syntaxconvert_dttm()emitsTO_DATE()/TO_TIMESTAMP()literals
Engine Spec Discovery#
Specs are loaded at runtime by load_engine_specs() in superset/db_engine_specs/__init__.py, which scans both the built-in db_engine_specs package and any third-party entry points registered under the "superset.db_engine_specs" group. get_engine_spec(backend, driver) resolves the spec for a given SQLAlchemy URL — matching by driver first, then by backend alone, then falling back to BaseEngineSpec.
Installing Database Drivers#
Most database drivers are not bundled with the default Docker image; they must be added separately. Superset ships cx-Oracle>8.0.0,<8.1 as the oracle optional extra in pyproject.toml, alongside 40+ other optional database extras .
Option 1 — requirements-local.txt (Docker, no Dockerfile change)#
The simplest path for Docker-based setups :
- Create
./docker/requirements-local.txtand add the driver package(s), e.g.cx-Oracle==8.0.1 - Run
docker compose down -v && docker compose up
docker/docker-bootstrap.sh checks for this file at startup and installs it via uv pip install -r (or pip install -r on older images) before starting the Flask app or Celery workers. The file is git-ignored by convention, keeping driver installs local and out of source control.
Option 2 — pyproject.toml optional extras (pip install)#
When installing via pip outside Docker, install the database extra directly:
pip install "apache-superset[oracle]"
# or for multiple:
pip install "apache-superset[oracle,postgres,mysql]"
The oracle extra pulls in cx-Oracle>8.0.0, <8.1 . Available extras include bigquery, mysql, postgres, snowflake, trino, hive, mssql, databricks, and many others .
Option 3 — Custom Dockerfile#
For production images, COPY a requirements-local.txt into the image and run pip install during the build, or extend the lean stage of the Dockerfile. The lean image installs from the pinned requirements/base.txt ; customizations should layer on top.
Key Files Reference#
| Path | Role |
|---|---|
superset/db_engine_specs/ | All engine spec classes (50+ databases) |
superset/db_engine_specs/base.py | BaseEngineSpec — base class for all specs |
superset/db_engine_specs/__init__.py | Discovery: load_engine_specs(), get_engine_spec() |
superset/db_engine_specs/oracle.py | Oracle engine spec (cx-Oracle driver) |
pyproject.toml | Optional database extras (40+ drivers) |
docker/requirements-local.txt | Git-ignored file for local driver overrides |
docker/docker-bootstrap.sh | Installs requirements-local.txt at container startup |
Dockerfile | Multi-stage build; lean target is the base for production |