GridForge provides a small, explicit Python API for preparing standard PYPOWER/MATPOWER cases for power-system studies. It keeps the familiar case tables, gives them readable column names, preserves real bus IDs, and adds a few domain operations that are error-prone with raw NumPy arrays. You can directly use its output to formulate power system optimization problems.
Install the released package from PyPI:
pip install powergridforgeFor development:
git clone https://github.com/xuwkk/gridforge.git
cd gridforge
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"To preview or check the documentation from the repository root:
python -m mkdocs serve
python -m mkdocs build --strictThe docs workflow
publishes documentation changes from master to gh-pages. For first-time
setup, choose Deploy from a branch and gh-pages under GitHub
Settings → Pages.
import gridforge as gf
import pandas as pd
case = gf.load_case("case14")
bus = case["bus"]
solar = pd.DataFrame({"BUS_IDX": [2, 6], "PG": [20.0, 30.0]})
case.add_component("solar", solar)
solar_by_bus_mw = case.connection_matrix("solar") @ case["solar"]["PG"].to_numpy()
dc = case.dc_model()
ac = case.ac_model()
print(solar_by_bus_mw, dc.ptdf.shape, ac.Ybus.shape)Export the standard electrical model as a standalone, NumPy-only PYPOWER case file:
case.to_python("case_custom.py")The file defines case_custom() and can be loaded with ordinary Python,
PYPOWER or GridForge. Standard numeric values retain full precision;
custom component tables and metadata are omitted. Existing files are
protected unless overwrite=True.
For a complete example, see the worked tutorial. The API reference lists the public operations; Cases and Tables defines what each file format preserves. The documentation site covers matrix axes, units, and AC/DC conventions.
GridForge is distributed under the MIT License.
