Skip to main content

microgrid

microgrid is a library that models a solar + battery plant (microgrid.plant) and produces marginal energy prices from it (microgrid.engine): what one more kWh costs, slot by slot over a horizon, and the value of energy by source. The plant model also stands alone, without the price code.

You describe the plant (plant/2: PV of either coupling, a battery on its own inverter or on a hybrid's DC bus, loads on either bus, the grid's limits and charge windows) and give it its inputs as time series (prices, PV and load forecasts, the meters); it returns prices, regimes, certainties and surplus for each slot.

The documentation is in docs/, published with each release at https://eman.github.io/microgrid/: how the prices are made, the concepts, how-to guides and the reference.

Install

pip install microgrid                # or: uv add microgrid
pip install "microgrid[sources]"     # with the readers of live sources (Home Assistant)

Python 3.14 or later. Before 1.0 a minor release may change a format, the API or the model: pin the minor release you tested with (microgrid ~= 0.1.0, Versions).

The command

microgrid (microgrid.cli, installed with the library) runs it on a dataset (dataset/1: a directory of series and the plant's and engine's files), so it needs no plant at hand. The example dataset (examples/dataset) is one synthetic week of the library's example plant in Europe/Berlin, the DST change on 2026-10-25 inside it:

uv run microgrid value --data examples/dataset --at 2026-10-22T13:00   # one valuation
uv run microgrid live --data examples/dataset --from 2026-10-22T06:00 --to 2026-10-22T20:00
uv run microgrid replay --data examples/dataset --from 2026-10-22 --to 2026-10-25
                                        # valuations scored against the meters
uv run microgrid check-plant --data examples/dataset --from 2026-10-21 --to 2026-10-27
                                        # the plant model against its meters
uv run microgrid ledger --data examples/dataset --from 2026-10-21 --to 2026-10-27
                                        # the battery's lots and their cost split
uv run microgrid fit-battery --data examples/dataset --end 2026-10-28 --days 7
                                        # the battery's conversion, fitted
uv run microgrid config check --data examples/dataset   # its plant/2 and engine/2
uv run microgrid schema                                 # the outputs' schema

With a sources/1 file naming a provider per input (any of several, none assumed; the sources extra, microgrid[sources]), it reads live inputs instead of a dataset:

uv run microgrid sources --sources sources.toml   # what each input is read from, or why not
uv run microgrid now --sources sources.toml       # a valuation now; --save DIR keeps the inputs
uv run microgrid fetch --sources sources.toml --from 2026-10-01 --to 2026-10-08 --out DIR
                                        # what was measured, as a dataset

A time without an offset is the plant's local time (an hour that repeats, the first time; one the clocks skip is refused).

Development

Python 3.14, uv. See AGENTS.md for the rules and conventions.

uv sync                      # .venv with the library and the dev tools
scripts/install-hooks.sh     # pre-push runs the local gate
scripts/ci_local.sh          # ruff, format, mypy --strict, the docs, pytest + coverage

License

MIT: see LICENSE.

Metadata

Release files for microgrid 0.1.2

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

Source distribution (sdist)

Source distribution for microgrid 0.1.2
File Size Uploaded Provenance Actions
microgrid-0.1.2.tar.gz 448.9 kB Without provenance Details for microgrid-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 672.2 kB

Release files / microgrid-0.1.2.tar.gz

Download URL microgrid-0.1.2.tar.gz
Size 448.9 kB
Tags Source
SHA-256 checksum
How to use checksums
69dbadd93359e47e819bca61d23190a977b96f5153a1d65d915cb5f22f4b41a9
BLAKE2b-256 checksum
How to use checksums
07e67d3893526099317b0e6b65123e0efc1a2087995bede3bfc0627f1429f3b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / microgrid-0.1.2-py3-none-any.whl

Download URL microgrid-0.1.2-py3-none-any.whl
Size 223.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
21ee767a2d808871da7080164206277c191d8cf422e3e09b66d010ad7054c83c
BLAKE2b-256 checksum
How to use checksums
6e04f07decdf5c13a04ca9010395bdb435a0412991da4da624abb345e56c6d8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for microgrid 0.1.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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