Skip to main content

plexosdb

SQLite-backed Python API for reading, building, and writing PLEXOS XML models

image image image CI codecov Ruff Documentation

plexosdb converts PLEXOS XML input files into an in-memory SQLite database, giving you a fast, typed Python API to query, create, and modify power system models programmatically, then write them back to XML.

Installation

pip install plexosdb

Or with uv:

uv add plexosdb

Python version support: 3.11, 3.12, 3.13, 3.14

Quick Start

from plexosdb import PlexosDB, ClassEnum, CollectionEnum

# Load a PLEXOS XML file into an in-memory SQLite database
db = PlexosDB.from_xml("model.xml")

# Query existing objects
generators = db.get_object_names(ClassEnum.Generator)

# Add new objects
db.add_object(ClassEnum.Generator, name="SolarPV_01", category="Renewables")
db.add_object(ClassEnum.Node, name="Bus_1")

# Create memberships between objects
db.add_membership(
    CollectionEnum.GeneratorNodes,
    parent_class=ClassEnum.Generator,
    parent_name="SolarPV_01",
    child_class=ClassEnum.Node,
    child_name="Bus_1",
)

# Export the modified model back to XML
db.to_xml("modified_model.xml")

Versioned Schema Initialization

When creating a brand-new database (not importing XML), you can preload the matching PLEXOS master template by version:

from plexosdb import PlexosDB

db = PlexosDB()
db.create_schema(version=10)

Supported versions: 9, 10, 11, 12.

Accepted inputs include integers, strings, and tuples. For example:

db.create_schema(version="v11.0R4")
db.create_schema(version=(12, 0, 3))

Read PLEXOS Solution ZIP Tables with pandas

from plexosdb import PlexosSolution
import pandas as pd

PLEXOS_SOLUTION = "/path/to/solution.zip"

sol = PlexosSolution.from_zip(PLEXOS_SOLUTION)
sol.to_sqlite("output.sqlite", if_exists="replace")

table = "ST__Interval__Regions__Fixed_Load"
sol.materialize_table(table, schema="report")
df_table = pd.read_sql_query(f'SELECT * FROM report."{table}"', sol.connection)

This pattern is useful when you only need a few report/data tables from a large solution ZIP, because it materializes tables on demand.

Documentation

Full documentation is available at natlabrockies.github.io/plexosdb.

For related previous/current work on querying PLEXOS outputs with DuckDB, see plexos2duckdb.

Developer Setup

plexosdb uses uv for dependency management.

git clone https://github.com/NatLabRockies/plexosdb.git
cd plexosdb
uv sync --all-groups

Install the git hooks so your code is checked before making commits:

uv run prek install

Run the test suite:

uv run pytest

License

This software is released under a BSD-3-Clause License.

This software was developed under software record SWR-24-90 at the National Laboratory of the Rockies (NLR).

Disclaimer

PLEXOS is a registered trademark of Energy Exemplar Pty Ltd. Energy Exemplar Pty Ltd. has no affiliation to or participation in this software. Reference herein to any specific commercial products, process, or service by trade name, trademark, manufacturer, or otherwise, does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United States Government or Alliance for Sustainable Energy, LLC ("Alliance"). The views and opinions of authors expressed in the available or referenced documents do not necessarily state or reflect those of the United States Government or Alliance.

Metadata

Release files for plexosdb 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for plexosdb 1.7.0
File Size Uploaded
plexosdb-1.7.0.tar.gz 1.6 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for plexosdb 1.7.0
File Interpreter ABI Platform
plexosdb-1.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 3.2 MB

Release files / plexosdb-1.7.0.tar.gz

Download URL plexosdb-1.7.0.tar.gz
Size 1.6 MB
Tags Source
SHA-256 checksum
How to use checksums
39b1cb558d2ad9170cb930dc7a8bad2da5a944e6472aebbd6ed2577dc47f35dd
BLAKE2b-256 checksum
How to use checksums
095f32647d1a43d9bf1a063c0c124c6308b5b682a4c668579995e2763bab3745
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.

Transparency log

Release files / plexosdb-1.7.0-py3-none-any.whl

Download URL plexosdb-1.7.0-py3-none-any.whl
Size 1.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
74c0a3269e40272f404a7d6ac4c2baa4527f55ae80db89de5342c41fd1c1cae7
BLAKE2b-256 checksum
How to use checksums
8755c34a28406c42f2cb1886f98b958afd3d79b6ca8c321fe345689fe14a8a29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.7.0 This release

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.0

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page