Query a Project’s Database Directly¶
Each STRIDE project stores its data in a DuckDB database at <project>/registry_data/data.duckdb. You can query it with SQL, either from Python (no extra installation) or with the DuckDB command line interface (CLI).
From Python¶
STRIDE already installs DuckDB’s Python package. Open the project read-only and use its connection:
from stride import Project
with Project.load("my_project", read_only=True) as project:
print(project.con.sql("SHOW ALL TABLES"))
df = project.con.sql("SELECT * FROM energy_projection LIMIT 10").df()
From the DuckDB CLI¶
Install the CLI¶
STRIDE does not install the DuckDB CLI. Follow the instructions at duckdb.org/docs/installation. At the time of writing they are:
curl https://install.duckdb.org | bash
powershell -NoExit -ExecutionPolicy Bypass -Command "irm https://install.duckdb.org/install.ps1 | iex"
Use a CLI version at least as new as the DuckDB version STRIDE uses, which you can check with:
$ python -c "import duckdb; print(duckdb.__version__)"
Open the database read-only¶
$ duckdb -readonly my_project/registry_data/data.duckdb
Always pass -readonly:
Several programs can then read the database at the same time, for example the CLI and
stride view.A newer CLI can’t modify the file. A file written by a newer DuckDB may become unreadable by the DuckDB version that STRIDE uses.
Then run SQL at the prompt, for example:
SHOW ALL TABLES;
SELECT * FROM energy_projection LIMIT 10;
What’s in the database¶
Schema |
Contents |
|---|---|
|
|
One per scenario, e.g. |
The calculated tables (dbt models) for that scenario |
|
The input datasets, e.g. |
Time zones¶
Timestamps are stored as absolute instants (TIMESTAMP WITH TIME ZONE). DuckDB displays them in the session’s time zone:
STRIDE’s own connections use UTC.
The CLI and other connections usually use your computer’s time zone.
To see local standard time, convert explicitly, for example timezone(time_zone, timestamp). See Time Conventions.
See also¶
Export Results to write tables to CSV or Parquet files
Process results with Python for aggregated queries from Python