bdsim simulates dynamic systems expressed as block diagrams, much like Simulink®, except that the diagram is written as Python code rather than drawn. It handles continuous-time, discrete-time and hybrid systems, and the wires between blocks can carry any Python type: scalars, NumPy arrays, dictionaries, or objects such as the SE3 poses from the Spatial Maths Toolbox.
The first two editions of Robotics, Vision & Control, and the MATLAB version of the third, make extensive use of Simulink® models. There was no equivalent in the Python world, so I wrote bdsim for the Python version of the third edition, where it runs all the block-diagram models. Some of the thinking behind it is in this LinkedIn article.
An example
We first sketch the system we want to simulate, here a simple first-order plant under proportional control:

and then write it down, block by block and wire by wire:
import bdsim
sim = bdsim.BDSim()
bd = sim.blockdiagram()
# define the blocks
demand = bd.STEP(T=1, name="demand")
sum = bd.SUM("+-")
gain = bd.GAIN(10)
plant = bd.LTI_SISO(0.5, [2, 1])
scope = bd.SCOPE(styles=["k", "r--"])
# connect the blocks
bd.connect(demand, sum[0], scope[1])
bd.connect(plant, sum[1])
bd.connect(sum, gain)
bd.connect(gain, plant)
bd.connect(plant, scope[0])
bd.compile()
out = sim.run(bd, T=5)Because the model is code, it can be kept in git, compared with diff, generated by a program, tested, and run in batches on a server. There is also a graphical editor, bdedit, for drawing diagrams.
Try it
- Run the example notebooks in your browser, with nothing to install.
- Install it with
pip install bdsim, orpip install bdsim[editor]to include the graphical editor. See the installation guide.
The graphical editor is built with Qt and runs on the desktop. The layout is saved as a JSON file with .bd extension. When this is loaded it creates the objects and wires to form an executable block diagram object.
It’s not Simulink but it’s pretty handy.
Learn more
- The bdsim wiki: tutorials, worked examples and notes on how it works inside.
- Documentation: the reference for every block, class and method.
- A New Python-Based Tool for Simulation of Dynamical Systems, the paper about bdsim in IEEE Control Systems Magazine (submitted version; published version).
- An early LinkedIn post on bdsim development from 2022.
- A hub of other Python-based simulation tools for multiple disciplines, currently over 30 tools.
- Source code on GitHub, and the package on PyPI.
