Molenspin models rotating mechanical assemblies as constraint graphs, integrates their equations of motion, and exports results as SVG animations or numerical timeseries.
Molenspin started as a tool to simulate a 17th-century Dutch windmill drivetrain — the kind with a wooden gear train that converts slow sail rotation into a fast millstone shaft. That specific problem turned out to be a good generalization target, and the library now handles any assembly where you can describe the topology as a directed graph of rotating bodies connected by gear meshes, belt drives, or fixed links.
The user-facing API is pure Python. The inner loop — constraint solving, numerical integration, geometry layout — is implemented in Rust and compiled to a Python extension via PyO3. On an M-series Mac or a modern Linux box, you can typically integrate a 12-body assembly at 100 kHz sample rate in well under a second.
An Assembly is the top-level container. You add shafts, gears, and constraints to it, then call .simulate().
A Shaft carries an angular velocity. Shafts are the edges in the assembly graph. You can fix a shaft's input velocity, leave it free, or drive it from a parent shaft through a gear mesh.
A Gear belongs to a shaft and meshes with one or more other gears. The gear ratio is determined by tooth counts. Molenspin supports spur gears, helical (approximated), and bevel gear angles.
Constraints enforce relationships between bodies — fixed pivot positions, rolling contact, belt drive ratios, or custom algebraic expressions. See the configuration reference for the full list.
Molenspin is a kinematic and quasi-static simulator. It doesn't model stress, fatigue, lubrication film thickness, or anything that requires finite-element analysis. If you need those, you'll want Abaqus or something at that weight. Molenspin is the thing you reach for when you need to know how fast something spins and where the contact points are, not whether the tooth will break.
New here? Start with the quickstart guide — it builds a working gear train model in about five minutes.
matplotlib for quick inline plots; lxml for faster SVG outputgit clone https://github.com/k-bekker/molenspin
cd molenspin
pip install -e ".[dev]"
Building from source requires a Rust toolchain (stable, 1.76+). maturin is the build backend and is listed as a dev dependency.
Apache 2.0. See LICENSE.txt.