mmgpy brings the power of MMG mesh adaptation to Python. Generate, optimize, and refine 2D, 3D, and surface meshes with a clean API.
import mmgpy
mesh = mmgpy.read("input.vtk")
mesh.remesh(hmax=0.1)
mesh.save("output.vtk")No installation needed — run directly with uvx:
# Remesh a mesh file
uvx mmgpy input.stl -o output.mesh -hmax 0.1
# Launch the interactive UI
uvx --from "mmgpy[ui]" mmgpy-uipip install mmgpy
# With UI support
pip install "mmgpy[ui]"Using uv?
uv add mmgpy # add to project dependencies
uv pip install mmgpy # install in current environment
uv pip install "mmgpy[ui]" # install with UI support
uv tool install mmgpy # install CLI tools globally
uv tool install "mmgpy[ui]" # install CLI tools + UI globally- Multi-dimensional — 2D triangular, 3D tetrahedral, and surface meshes
- Local refinement — Control mesh density with spheres, boxes, cylinders
- Anisotropic adaptation — Metric tensors for directional refinement
- Level-set discretization — Extract isosurfaces from implicit functions
- Lagrangian motion — Remesh while tracking displacement fields
- PyVista integration — Visualize and convert meshes seamlessly
- 40+ file formats — VTK, STL, OBJ, GMSH, and more
import mmgpy
mesh = mmgpy.read("input.mesh")
result = mesh.remesh(hmax=0.1)
print(f"Quality: {result.quality_mean_before:.2f} → {result.quality_mean_after:.2f}")
mesh.save("output.vtk")mesh = mmgpy.read("input.mesh")
# Fine mesh near a point
mesh.set_size_sphere(center=[0.5, 0.5, 0.5], radius=0.2, size=0.01)
# Fine mesh in a region
mesh.set_size_box(bounds=[[0, 0, 0], [0.3, 0.3, 0.3]], size=0.02)
mesh.remesh(hmax=0.1)from mmgpy import Mmg3DOptions
opts = Mmg3DOptions(hmin=0.01, hmax=0.1, hausd=0.001)
mesh.remesh(opts)
# Or use presets
mesh.remesh(Mmg3DOptions.fine())mesh.plot() # Quick plot with edges
# Or for custom plotting:
import pyvista as pv
plotter = pv.Plotter()
plotter.add_mesh(mesh.vtk, show_edges=True, color="lightblue")
plotter.show()MMG executables are included and available after installation:
# Auto-detect mesh type
mmg input.mesh -o output.mesh -hmax 0.1
# Or use specific commands
mmg3d input.mesh -o output.mesh -hmax 0.1
mmgs surface.stl -o refined.mesh -hausd 0.001
mmg2d domain.mesh -o refined.mesh -hmax 0.05
# Check versions
mmg --versionThe _O3 suffix variants (mmg3d_O3, etc.) are also available for compatibility.
Contributions are welcome! See CONTRIBUTING.md for development setup, coding standards, and the pull request process.
MIT


