What is Magpylib ?#
Magpylib is a Python package for calculating 3D static magnetic fields of permanent magnets, currents and other sources. The computation is based on analytical expressions and therefore extremely fast. A user friendly API combined with graphic output enables convenient positioning of sources and observers.

Quickstart#
Magpylib is on PyPI and conda-forge. Install using pip (pip install magpylib
) or conda (conda install magpylib
) package managers.
The following Example code outlines the core functionality:
import magpylib as magpy
source = magpy.magnet.Cylinder(magnetization=(0,0,350), dimension=(4,5), position=(1,2,3))
observer = (4,4,4)
B = source.getB(observer)
print(B)
# out: [ 10.30092924 6.86728616 -20.96623472]
Here, a cylinder shaped permanent magnet with (diameter, height) of (4, 5) millimeters is created in a global coordinate system at position (1,2,3). The magnetization is homogeneous and points in z-direction with an amplitude of 350 millitesla (=\(\mu_0\times M\)). The B-field is computed at the observer position (4,4,4) and returned in units of millitesla.
FUNCTIONALITY
EXAMPLE GALLERIES
LIBRARY DOCSTRINGS
CHANGELOG
- Releases
- 4.2.0 - 2023-01-27
- 4.1.2 - 2023-01-15
- 4.1.1 - 2022-08-11
- 4.1.0 - 2022-08-08
- 4.0.4 - 2022-06-09
- 4.0.3 - 2022-05-13
- 4.0.2 - 2022-05-04
- 4.0.1 - 2022-04-29
- 4.0.0 - 2022-04-14
- 3.0.5 - 2022-04-26
- 3.0.4 - 2022-02-17
- 3.0.3 - 2022-02-17
- 3.0.2 - 2021-06-27
- 3.0.1 - 2021-06-27
- 3.0.0 - 2021-06-27
- 2.3.0b - 2020-01-17
- 2.1.0b - 2019-12-06
- 2.0.0b - 2019-11-29
- 1.2.1b0 - 2019-07-31
- 1.2.0b0 - 2019-07-16
- 1.1.1b0 - 2019-06-25
- 1.1.0b0 - 2019-06-14
- 1.0.2b0 - 2019-05-29
- 1.0.1b0 - 2019-05-28
- 1.0.0b0 - 2019-05-21