v0.4.1 — now with GPU-accelerated integration

Kinematic simulation for
rotating assemblies

Molenspin is a Python library for building, simulating, and exporting multi-body kinematic models. Designed around gear trains, windmill linkages, and cam mechanisms — but general enough for anything that spins.

$ pip install molenspin
Abstract visualization of rotating mechanical components

Everything you need to model rotational mechanics

From a simple planetary gear set to a full Dutch windmill drivetrain.

Constraint-based kinematics

Define joints, gear ratios, and fixed pivots declaratively. The solver handles the rest.

Time-step integration

Runge-Kutta and Verlet integrators built in. Swap them with a single keyword argument.

SVG & JSON export

Export frame-by-frame SVG animations or machine-readable JSON timeseries for post-processing.

Pure Python, Rust core

Clean Python API. The inner loop is a compiled Rust extension — benchmarks here.

Quick example

A three-stage gear train in under 20 lines.

import molenspin as ms

asm = ms.Assembly()

# input shaft — 1800 rpm
shaft_in = asm.add_shaft(omega_rpm=1800, name="motor")

# stage 1: 18→72 tooth reduction (ratio 4:1)
g1a = asm.add_gear(teeth=18, driven_by=shaft_in)
g1b = asm.add_gear(teeth=72, meshes_with=g1a)

# stage 2: 24→96 (ratio 4:1)
g2a = asm.add_gear(teeth=24, driven_by=g1b.shaft)
g2b = asm.add_gear(teeth=96, meshes_with=g2a)

# simulate 2 seconds, 1 kHz sample rate
result = asm.simulate(duration=2.0, dt=1e-3)

print(result.shafts["motor"].omega_history[-1])  # 1800.0 rad/s equiv
print(result.shafts[g2b.shaft].omega_rpm)         # 112.5 rpm

result.export_svg("output.svg", fps=24)
Terminal showing molenspin simulation output

Recent posts

All posts →