Skip to main content

⚡ EnergyDB

Persistent storage for energy portfolios — assets, grid topology, and 3-dimensional time series, in one connected database.

PyPI Python Versions License Slack


🏗️ What is EnergyDB?

EnergyDB is a database for energy portfolios. It stores three things together in one connected system:

Layer Description Real-World Example
🌳 Asset hierarchy Arbitrary-depth tree of portfolios, sites, and assets "Offshore-1 → WindTurbine T01 → power"
🔗 Grid topology Typed edges (lines, transformers, pipes, interconnections) connecting any two assets "Cable-1: BusA → BusB"
⏱️ 3-dimensional time series Actuals and versioned forecasts attached to any node or edge, queryable as-of any point in time "power_flow on Cable-1, valid Wed 12:00, known Mon 18:00"

Structure lives in PostgreSQL, values live in ClickHouse, and stable UUID identity lets Python objects round-trip to the database without losing any structural state.

EnergyDB extends TimeDB with persistent storage for EnergyDataModel hierarchies.


✨ Why EnergyDB?

Most time-series systems are agnostic about what their series represent — they treat data as opaque (series_id, timestamp, value) triples. EnergyDB knows it is a portfolio, and links every series back to the asset or grid edge it describes.

  • 🔁 Round-trip persistence: Every Element keeps its UUID7 from in-memory object to row primary key — renames, moves, and property edits become silent UPDATEs, never delete-then-insert.
  • 📋 Diffable structural changes: dry_run=True previews every insert, rename, move, and delete before you apply — no surprise data loss on replace_subtree.
  • ⏱️ Time-of-knowledge queries: Forecast revisions, corrections, and as-of backtests, powered by TimeDB.
  • 🧭 Lazy fluent navigation: client.get_node("Portfolio", "Site", "T01").read(...) resolves to one indexed SQL query, regardless of subtree size.
  • ⚖️ Unit conversion at the boundary: Declare canonical units once; pint rescales every read and write automatically.
  • 🧹 Idempotent writes: write(..., skip_unchanged=True) drops rows that only duplicate the latest stored value before insert, so writing the same window repeatedly doesn't bloat storage. Opt-in; the write still returns its run_id (now a WriteResult carrying .written / .skipped counts).

TimeDB demo

🚀 Quick Start

1. Installation

pip install energydb

Requires Python 3.12+, PostgreSQL (asset hierarchy + series catalog), and ClickHouse (time-series values).

Need a local Postgres + ClickHouse? One command brings both up: cd local-db && docker compose up -d (see local-db/, or DEVELOPMENT.md for the full setup).

2. Usage Example

from datetime import UTC, datetime
import energydb as edb
import pandas as pd

client = edb.Client()  # reads TIMEDB_PG_DSN / TIMEDB_CH_URL
client.create()

# 1. Declare your portfolio: a tree of typed assets with their series.
t01 = edb.wind.WindTurbine(
    name="T01", capacity=3.5, hub_height=80,
    timeseries=[edb.TimeSeries(name="power", unit="MW",
                               data_type=edb.DataType.ACTUAL)],
)
portfolio = edb.Portfolio(
    name="my-portfolio",
    members=[edb.Site(name="Offshore-1", members=[t01])],
)
client.register_tree(portfolio)   # create-only; edit existing nodes via scope mutators

# 2. Write hourly power for that turbine.
start = datetime(2026, 1, 1, tzinfo=UTC)
df = pd.DataFrame({
    "valid_time": pd.date_range(start, periods=24, freq="1h", tz="UTC"),
    "value":      [2.5 + 0.05 * i for i in range(24)],
})
client.get_node("my-portfolio", "Offshore-1", "T01").write(
    df, name="power", data_type="actual",
)

# 3. Read across the whole portfolio in one fluent call.
client.get_node("my-portfolio").read(name="power", data_type="actual")

🧪 Try it in Google Colab

Want to try EnergyDB without a local setup? Open our Quickstart in Colab — the first cell automatically installs PostgreSQL + ClickHouse inside the VM.

Open In Colab

Note: Data persists only within the active Colab session. Additional notebooks are available in the examples/ directory.


📚 Documentation & Resources


📦 Related Projects

Project Description
TimeDB 3-dimensional time-series storage on ClickHouse with auditability and overlapping-forecast support
TimeDataModel Pythonic data model for time series
EnergyDataModel Data model for energy assets (solar, wind, battery, grid, ...)

🤝 Contributing

Contributions are welcome! If you're interested in improving EnergyDB, please see our Development Guide for local setup instructions.


Licensed under the Apache-2.0 License.

Find a bug or have a feature request? Open an Issue.

Download files

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

Source Distribution

energydb-0.8.0.tar.gz (120.8 kB view details)

Uploaded Source

Built Distribution

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

energydb-0.8.0-py3-none-any.whl (84.0 kB view details)

Uploaded Python 3

File details

Details for the file energydb-0.8.0.tar.gz.

File metadata

  • Download URL: energydb-0.8.0.tar.gz
  • Upload date:
  • Size: 120.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for energydb-0.8.0.tar.gz
Algorithm Hash digest
SHA256 b69e77f44146575da5ca372d974f3cd877fde9077bc4c3c142a2355559575f42
MD5 6086341e32f15c41571ace6531f60c66
BLAKE2b-256 7b7819189169defccb4952e0bb34f28325cffebf5904a0ccd1c423bdd2d836bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for energydb-0.8.0.tar.gz:

Publisher: publish.yml on rebase-energy/energydb

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

File details

Details for the file energydb-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: energydb-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 84.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for energydb-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c1b4694c8398c1edc2651beec308c2ae1232e5f9428fa40ed83576281193d54e
MD5 ef8bd9aeebf5acb6b3b154c140804bc4
BLAKE2b-256 daf3a89e49b34322824a02b727363be70ecd2690c175aa863e28a0105bcfdf2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for energydb-0.8.0-py3-none-any.whl:

Publisher: publish.yml on rebase-energy/energydb

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page