SQLite Solution Reader
The SQLite solution reader imports a PLEXOS solution ZIP into SQLite and materializes derived result tables for analysis. Import it explicitly to distinguish it from the DuckDB-backed solution wrapper:
from plexosdb.solution_reader import PlexosSolutionDisplay Helpers
Section titled “Display Helpers”Result Types
Section titled “Result Types”See Inspecting a PLEXOS Solution for a complete ZIP-to-SQLite workflow.
Public module members
Section titled “Public module members”plexosdb.solution_reader.solution
Section titled “plexosdb.solution_reader.solution”PlexosSolution
Section titled “PlexosSolution”Fluent interface for importing and querying a PLEXOS solution.
Two entry points are available:
from_zip— bind to a PLEXOS solution ZIP file and useto_sqliteto import it. Both XML metadata and BIN payloads are parsed during import.from_sqlite— open an already-imported SQLite database directly, without needing the original ZIP file.
Typical use with a ZIP::
with PlexosSolution.from_zip("mysolution.zip") as sol: result = sol.to_sqlite("output.sqlite") sol.materialize_table("Generator")Re-opening an existing database (no ZIP needed)::
sol = PlexosSolution.from_sqlite("output.sqlite")show_db_tables(sol)sol.materialize_table("Generator")sol.close()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 PlexosSolution bound to a PLEXOS solution ZIP.
Parameters
pathPath to the PLEXOS solution ZIP file.model_nameOptional hint for selecting the correct XML when multiple XML files exist inside the archive.
from_sqlite
Section titled “from_sqlite”from_sqlite(cls, path: str | Path) -> PlexosSolutionOpen an existing PLEXOS solution SQLite database without a source ZIP.
Useful for reading and querying a database that was previously created
with to_sqlite or plexos_to_sqlite. No ZIP file is
required — the XML metadata and BIN payloads are already stored in
SQLite.
Parameters
pathPath to an existing PLEXOS solution SQLite file.
Raises
FileNotFoundErrorIf path does not exist.
to_sqlite
Section titled “to_sqlite”to_sqlite(self, database: str | Path | None=None, *, if_exists: Literal['fail', 'reuse', 'replace']='reuse', materialize: Literal['none', 'all'] | Sequence[str]='none', decode_bin_values: bool=True) -> SQLiteResultImport the solution ZIP into a SQLite database.
Parameters
-
databaseFilesystem path for the SQLite file.None(default) or the special string':memory:'create an in-memory database (if_existsis ignored in that case). -
if_existsControls behaviour when database already exists on disk:'fail'RaiseFileExistsError.'reuse'Open the existing file, decode BIN values if missing, and attach derived-table schemas. No re-import is performed.'replace'Delete the file and create a fresh database. -
decode_bin_valuesIfTrue(default), decode the BIN payload files from the solution ZIP intot_data_values. Set toFalseto skip BIN decoding — useful when only the table catalog or XML metadata tables are needed, which avoids writing potentially millions of rows and is significantly faster for large solutions. -
materializeWhich derived tables to materialize after import:'none'Do not materialize any tables (default).'all'Materialize all available derived tables. sequence of strings Materialize only the named tables.
Returns
SQLiteResultContains the database path (Nonefor in-memory) and the list of table names in the main schema after import.
info(self) -> SolutionInfoReturn metadata about the solution archive.
Raises
RuntimeErrorIf no ZIP path has been configured (seefrom_zip).
list_tables
Section titled “list_tables”list_tables(self, *, schema: Literal['raw', 'processed', 'data', 'report']='report') -> list[TableInfo]List tables available under the given schema.
Parameters
schema'raw'All tables present in the main SQLite schema.'processed'Core PLEXOS entity tables (class, object, membership, property).'data'Derived analysis tables (whether materialized or not).'report'Same as data — derived tables exposed under the report schema.
materialize_table
Section titled “materialize_table”materialize_table(self, name: str, *, schema: Literal['data', 'report']='report', if_exists: Literal['fail', 'reuse', 'replace']='reuse') -> MaterializeResultMaterialize one derived table into the attached schema.
Parameters
nameName of the derived table to materialize (e.g.'Generator').schemaTarget schema:'data'or'report'.if_exists'reuse'(default) — return without re-materializing if the table already exists.'fail'— raiseFileExistsError.'replace'— drop the existing table and re-materialize.
connection
Section titled “connection”connection: sqlite3.ConnectionThe active SQLite connection.
Raises
RuntimeErrorIfto_sqlitehas not been called yet.
close(self) -> NoneClose the active SQLite connection.
source
Section titled “source”source: Path | NonePath to the source ZIP file, or None for from_sqlite instances.
name: strDisplay name for the solution.
Returns the stem of the source ZIP when available, then the stem of
the SQLite database, then 'unknown'.
plexosdb.solution_reader.display
Section titled “plexosdb.solution_reader.display”show_db_tables
Section titled “show_db_tables”Print the table catalog of a PLEXOS solution in DuckDB-style box format.
Collects all physical tables from attached SQLite schemas together with
logical derived result tables (data / report) from the solution
metadata, sorts them by schema then name, and prints the result as a
Unicode box table — the same visual style used by DuckDB.
This function must be called after PlexosSolution.to_sqlite has
been invoked (i.e. after the SQLite connection has been opened).
Parameters
clientAPlexosSolutioninstance with an active connection.max_rowsMaximum number of rows to show before truncating with·rows. When the result exceeds max_rows, the first and lastmax_rows // 2rows are displayed. Defaults to20.
Examples
from plexosdb import PlexosSolution, show_db_tables
sol = PlexosSolution.from_zip("my_solution.zip")sol.to_sqlite("output.sqlite", if_exists="replace", decode_bin_values=False)
show_db_tables(sol)show_db_tables(client: PlexosSolution, *, max_rows: int=20) -> Noneplexosdb.solution_reader.types
Section titled “plexosdb.solution_reader.types”SolutionInfo
Section titled “SolutionInfo”Metadata about a PLEXOS solution archive.
SQLiteResult
Section titled “SQLiteResult”Result returned by PlexosSolution.to_sqlite.
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.
TableInfo
Section titled “TableInfo”Metadata about one table or view in a solution schema.
MaterializeResult
Section titled “MaterializeResult”Result returned by PlexosSolution.materialize_table.