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.
Import
Section titled “Import”from plexosdb import PlexosSolutionDeclared fields
Section titled “Declared fields”_zip_path
Section titled “_zip_path”_zip_path: Path | None_model_name
Section titled “_model_name”_model_name: str | None_database_path
Section titled “_database_path”_database_path: Path | None_connection
Section titled “_connection”_connection: duckdb.DuckDBPyConnection | NoneConstructor
Section titled “Constructor”__init__(self, source_path: str | Path | None=None, *, model_name: str | None=None, _factory_token: object | None=None) -> NonePrevent direct construction; use a named factory instead.
Declared methods and properties
Section titled “Declared 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.