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.

  • Data in, data out. No I/O: a client hands in the plant's configuration (plant/2) and its inputs as time series (prices, PV and load forecasts, the meters), and gets prices, regimes, certainties and surplus back.
  • The plant model takes its topology as configuration: 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.

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. microgrid.cli reads the files; the engine still does no I/O. 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.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 microgrid 0.1.0
File Size Uploaded Provenance Actions
microgrid-0.1.0.tar.gz 449.0 kB Without provenance Details for microgrid-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 672.5 kB

Release files / microgrid-0.1.0.tar.gz

Download URL microgrid-0.1.0.tar.gz
Size 449.0 kB
Tags Source
SHA-256 checksum
How to use checksums
be5b883ead4065f3178aab1e26e79e6a706b96b9357553e29d57d4c811a2202f
BLAKE2b-256 checksum
How to use checksums
69397bdf41d3c9fb6f804bfa9f79ecacc2ccd760937eb203d517941c1ee71fec
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.0-py3-none-any.whl

Download URL microgrid-0.1.0-py3-none-any.whl
Size 223.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b694b0edb7a60dec60996727b08d0d76b1258088d4c51ff6722cf60cbb407d9d
BLAKE2b-256 checksum
How to use checksums
c2e04d6a34aec1cbf75c772eed628cce7f8d09a50e288e4131a1c8e55cacf75d
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.0

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