Skip to main content

shapemesh

CI

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

Status: v0.1.0 — initial 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 into more complex shapes with boolean operations such as Union; and label them. Labels become Gmsh physical groups, so after calling build() you can query the elements belonging to each labelled shape.

Features

  • 12 shape primitives: Point, Line, Polyline, Circle, 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.
  • 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.2.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.2.0
File Size Uploaded Provenance Actions
shapemesh-0.2.0.tar.gz 100.6 kB Without provenance Details for shapemesh-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 147.2 kB

Release files / shapemesh-0.2.0.tar.gz

Download URL shapemesh-0.2.0.tar.gz
Size 100.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fa5c6fd8914991ad5844aff25f7e610030291d94db4b92bdb7b6c12c2c725299
BLAKE2b-256 checksum
How to use checksums
80176f98e722fe3b818bf9dd4887e22a8fcd5e638a85a954c2c5dbd1e693fe2e
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.2.0-py3-none-any.whl

Download URL shapemesh-0.2.0-py3-none-any.whl
Size 46.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
476055a0da6b2de9e0eb006845358ad568d70c19b561966df2197b8dd55d721a
BLAKE2b-256 checksum
How to use checksums
e2999137a0c44c173be7f27b86fb1c1e58315d08faa1880ce01647f01afebbaf
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.2.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