Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

magpylib - A simple and user friendly magnetic toolbox for Python 3


Builds:

Documentation:

Test Coverage: Language grade: Python

Downloads: PyPI version Conda Cloud Conda Cloud

What is magpylib ?

  • Python package for calculating magnetic fields of magnets, currents and moments (sources).
  • It provides convenient methods to generate, geometrically manipulate, group and vizualize assemblies of sources.
  • The magnetic fields are determined from underlying (semi-analytical) solutions which results in fast computation times (sub-millisecond) and requires little computation power.

Dependencies:

Python3.6+, Numpy, Matplotlib


Guides & Installation:

Please check out our documentation for getting started and more info!

Quickstart:

Installing this project using pip:

  • run the following in your Python environment terminal:
    pip install magpylib
    

Installing this project locally:

  • Clone this repository to your machine.
  • In the directory, run pip install . in your conda terminal.

Example:

  • Two permanent magnets with axial magnetization are created and geometrically manipulated. They are grouped in a single collection and the system geometry is displayed using a supplied method.
  • The total magnetic field that is generated by the collection is calculated on a grid in the xz-plane and is displayed using matplotlib.

Program output:

Code:

# imports
import numpy as np
import matplotlib.pyplot as plt
import magpylib as magpy
 
# create magnets
magnet1 = magpy.source.magnet.Box(mag=[0,0,600],dim=[3,3,3],pos=[-4,0,3])
magnet2 = magpy.source.magnet.Cylinder(mag=[0,0,500], dim=[3,5], pos=[0,0,0])

# manipulate magnets
magnet1.rotate(45,[0,1,0],anchor=[0,0,0])
magnet2.move([5,0,-4])

# collect magnets
pmc = magpy.Collection(magnet1,magnet2)

# display system geometry
pmc.displaySystem()

# calculate B-fields on a grid
xs = np.linspace(-10,10,20)
zs = np.linspace(-10,10,20)
Bs = np.array([[pmc.getB([x,0,z]) for x in xs] for z in zs])

# display fields using matplotlib
fig, ax = plt.subplots()
X,Y = np.meshgrid(xs,zs)
U,V = Bs[:,:,0], Bs[:,:,2]
ax.streamplot(X, Y, U, V, color=np.log(U**2+V**2), density=1.5)
plt.show() 

Release files for magpylib 1.2.1b0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for magpylib 1.2.1b0
File Size Uploaded
magpylib-1.2.1b0.tar.gz 63.1 kB Details

Release files / magpylib-1.2.1b0.tar.gz

Download URL magpylib-1.2.1b0.tar.gz
Size 63.1 kB
Tags Source
SHA-256 checksum
How to use checksums
cb202ed45c06c136371117d9c64e7ef9fdf6698776d12d8f18117cb20f7d073e
BLAKE2b-256 checksum
How to use checksums
697cff24793e63159aec0be955e13b3dee5ba0da9a2403d0fdf975aebcda2eee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.4

Release history Release notifications | RSS feed

5.2.3

2 release files

5.2.2

2 release files

5.2.1

2 release files

5.2.0

2 release files

5.1.1

2 release files

5.1.0

2 release files

5.0.4

2 release files

5.0.3

2 release files

5.0.2

2 release files

5.0.1

2 release files

5.0.0

2 release files

4.5.1

2 release files

4.5.0

2 release files

4.4.1

2 release files

4.4.0

2 release files

4.3.0

2 release files

4.2.0

2 release files

4.1.2

1 release file

4.1.1

1 release file

4.1.0

1 release file

4.0.4

1 release file

4.0.3

1 release file

4.0.2

1 release file

4.0.1

1 release file

4.0.0

1 release file

3.0.5

1 release file

3.0.4

1 release file

3.0.2

1 release file

This release

1.2.1b0 This release

1 release file

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