A collection of Python scripts and Jupyter notebooks that demonstrate how to use PyBaMM. For further examples, see the PyBaMM case studies GitHub repository.

For new users we recommend the Getting Started notebooks. These are intended to be very simple step-by-step guides to show the basic functionality of PyBaMM. For more detailed notebooks, please see the examples listed below.

You may run the notebooks in Google Colab.

This page contains a number of examples showing how to use PyBaMM. Each example was created as a Jupyter notebook. These notebooks can be downloaded and used locally by running

$ jupyter notebook

from your local PyBaMM repository or used online through Google Colab. Alternatively, you can simply copy/paste the relevant code.

Using PyBaMM#

The easiest way to start with PyBaMM is by running and comparing some of the inbuilt models:

It is also easy to add new models or change the setting that are used:

Expression tree structure#

PyBaMM is built around an expression tree structure.

The following notebooks are specific to different stages of the PyBaMM pipeline, such as choosing a model, spatial method, or solver.


Several battery models are implemented and can easily be used or compared. The notebooks below show the solution of each individual model.

Once you are comfortable with the expression tree structure, a good starting point to understand the models in PyBaMM is to take a look at

the basic SPM and basic DFN,

since these define the entire model (variables, equations, initial and boundary conditions, events) in a single class and so are easier to understand. However, we recommend that you subsequently use the full models as they offer much greater flexibility for coupling different physical effects and visualising a greater range of variables.

Lithium-ion models#

Lead-acid models#

Spatial Methods#

The following spatial methods are implemented

  • Finite Volumes (1D only)

  • Spectral Volumes (1D only)

  • Finite Elements (only for 2D current collector domains)


The following notebooks show examples for generic ODE and DAE solvers. Several solvers are implemented in PyBaMM and we encourage users to try different ones to find the most appropriate one for their models.