{"id":5319,"library":"meshio","title":"meshio","description":"meshio is a Python library for reading and writing various unstructured mesh formats, facilitating smooth conversion between them. It supports a wide array of formats including Abaqus, ANSYS msh, Gmsh, STL, VTK, XDMF, and many others. Currently at version 5.3.5, meshio is actively maintained with regular updates and requires Python 3.8 or newer. It can be used both as a command-line tool for conversions and as a Python API for programmatic mesh manipulation.","status":"active","version":"5.3.5","language":"en","source_language":"en","source_url":"https://github.com/nschloe/meshio","tags":["mesh","CAD","IO","scientific computing","geometry","finite element","data conversion"],"install":[{"cmd":"pip install meshio","lang":"bash","label":"Core installation"},{"cmd":"pip install meshio[all]","lang":"bash","label":"Installation with all optional dependencies for full format support"}],"dependencies":[{"reason":"Fundamental array manipulation for mesh data.","package":"numpy","optional":false},{"reason":"Required for H5M and XDMF mesh formats.","package":"h5py","optional":true},{"reason":"Required for Netgen mesh formats.","package":"netCDF4","optional":true},{"reason":"Required for some XDMF XML parsing.","package":"lxml","optional":true},{"reason":"Used for rich command-line output from the `meshio` CLI tools.","package":"rich","optional":true}],"imports":[{"symbol":"meshio","correct":"import meshio"}],"quickstart":{"code":"import meshio\nimport numpy as np\n\n# Define points (vertices) of the mesh\npoints = [\n    [0.0, 0.0, 0.0],\n    [1.0, 0.0, 0.0],\n    [0.0, 1.0, 0.0],\n    [1.0, 1.0, 0.0],\n    [2.0, 0.0, 0.0],\n    [2.0, 1.0, 0.0],\n]\n\n# Define cells (elements) of the mesh, grouped by type\n# Here, two triangles and one quad\ncells = [\n    (\"triangle\", np.array([[0, 1, 2], [1, 3, 2]])),\n    (\"quad\", np.array([[1, 4, 5, 3]])),\n]\n\n# Create a Mesh object\nmesh = meshio.Mesh(\n    points,\n    cells,\n    # Optionally provide extra data on points, cells, etc.\n    point_data={\"T\": np.array([0.3, -1.2, 0.5, 0.7, 0.0, -3.0])},\n    # Each item in cell data must match the cells array structure\n    cell_data={\"a\": [np.array([0.1, 0.2]), np.array([0.4])]}\n)\n\n# Write the mesh to a file (format inferred from extension, or explicitly specified)\nmesh.write(\n    \"output.vtk\",\n    # file_format=\"vtk\", # optional, inferred from extension\n    binary=True # Write in binary format (e.g. for VTK)\n)\n\n# Read a mesh from a file\nread_mesh = meshio.read(\"output.vtk\")\n\nprint(f\"Read mesh points:\\n{read_mesh.points}\")\nprint(f\"Read mesh cells:\\n{read_mesh.cells}\")\nprint(f\"Read mesh point data (T):\\n{read_mesh.point_data['T']}\")\nprint(f\"Read mesh cell data (a):\\n{read_mesh.cell_data['a']}\")","lang":"python","description":"This quickstart demonstrates how to create a mesh from points and cells, add associated data (point data, cell data), write it to a VTK file, and then read it back. The `meshio.Mesh` constructor takes points, a list of cell blocks (type and indices), and optional point/cell/field data. The `mesh.write()` method saves the mesh, and `meshio.read()` loads it."},"warnings":[{"fix":"Review and update code that accesses `mesh.cells` or `mesh.cell_data` directly. The structure for `cells` is a list of `(cell_type_string, numpy_array_of_indices)` tuples. Ensure compatibility with meshio's current data structures.","message":"Breaking changes in meshio versions 4.0.0 and newer, particularly concerning the internal representation and handling of mesh.cells, can cause compatibility issues with code written for older versions, especially when interfacing with other finite element libraries like FEniCS.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Install `meshio` with all optional dependencies using `pip install meshio[all]` or install specific dependencies (e.g., `h5py`, `netCDF4`, `lxml`) as needed for the desired formats.","message":"For full support of all advertised mesh formats (e.g., H5M, NetCDF, comprehensive XDMF features), `meshio` requires several optional dependencies. Without these, attempts to read or write specific formats will result in `ModuleNotFoundError` or similar errors.","severity":"gotcha","affected_versions":"All"},{"fix":"Always provide the `cells` argument as a list of `(cell_type_string, numpy_array_of_indices)` tuples. Refer to `meshio` documentation or source for exact cell type strings and expected node ordering for each type (e.g., `meshio._common.num_nodes_per_cell`).","message":"When constructing a `meshio.Mesh` object programmatically, the `cells` argument expects a list of tuples, where each tuple must contain a string identifying the cell type (e.g., \"triangle\", \"quad\", \"tetra\") and a NumPy array of node indices for that cell type. Misunderstanding or incorrectly formatting this can lead to errors, particularly with mixed cell types or incorrect node ordering.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade `meshio` to version 5.3.5 or newer to ensure full compatibility with NumPy 2.0. If an upgrade is not possible, downgrade NumPy to a compatible version (e.g., NumPy 1.x).","message":"Older versions of `meshio` (prior to 5.3.5) exhibited compatibility issues with NumPy 2.0, leading to runtime errors or unexpected behavior.","severity":"breaking","affected_versions":"<5.3.5"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}