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.

Related Work

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 Renewable Energy Laboratory (NREL).

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plexosdb-1.6.1.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plexosdb-1.6.1-py3-none-any.whl (1.6 MB view details)

Uploaded Python 3

File details

Details for the file plexosdb-1.6.1.tar.gz.

File metadata

  • Download URL: plexosdb-1.6.1.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for plexosdb-1.6.1.tar.gz
Algorithm Hash digest
SHA256 276bff067f937b55ae3070b2151b9eaef9cbd2a2e716595ce6ce68bc6123ae7f
MD5 d7aec659d65c1f953f3b91c9143554d9
BLAKE2b-256 b50479d76def07a3a25c34085e9f5633bca75a1d2d809b5b4882741a6fb28ccd

See more details on using hashes here.

Provenance

The following attestation bundles were made for plexosdb-1.6.1.tar.gz:

Publisher: release.yaml on NatLabRockies/plexosdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file plexosdb-1.6.1-py3-none-any.whl.

File metadata

  • Download URL: plexosdb-1.6.1-py3-none-any.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for plexosdb-1.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bcbffedb653447ae41f164fc25bc6a754cbbb2a2194fc55720e4b3f625ad96a4
MD5 713469b72851b6217802c53604970f2f
BLAKE2b-256 c3166a20209dc60165863e1cb0627b8f85d4dc1c374e1069b8897ef302fc42b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for plexosdb-1.6.1-py3-none-any.whl:

Publisher: release.yaml on NatLabRockies/plexosdb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.6.1 This release

2 files

1.6.0

2 files

1.5.0

2 files

1.4.1

2 files

1.4.0

2 files

1.3.4

2 files

1.3.3

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.1.0

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

0.0.0

2 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