Skip to content

gmshparser

Python CI - Status PyPI - Version PyPI - Downloads Coverage Status Documentation Status

A lightweight Python package for parsing Gmsh .msh mesh files

Package author: Jukka Aho (@ahojukka5)

Overview

gmshparser is a small Python package designed to do one thing well: parse Gmsh mesh file formats. With no external dependencies and a clean API, it provides a simple stand-alone solution for importing meshes into your FEM research code.

Key Features

  • Multiple format support: MSH 1.0, 2.0, 2.1, 2.2, 4.0, and 4.1
  • Automatic version detection: No need to specify format version
  • Zero dependencies: Pure Python implementation
  • 100% test coverage: Thoroughly tested and documented
  • Command-line interface: Extract mesh data from terminal
  • Easy visualization: Built-in matplotlib helpers

Quick Start

Install the package:

pip install gmshparser

Parse a mesh file:

import gmshparser

mesh = gmshparser.parse("mesh.msh")
print(f"Loaded mesh with {mesh.get_number_of_nodes()} nodes "
      f"and {mesh.get_number_of_elements()} elements")

Supported Formats

gmshparser supports all major versions of the Gmsh MSH file format:

Version Description Status
MSH 1.0 Legacy format with $NOD/$ELM sections ✅ Supported
MSH 2.0 Standard format with $MeshFormat ✅ Supported
MSH 2.1 Added $PhysicalNames support ✅ Supported
MSH 2.2 Compatible with 2.0/2.1 ✅ Supported
MSH 4.0 Modern format with $Entities ✅ Supported
MSH 4.1 Latest version ✅ Supported

Documentation Sections

User Guide

Learn how to install, use, and visualize meshes with gmshparser.

Developer Guide

Contribute to the project, understand the architecture, and write custom parsers.

API Reference

Complete API documentation for all classes and functions.

Quick Example

import gmshparser

# Parse mesh file
mesh = gmshparser.parse("data/testmesh.msh")

# Access nodes
for entity in mesh.get_node_entities():
    for node in entity.get_nodes():
        print(f"Node {node.get_tag()}: {node.get_coordinates()}")

# Access elements
for entity in mesh.get_element_entities():
    for element in entity.get_elements():
        print(f"Element {element.get_tag()}: {element.get_connectivity()}")

Contributing

Contributions are always welcome! Please see our Contributing Guide for details on how to get started.