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.1

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.1
File Size Uploaded Provenance Actions
microgrid-0.1.1.tar.gz 448.8 kB Without provenance Details for microgrid-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 672.1 kB

Release files / microgrid-0.1.1.tar.gz

Download URL microgrid-0.1.1.tar.gz
Size 448.8 kB
Tags Source
SHA-256 checksum
How to use checksums
62df1b62e9acc3364e9eb4e0d72656b57f0dbdebfea787525d17bd1a6e2dd171
BLAKE2b-256 checksum
How to use checksums
ec3c9cd4048b384b4860af5947ffd68c015f0725853ef5d30a36d619d62c4f8d
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.1-py3-none-any.whl

Download URL microgrid-0.1.1-py3-none-any.whl
Size 223.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a2c9470fcc7a5edb1fbe23f9af1cc84bd322a2603716a2d7f8068fdb4d4374f0
BLAKE2b-256 checksum
How to use checksums
1094864b6b9393c267468da17d50ac855b8db1debe01c44996b1d4dd5ea09fdf
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.1

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