Skip to main content

battwin

The Battery Twin Envelope (BTE): an open specification — plus reference SDK — for expressing and exchanging battery digital twins.

A battery digital twin is, as a data artifact, a composition: an identity, a specification, one or more models, an estimated state, and links to measurement data. Today every platform encapsulates that composition privately. battwin defines it openly, as a small immutable JSON document — the twin envelope — that references existing open standards instead of reinventing them:

BattINFO records ─────┐  (identity & specification, by IRI)
BPX / BattMo params ──┼──▶  Battery Twin Envelope (.twin.json)  ──▶ registries,
BDF datasets & feeds ─┘  (models & data, by reference)               platforms,
                                                                     archives

Envelopes are documents, not engines: how a twin is hosted, simulated, or synchronized is an implementation concern; how it is expressed is a community concern. The full format is defined in SPEC.md.

Documentation: digibatt.github.io/battwin

Installation

pip install battwin

Dependencies: pydantic and jsonschema — nothing else. The optional battwin[shacl] extra (pyshacl) adds a third, SHACL-based validation layer over the JSON-LD rendering.

Quickstart

from battwin import new_envelope, save, validate_file

twin = new_envelope(label="Bench cell 001", chemistry="LFP")
save(twin, "bench-cell-001.twin.json")
assert validate_file("bench-cell-001.twin.json") == []

Updating a twin creates a new, hash-chained version — envelopes are immutable:

from datetime import datetime, timezone
from battwin import StateSnapshot, load, save

v1 = load("bench-cell-001.twin.json")
v2 = v1.next_version(
    state=StateSnapshot(
        as_of=datetime.now(timezone.utc),
        state_of_charge=0.8,
        method="coulomb_counting",
        source_data="data/SINTEF__001__20260707_001.bdf.csv",
    )
)
assert v2.version.previous == v1.content_hash()  # verifiable lineage
save(v2, "bench-cell-001.v2.twin.json")

And from the command line:

battwin init --label "Bench cell 001" --chemistry LFP -o cell.twin.json
battwin validate cell.twin.json
battwin validate --shacl cell.twin.json         # + SHACL shapes layer (battwin[shacl])
battwin show cell.twin.json
battwin diff cell.twin.json cell.v2.twin.json   # checks the version chain
battwin schema                                  # print the packaged JSON Schema
battwin context                                 # print the packaged JSON-LD context

battwin schema and battwin context print the language-neutral contracts to stdout, so non-Python consumers can pull them without touching the SDK.

What's in an envelope

{
  "bte_version": "0.1.1",
  "id": "urn:bte:energizer-cr2032:demo-001",
  "identity":      { "label": "...", "serial_number": "...", "battinfo_iri": "...", "passport_id": "..." },
  "specification": { "battinfo_record": "https://w3id.org/battinfo/cell-spec/...", "chemistry": "Li/MnO2" },
  "models":        [ { "kind": "bpx", "name": "...", "source": "params.bpx.json", "validity": { "...": "..." } } ],
  "state":         { "as_of": "2026-07-07T12:00:00Z", "state_of_charge": 0.82, "energy_throughput_kwh": 0.00013, "equivalent_full_cycles": 0.0006, "method": "coulomb_counting" },
  "data":          [ { "kind": "bdf", "uri": "data/SINTEF__DEMO-001__20260707_001.bdf.csv", "role": "cycling" } ],
  "provenance":    { "created": "...", "created_by": "...", "tool": "battwin/0.4.0" },
  "extensions":    { "lab:fixture_id": "bench-07" },
  "version":       { "number": 2, "previous": "sha256:...", "changed": ["state"], "timestamp": "..." }
}

Vendor- or tool-specific facts that aren't (yet) canonical go in extensions under namespaced keys — see SPEC.md §3.8.

A complete example lives at examples/cr2032.twin.json, and examples/p45b/ carries an openly licensed ECM parameter set for the Molicel INR21700-P45B used by the hands-on tutorials. Envelopes also render as JSON-LD (save(..., jsonld=True)) using the packaged context, so they slot into linked-data pipelines alongside BattINFO — and with the battwin[shacl] extra installed, battwin validate --shacl checks that rendering against the packaged SHACL shapes as a third validation layer.

Non-goals

battwin deliberately does not:

  • run simulations (that's PyBaMM, BattMo, and the platforms built on them);
  • host twins or define sync/REST protocols;
  • manage fleets or tenants;
  • acquire measurement data (see battfeed for source→BDF collection, and the BDF toolchain for files at rest);
  • replace BattINFO, BPX, or BDF — it composes them by reference.

Related projects

Project Role relative to battwin
BattINFO semantic records the envelope references for identity/spec
BDF / batterydf time-series datasets the envelope links in data[]
BPX parameter sets bound in models[]
battfeed collects live source data into the BDF files a twin links

Python support

Python 3.10 – 3.12.

Acknowledgements

EU flag

This project has received support from European Union research and innovation programs under grant agreement 101103997 – DigiBatt.

License

Apache-2.0. See LICENSE and NOTICE.

Download files

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

Source Distribution

battwin-0.4.1.tar.gz (54.2 kB view details)

Uploaded Source

Built Distribution

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

battwin-0.4.1-py3-none-any.whl (45.5 kB view details)

Uploaded Python 3

File details

Details for the file battwin-0.4.1.tar.gz.

File metadata

  • Download URL: battwin-0.4.1.tar.gz
  • Upload date:
  • Size: 54.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for battwin-0.4.1.tar.gz
Algorithm Hash digest
SHA256 3946135216abab4a915746ed447adf6680e7df52379ea2a5efbf073b919ee235
MD5 badbb83352d554f068ac2748fe4e75ad
BLAKE2b-256 1c1f95031a6b0cb18d8c8e0554919b4184804e1156a759bc96699f79936e3d28

See more details on using hashes here.

Provenance

The following attestation bundles were made for battwin-0.4.1.tar.gz:

Publisher: publish.yml on DigiBatt/battwin

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

File details

Details for the file battwin-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: battwin-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 45.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for battwin-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f32996f7a91710f92ebc26ca73cd5c5fecadabbde0236334ceb1ce5e480d17f
MD5 6e4ccb206a037d1ad7a9c4705768cd57
BLAKE2b-256 1817a7129e684f2145bb2678b35b3956a665561892d8edf11fb29975db265063

See more details on using hashes here.

Provenance

The following attestation bundles were made for battwin-0.4.1-py3-none-any.whl:

Publisher: publish.yml on DigiBatt/battwin

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

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 files

0.4.0

2 files

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