DuckDB Solution Reader
The DuckDB solution reader converts a PLEXOS solution ZIP with plexos2duckdb
and exposes lazy DuckDB relations for analysis. Import it explicitly to
distinguish it from the SQLite-backed solution reader:
from plexosdb.db_solution import PlexosSolutionResult Types
Section titled “Result Types”See Reading a PLEXOS Solution for a complete ZIP-to-DuckDB workflow.
Public module members
Section titled “Public module members”plexosdb.db_solution
Section titled “plexosdb.db_solution”PlexosSolution
Section titled “PlexosSolution”PLEXOS solution wrapper backed by plexos2duckdb.
Passing database to to_duckdb creates or reuses a file-backed
DuckDB database, which is the fastest path for large solutions. Omitting
database keeps the result in memory by converting through a temporary
DuckDB file and copying it into an in-memory DuckDB connection.
Methods and properties
Section titled “Methods and properties”from_zip
Section titled “from_zip”from_zip(cls, path: str | Path, *, model_name: str | None=None) -> PlexosSolutionCreate a solution wrapper bound to a PLEXOS solution path.
to_duckdb
Section titled “to_duckdb”to_duckdb(self, database: str | Path | None=None, *, if_exists: IfExists='reuse', n_threads: int | None=None, table_name_pattern: str | None=None, in_memory: bool | None=None) -> DuckDBResultConvert the solution with plexos2duckdb and open a DuckDB connection.
Parameters
databaseOutput DuckDB path. When omitted, the result is in memory unlessin_memory=Falseis provided.if_existsFile-backed overwrite policy:'fail','reuse', or'replace'. Ignored for in-memory conversion because the intermediate database is temporary.n_threadsOptional thread count passed toplexos2duckdbfor time-series table writes.table_name_patternOptional regex passed toplexos2duckdbto restrict generated data tables.in_memoryTrueforces an in-memory final connection,Falseforces a file-backed database, andNoneuses in memory when database is omitted.
info(self) -> DuckDBSolutionInfoReturn metadata about the configured or converted DuckDB solution.
list_tables
Section titled “list_tables”list_tables(self, *, schema: DuckDBSchema='report') -> list[TableInfo]List tables or views in one DuckDB solution schema.
sql(self, query_string: str) -> duckdb.DuckDBPyRelationBuild a lazy DuckDB relation from a SQL query.
query(self, query_string: str, params: tuple[Any, ...] | dict[str, Any] | None=None) -> list[Any]Execute a read-only query and return all rows.
query_dicts
Section titled “query_dicts”query_dicts(self, query_string: str, params: tuple[Any, ...] | dict[str, Any] | None=None) -> list[dict[str, Any]]Execute a read-only query and return rows as dictionaries.
table(self, table: str | ResultTable, *, schema: DuckDBSchema='report') -> duckdb.DuckDBPyRelationBuild a lazy DuckDB relation for a solution table or view.
list_objects_by_class
Section titled “list_objects_by_class”list_objects_by_class(self, class_enum: ClassEnum | str, /, *, category: str | None=None) -> list[str]Return solution object names for a PLEXOS class.
list_result_tables
Section titled “list_result_tables”list_result_tables(self, *, schema: ResultSchema='report', phase: PhaseEnum | str | None=None, period: PeriodEnum | str | None=None, class_enum: ClassEnum | str | None=None, collection: CollectionEnum | str | None=None, property_name: str | None=None) -> list[ResultTable]List result tables using PLEXOS class, collection, and property filters.
result_table
Section titled “result_table”result_table(self, *, schema: ResultSchema='report', phase: PhaseEnum | str=PhaseEnum.ST, period: PeriodEnum | str=PeriodEnum.INTERVAL, class_enum: ClassEnum | str | None=None, collection: CollectionEnum | str | None=None, property_name: str) -> ResultTableReturn one result table matching PLEXOS dimensions.
get_result
Section titled “get_result”get_result(self, table_name: ResultTable | str, /, *, object_names: str | Iterable[str] | None=None, category: str | None=None, sample_names: str | Iterable[str] | None='Mean', bands: int | Iterable[int] | None=None, start: str | None=None, end: str | None=None, columns: Sequence[str] | None=None) -> duckdb.DuckDBPyRelationBuild a lazy relation for filtered rows from a result table.
connection
Section titled “connection”connection: duckdb.DuckDBPyConnectionThe active DuckDB connection.
close(self) -> NoneClose the active DuckDB connection.
Full reference: PlexosSolution.
plexosdb.db_solution_models
Section titled “plexosdb.db_solution_models”DuckDBSchema
Section titled “DuckDBSchema”DuckDBSchema = Literal['raw', 'processed', 'data', 'report']IfExists
Section titled “IfExists”IfExists = Literal['fail', 'reuse', 'replace']ResultSchema
Section titled “ResultSchema”ResultSchema = Literal['data', 'report']DuckDBResult
Section titled “DuckDBResult”Result returned by plexosdb.db_solution.PlexosSolution.to_duckdb.
Methods and properties
Section titled “Methods and properties”is_in_memory
Section titled “is_in_memory”is_in_memory: boolReturn True when the database lives in memory only.
Full reference: DuckDBResult.
DuckDBSolutionInfo
Section titled “DuckDBSolutionInfo”Metadata about a DuckDB-backed PLEXOS solution.
Full reference: DuckDBSolutionInfo.
TableInfo
Section titled “TableInfo”Metadata about one table or view in a DuckDB solution schema.
Full reference: TableInfo.
ResultTable
Section titled “ResultTable”Metadata for one PLEXOS solution result table or view.
Full reference: ResultTable.