Skip to main content

shapemesh

CI

A Gmsh-powered geometry and meshing library: a small, closed set of 0–3D shapes, n-ary booleans, rigid transforms, extrusions, and entity-level MSH 4.1 I/O.

Status: v0.3.0 — latest release.

Why shapemesh?

shapemesh is an easy-to-use wrapper for the powerful Gmsh meshing library. It simplifies creating complex geometries and meshing them into three steps: create primitive 1D to 3D shapes using the Shape primitives — for example a Line, Polygon, or Box; combine them with boolean operations such as Union, rigid transforms such as Translate and Rotate, or extrusions such as Extrude and Revolve; and label them. Labels become Gmsh physical groups, so after calling build() you can query the elements belonging to each labelled shape.

Features

  • 13 shape primitives: Point, Line, Polyline, Circle, CircleArc, Ellipse, Polygon, Rectangle, Disk, EllipticalDisk, Sphere, Box, Cylinder. Missing something? Open an issue — the v1 set is intentionally small.
  • n-ary booleans: Union, Intersection, Difference with variadic or sequence constructors.
  • Rigid transforms: Translate and Rotate compose with primitives and booleans in the immutable shape graph.
  • Extrusions: Extrude, Revolve, and ExtrudeAlong raise a 0D–2D shape's dimension by one. ExtrudeAlong accepts one smooth guide curve or a tangent-continuous Path composed of Line and CircleArc segments, passed variadically or as a single sequence.
  • Overlapping physical groups: labels are preserved across Gmsh fragment remapping, so an intersection volume can belong to multiple groups.
  • MSH 4.1 ASCII I/O: read and write entity-classified meshes, with or without Gmsh running.
  • Typed public API: NumPy-based data model, PEP 561 py.typed marker, and strict Python ≥3.12 typing.

Install

pip install shapemesh

Gmsh (≥4.0) is installed automatically as a runtime dependency. shapemesh is tested against Gmsh 4.15.2.

Quick start

from shapemesh import Box, MeshSettings, build

column = Box(origin=(0, 0, 0), dx=1, dy=1, dz=1, label="column")
mesh = build(shapes=column, settings=MeshSettings())
mesh.write_msh("column.msh")

How it works

shapemesh builds a small scene graph of immutable shapes, hands it to Gmsh, and then remaps the resulting entities back to your labels.

  1. Define shapes. Every primitive takes a label. Labels are not just metadata — they become Gmsh physical groups.
  2. Build. build() realizes the geometry in a fresh Gmsh model, sets mesh settings, and generates the mesh.
  3. Fragment and remap. When shapes overlap, Gmsh fragments them into conformal pieces. shapemesh tracks which output pieces came from which input label and rebuilds the physical groups. A piece that lies in the overlap of two shapes belongs to both groups.
from shapemesh import Box, MeshSettings, build

a = Box(origin=(0, 0, 0), dx=1, dy=1, dz=1, label="a")
b = Box(origin=(0.5, 0, 0), dx=1, dy=1, dz=1, label="b")
mesh = build(shapes=[a, b], settings=MeshSettings())

# Three volume pieces: a-only, overlap, b-only.
assert len(mesh.entities(dim=3)) == 3

# The overlap piece is in both physical groups.
shared = set(mesh.physical_group(name="a", dim=3).entities) & set(
    mesh.physical_group(name="b", dim=3).entities
)
assert len(shared) == 1

This fragment remap is what makes overlapping physical groups work without any manual entity bookkeeping.

Examples

Examples covering structural workflows and element-node data access live in examples/:

Documentation

License

shapemesh is licensed under the GNU Lesser General Public License v3 or later (LGPL-3.0-or-later). See COPYING and COPYING.LESSER for the full texts.

Note on Gmsh: shapemesh itself is LGPL-3.0-or-later. It requires Gmsh as a runtime dependency, and Gmsh is licensed under GPL-2.0-or-later. If you distribute a combined work that includes Gmsh — for example, a closed-source application shipped with shapemesh and Gmsh — Gmsh's copyleft obligations apply to that distribution. Internal or server-side use without distribution is not affected.

Metadata

Release files for shapemesh 0.3.0

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

Source distribution (sdist)

Source distribution for shapemesh 0.3.0
File Size Uploaded Provenance Actions
shapemesh-0.3.0.tar.gz 116.8 kB Without provenance Details for shapemesh-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shapemesh 0.3.0
File Interpreter ABI Platform Actions
shapemesh-0.3.0-py3-none-any.whl Python 3 none any Details for shapemesh-0.3.0-py3-none-any.whl

Total release size: 168.3 kB

Release files / shapemesh-0.3.0.tar.gz

Download URL shapemesh-0.3.0.tar.gz
Size 116.8 kB
Tags Source
SHA-256 checksum
How to use checksums
086b7c71b9aa758a38aa07311adf69c5248beffc5f9d8e2bf0d835708e28b932
BLAKE2b-256 checksum
How to use checksums
66e3471d9079e967c562f3446390bca61ab77873e08a329e063c485a348f2082
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / shapemesh-0.3.0-py3-none-any.whl

Download URL shapemesh-0.3.0-py3-none-any.whl
Size 51.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
84a256eaf5d51340250c2bb4575210d677c76a1079b99c25f63d1cf34a2b3382
BLAKE2b-256 checksum
How to use checksums
2c8138cc334963e7694057762a4c53a8a5ba548ba15e05d52e8d19fb7fb3b184
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for shapemesh 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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