Skip to main content

PyBaMM

Python Battery Mathematical Modelling — an open-source library for fast, flexible physics-based battery simulation.

import pybamm

model = pybamm.lithium_ion.DFN()   # Doyle-Fuller-Newman model
sim = pybamm.Simulation(model)
sim.solve([0, 3600])               # solve for 1 hour
sim.plot()

Why PyBaMM?

PyBaMM accelerates battery modelling research by providing open-source tools for multi-institutional, interdisciplinary collaboration. It delivers:
  • A framework for writing and solving systems of differential equations
  • A library of battery models (SPM, SPMe, DFN, MPM, MSMR, ECM, and more)
  • Specialized tools for simulating battery experiments and visualizing results

Get Started

Run your first battery simulation in minutes with the quickstart guide.

Installation

Install PyBaMM via pip or conda on Linux, macOS, or Windows.

Battery Models

Explore physics-based models for lithium-ion, lead-acid, sodium-ion, and more.

API Reference

Comprehensive reference for every class, method, and parameter.

Key capabilities

Physics-based models

DFN, SPM, SPMe, MPM, MSMR — from full-order to reduced-order models.

Multiple solvers

CasADi, IDAKLU, SciPy, and JAX backends for speed and flexibility.

Rich parameter sets

Published parameters for Chen2020, Marquis2019, OKane2022, and many more.

Experiment definition

Define CC, CV, rest, and hold steps with plain-text experiment strings.

Batch studies

Sweep parameters and compare models with BatchStudy.

Interactive plots

Built-in QuickPlot with interactive visualization of any model variable.

Quick example

Run a constant-current/constant-voltage charge cycle:
import pybamm

experiment = pybamm.Experiment(
    [
        (
            "Discharge at C/10 for 10 hours or until 3.3 V",
            "Rest for 1 hour",
            "Charge at 1 A until 4.1 V",
            "Hold at 4.1 V until 50 mA",
            "Rest for 1 hour",
        )
    ]
    * 3,
)
model = pybamm.lithium_ion.DFN()
sim = pybamm.Simulation(model, experiment=experiment)
sim.solve()
sim.plot()

Supported battery chemistries

Lithium-ion

SPM, SPMe, DFN, MPM, MSMR, Newman-Tobias, Yang2017 — full suite of Li-ion models.

Lead-acid

Isothermal porous-electrode and quasi-static models for lead-acid batteries.

Equivalent circuit

Thevenin and other ECM models for fast, empirical simulation.

Sodium-ion

Physics-based models adapted for sodium-ion chemistries.

Installation

pip install pybamm
PyBaMM is available on Linux, macOS, and Windows for Python 3.10–3.14.
PyBaMM is a NumFOCUS fiscally sponsored project. If PyBaMM is useful in your research, consider citing the paper and making a tax-deductible donation.

Build docs developers (and LLMs) love