Python wrapper for OpenMagnetics
Project description
PyOpenMagnetics - Python Wrapper for OpenMagnetics
PyOpenMagnetics is a Python wrapper for MKF (Magnetics Knowledge Foundation), the simulation engine of OpenMagnetics, providing a comprehensive toolkit for designing and analyzing magnetic components such as transformers and inductors.
Features
- 🧲 Core Database: Access to extensive database of core shapes, materials, and manufacturers
- 🔌 Winding Design: Automatic winding calculations with support for various wire types (round, litz, rectangular, planar)
- 📊 Loss Calculations: Core losses (Steinmetz), winding losses (DC, skin effect, proximity effect)
- 🎯 Design Adviser: Automated recommendations for optimal magnetic designs
- 📈 Signal Processing: Harmonic analysis, waveform processing
- 🖼️ Visualization: SVG plotting of cores, windings, magnetic fields
- 🔧 SPICE Export: Export magnetic components as SPICE subcircuits
Installation
From PyPI (recommended)
pip install PyOpenMagnetics
From Source
git clone https://github.com/OpenMagnetics/PyOpenMagnetics.git
cd PyOpenMagnetics
pip install .
Quick Start
Basic Example: Creating a Core
import PyOpenMagnetics
# Find a core shape by name
shape = PyOpenMagnetics.find_core_shape_by_name("E 42/21/15")
# Find a core material by name
material = PyOpenMagnetics.find_core_material_by_name("3C95")
# Create a core with gapping
core_data = {
"functionalDescription": {
"shape": shape,
"material": material,
"gapping": [{"type": "subtractive", "length": 0.001}], # 1mm gap
"numberStacks": 1
}
}
# Calculate complete core data
core = PyOpenMagnetics.calculate_core_data(core_data, False)
print(f"Effective area: {core['processedDescription']['effectiveParameters']['effectiveArea']} m²")
Design Adviser: Get Magnetic Recommendations
import PyOpenMagnetics
# Define design requirements
inputs = {
"designRequirements": {
"magnetizingInductance": {
"minimum": 100e-6, # 100 µH minimum
"nominal": 110e-6 # 110 µH nominal
},
"turnsRatios": [{"nominal": 5.0}] # 5:1 turns ratio
},
"operatingPoints": [
{
"name": "Nominal",
"conditions": {"ambientTemperature": 25},
"excitationsPerWinding": [
{
"name": "Primary",
"frequency": 100000, # 100 kHz
"current": {
"waveform": {
"data": [0, 1.0, 0],
"time": [0, 5e-6, 10e-6]
}
},
"voltage": {
"waveform": {
"data": [50, 50, -50, -50],
"time": [0, 5e-6, 5e-6, 10e-6]
}
}
}
]
}
]
}
# Process inputs (adds harmonics and validation)
processed_inputs = PyOpenMagnetics.process_inputs(inputs)
# Get magnetic recommendations
# core_mode: "available cores" (stock cores) or "standard cores" (all standard shapes)
result = PyOpenMagnetics.calculate_advised_magnetics(processed_inputs, 5, "standard cores")
# Result format: {"data": [{"mas": {...}, "scoring": float, "scoringPerFilter": {...}}, ...]}
for i, item in enumerate(result["data"]):
mag = item["mas"]["magnetic"]
core = mag["core"]["functionalDescription"]
print(f"{i+1}. {core['shape']['name']} - {core['material']['name']} (score: {item['scoring']:.3f})")
Calculate Core Losses
import PyOpenMagnetics
# Define core and operating point
core_data = {...} # Your core definition
operating_point = {
"name": "Nominal",
"conditions": {"ambientTemperature": 25},
"excitationsPerWinding": [
{
"frequency": 100000,
"magneticFluxDensity": {
"processed": {
"peakToPeak": 0.2, # 200 mT peak-to-peak
"offset": 0
}
}
}
]
}
losses = PyOpenMagnetics.calculate_core_losses(core_data, operating_point, "IGSE")
print(f"Core losses: {losses['coreLosses']} W")
Winding a Coil
import PyOpenMagnetics
# Define coil requirements
coil_functional_description = [
{
"name": "Primary",
"numberTurns": 50,
"numberParallels": 1,
"wire": "Round 0.5 - Grade 1"
},
{
"name": "Secondary",
"numberTurns": 10,
"numberParallels": 3,
"wire": "Round 1.0 - Grade 1"
}
]
# Wind the coil on the core
result = PyOpenMagnetics.wind(core_data, coil_functional_description, bobbin_data, [1, 1], [])
print(f"Winding successful: {result.get('windingResult', 'unknown')}")
Flyback Converter Wizard
PyOpenMagnetics includes a complete flyback converter design wizard. See flyback.py for a full example:
from flyback import design_flyback, create_mas_inputs, get_advised_magnetics
# Define flyback specifications
specs = {
"input_voltage_min": 90,
"input_voltage_max": 375,
"outputs": [{"voltage": 12, "current": 2, "diode_drop": 0.5}],
"switching_frequency": 100000,
"max_duty_cycle": 0.45,
"efficiency": 0.85,
"current_ripple_ratio": 0.4,
"force_dcm": False,
"safety_margin": 0.85,
"ambient_temperature": 40,
"max_drain_source_voltage": None,
}
# Calculate magnetic requirements
design = design_flyback(specs)
print(f"Required inductance: {design['min_inductance']*1e6:.1f} µH")
print(f"Turns ratio: {design['turns_ratios'][0]:.2f}")
# Create inputs for PyOpenMagnetics
inputs = create_mas_inputs(specs, design)
# Get recommended magnetics
magnetics = get_advised_magnetics(inputs, max_results=5)
API Reference
Database Access
| Function | Description |
|---|---|
get_core_materials() |
Get all available core materials |
get_core_shapes() |
Get all available core shapes |
get_wires() |
Get all available wires |
get_bobbins() |
Get all available bobbins |
find_core_material_by_name(name) |
Find core material by name |
find_core_shape_by_name(name) |
Find core shape by name |
find_wire_by_name(name) |
Find wire by name |
Core Calculations
| Function | Description |
|---|---|
calculate_core_data(core, process) |
Calculate complete core data |
calculate_core_gapping(core, gapping) |
Calculate gapping configuration |
calculate_inductance_from_number_turns_and_gapping(...) |
Calculate inductance |
calculate_core_losses(core, operating_point, model) |
Calculate core losses |
Winding Functions
| Function | Description |
|---|---|
wind(core, coil, bobbin, pattern, layers) |
Wind coils on a core |
calculate_winding_losses(...) |
Calculate total winding losses |
calculate_ohmic_losses(...) |
Calculate DC losses |
calculate_skin_effect_losses(...) |
Calculate skin effect losses |
calculate_proximity_effect_losses(...) |
Calculate proximity effect losses |
Design Adviser
| Function | Description |
|---|---|
calculate_advised_cores(inputs, max_results) |
Get recommended cores |
calculate_advised_magnetics(inputs, max, mode) |
Get complete designs |
process_inputs(inputs) |
Process and validate inputs |
Visualization
| Function | Description |
|---|---|
plot_core(core, ...) |
Generate SVG of core |
plot_sections(magnetic, ...) |
Plot winding sections |
plot_layers(magnetic, ...) |
Plot winding layers |
plot_turns(magnetic, ...) |
Plot individual turns |
plot_field(magnetic, ...) |
Plot magnetic field |
Settings
| Function | Description |
|---|---|
get_settings() |
Get current settings |
set_settings(settings) |
Configure settings |
reset_settings() |
Reset to defaults |
SPICE Export
| Function | Description |
|---|---|
export_magnetic_as_subcircuit(magnetic, ...) |
Export as SPICE model |
Core Materials
PyOpenMagnetics includes materials from major manufacturers:
- TDK/EPCOS: N27, N49, N87, N95, N97, etc.
- Ferroxcube: 3C90, 3C94, 3C95, 3F3, 3F4, etc.
- Fair-Rite: Various ferrite materials
- Magnetics Inc.: Powder cores (MPP, High Flux, Kool Mu)
- Micrometals: Iron powder cores
Core Shapes
Supported shape families include:
- E cores: E, EI, EFD, EQ, ER
- ETD/EC cores: ETD, EC
- PQ/PM cores: PQ, PM
- RM cores: RM, RM/ILP
- Toroidal: Various sizes
- Pot cores: P, PT
- U/UI cores: U, UI, UR
- Planar: E-LP, EQ-LP, etc.
Wire Types
- Round enamelled wire: Various AWG and IEC sizes
- Litz wire: Multiple strand configurations
- Rectangular wire: For high-current applications
- Foil: For planar magnetics
- Planar PCB: For integrated designs
Configuration
Use set_settings() to configure:
settings = PyOpenMagnetics.get_settings()
settings["coilAllowMarginTape"] = True
settings["coilWindEvenIfNotFit"] = False
settings["painterNumberPointsX"] = 50
PyOpenMagnetics.set_settings(settings)
Contributing
Contributions are welcome! Please see the OpenMagnetics organization for contribution guidelines.
Documentation
Quick Start
- llms.txt - Comprehensive API reference optimized for AI assistants and quick lookup
- examples/ - Practical example scripts for common design workflows
- PyOpenMagnetics.pyi - Type stubs for IDE autocompletion
Tutorials
- notebooks/ - Interactive Jupyter notebook tutorials with visualizations
- Getting Started - Introduction to PyOpenMagnetics
- Buck Inductor - Complete inductor design workflow
- Core Losses - In-depth core loss analysis
Reference
- docs/errors.md - Common errors and solutions
- docs/performance.md - Performance optimization guide
- docs/compatibility.md - Python/platform version compatibility
Validation
- api/validation.py - Runtime JSON schema validation for inputs
License
This project is licensed under the MIT License - see the LICENSE file for details.
Related Projects
- MKF - C++ magnetics library
- MAS - Magnetic Agnostic Structure schema
- OpenMagnetics Web - Online design tool
References
- Maniktala, S. "Switching Power Supplies A-Z", 2nd Edition
- Basso, C. "Switch-Mode Power Supplies", 2nd Edition
- McLyman, C. "Transformer and Inductor Design Handbook"
Support
For questions and support:
- 🐛 GitHub Issues
- 💬 Discussions
- 📧 Contact the maintainers
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyopenmagnetics-1.2.1.tar.gz.
File metadata
- Download URL: pyopenmagnetics-1.2.1.tar.gz
- Upload date:
- Size: 135.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bef507bb4d835f8082df4a5015866b8a1a714c46538e2ded9212bf7a0c56293d
|
|
| MD5 |
8f1ffb384449dc88410f71c07f901387
|
|
| BLAKE2b-256 |
3339c4d01e18babf63bd3f573c13c431f142440ef6cb68b392e97ce0ea999ad1
|
File details
Details for the file pyopenmagnetics-1.2.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: pyopenmagnetics-1.2.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccb5311f791fe9d3b2dc0efa20a5c65cb3b9e87c2a5872ebffc3fd310eba1ae7
|
|
| MD5 |
b3d491ad482d41152459c165bea194e8
|
|
| BLAKE2b-256 |
b4da701a0f0271753391e0f42919deb825ee99ee3b39390ad004ea6611699f95
|
File details
Details for the file pyopenmagnetics-1.2.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyopenmagnetics-1.2.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.9 MB
- Tags: CPython 3.13, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ef5b7b72a50a33f9c20563501e286a199dd32c48f232f2c5efb7da60953fefa
|
|
| MD5 |
028c4afdae4485e81d8a27ff09811fd9
|
|
| BLAKE2b-256 |
a6ff94e7d800b605acdd0bd1f752883e217ca791053356b4c7813aef418fee5f
|
File details
Details for the file pyopenmagnetics-1.2.1-cp313-cp313-macosx_15_0_arm64.whl.
File metadata
- Download URL: pyopenmagnetics-1.2.1-cp313-cp313-macosx_15_0_arm64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.13, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bd94a4b9fb9794c1e7cc8f19c214a723d36f7e361052db974cd73ca2c3f8156
|
|
| MD5 |
ad4a69061f5a67842c4c15c347482dfd
|
|
| BLAKE2b-256 |
e6bf5d4295bc1764cb0fe9be81f90ccfcdfa1ed068ff2a0f83630d514e18ae56
|
File details
Details for the file pyopenmagnetics-1.2.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: pyopenmagnetics-1.2.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a95d72d178361216fb7650ce17573161a532100dbb6729ce151ff496c7195a3b
|
|
| MD5 |
d81c1de86d8330f11b715b58e4c3929b
|
|
| BLAKE2b-256 |
883f967c1f30840de7d69339c22c5977f13b68bea9db47bea2791cc6ee1f7e07
|
File details
Details for the file pyopenmagnetics-1.2.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyopenmagnetics-1.2.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.9 MB
- Tags: CPython 3.12, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cb1dcccbee1cd7eaa225ed99d38cba41b05197d8efe024182e72de2f411876e
|
|
| MD5 |
946e7ecb7ac43fdea3bd5a5dd36b6254
|
|
| BLAKE2b-256 |
982a5ca05ce5f009cb9fc4a5013f40e934a64eaf427d1d227b15e19853a432b6
|
File details
Details for the file pyopenmagnetics-1.2.1-cp312-cp312-macosx_15_0_arm64.whl.
File metadata
- Download URL: pyopenmagnetics-1.2.1-cp312-cp312-macosx_15_0_arm64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.12, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9094ac87bee46012b21e9cc3d7a0281befc9b54275a53dde9797af4255019916
|
|
| MD5 |
fcf67473c771becdd44cd2b8ec5460a4
|
|
| BLAKE2b-256 |
8470ea1243ff197e45fd08f09c69758b1b247fd7c8f7aadb01c5cbdd80d0a19f
|
File details
Details for the file pyopenmagnetics-1.2.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: pyopenmagnetics-1.2.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c19371e40358acf008780160024e1759c42ee0442e58968f61ad94b097babced
|
|
| MD5 |
fcc79d2cfc492e0e1154a5b85e956852
|
|
| BLAKE2b-256 |
30946e4eb5010d2113528ab246e7dc1d2676bbaea5f8e764028f8627dc3bd791
|
File details
Details for the file pyopenmagnetics-1.2.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyopenmagnetics-1.2.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.9 MB
- Tags: CPython 3.11, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7adb0a72d09267c1270df020cf855d871bd9a6576d66a54219135760df7a5bb3
|
|
| MD5 |
1c1df0f018ff109ea6cd878a52a5e659
|
|
| BLAKE2b-256 |
6989503747302f823dfdb34da75360833a63f7fff888429c6c0676a3b7d4bb12
|
File details
Details for the file pyopenmagnetics-1.2.1-cp311-cp311-macosx_15_0_arm64.whl.
File metadata
- Download URL: pyopenmagnetics-1.2.1-cp311-cp311-macosx_15_0_arm64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.11, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d3c4a9ac753dfffa07fe048f4eabcaa1b536cfe8f7cb2fd61f13ed9b209f63c
|
|
| MD5 |
2ab4860c6704bea983915b5914162ea7
|
|
| BLAKE2b-256 |
a4686495e60c631ebb08800fdf5605e091cf96d3d19c8412cba0709f7af30929
|
File details
Details for the file pyopenmagnetics-1.2.1-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: pyopenmagnetics-1.2.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e1ae59d327b8408cd26a2232a73fb053d0a879191203f4bb9c4c87863f91f9e
|
|
| MD5 |
9dc20c99c2ba9d12abe7a89f0abf160f
|
|
| BLAKE2b-256 |
1e5f2956670801cb55760be50dda95a8e191951bd0e9caf70c3c482cc45ba084
|
File details
Details for the file pyopenmagnetics-1.2.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyopenmagnetics-1.2.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 4.9 MB
- Tags: CPython 3.10, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0efd981c7de45064e7ae661dbd44caf044620597ccc8207302184bf1eeea51d
|
|
| MD5 |
9d2b684a010222ebb527cfdf0bd3faaa
|
|
| BLAKE2b-256 |
d0ae48d58884cef4a5af29f566d65d0207da24e1829bc0ab5172796dd5e76c9c
|
File details
Details for the file pyopenmagnetics-1.2.1-cp310-cp310-macosx_15_0_arm64.whl.
File metadata
- Download URL: pyopenmagnetics-1.2.1-cp310-cp310-macosx_15_0_arm64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.10, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
272597d4aaa8b3688568050ef84c011efdfffa872fc0fd320781472d12d72e46
|
|
| MD5 |
2f8afdfb3dd30cbfcbdc11b218885799
|
|
| BLAKE2b-256 |
bd5998d79966607e7225c3644dcc2f131cf48e3378686796d9f68470c3ab3193
|