Skip to main content

CadPy — Semantic Assembly Modeling Language for Python

Deterministic, Zero-Coordinate, LLM-Native CAD Engine built on OpenCASCADE (OCCT)

CadPy is a Python CAD library purpose-built for AI/LLM code generation. Instead of hundreds of lines of explicit coordinate math, CadPy lets you describe assemblies declaratively — using semantic mates, anchor ports, and parametric variables — while a pure OpenCASCADE backend produces watertight B-Rep solids.


Why CadPy?

General-purpose 3D CAD libraries (CadQuery, PythonOCC, build123d) are designed for human developers. When LLMs (Claude, GPT, Gemini) generate code with these libraries, common failure modes include:

Problem Impact
High token cost Hundreds of lines for a simple part or assembly
Syntax errors & context loss Complex fluent-API chains cause frequent LLM mistakes
Topological instability Face/edge addressing leads to hallucinated selectors

The Solution: Declarative, LLM-Friendly CAD

[CadPy DSL (LLM Interface)]
         ↓
[CadPy Compiler & IR (Constraint Solver)]
         ↓
[CadPy OCCT Backend (Pure OpenCASCADE Core)]
    ├── B-Rep & Topology Layer (TopoDS_Shape, Faces, Edges)
    ├── Assembly Mates & Joints Engine
    └── Reverse Engineering & Import Engine (STEP/IGES)

Key Features

A. High-Level Assembly & Mates

Instead of placing parts with raw X, Y, Z transforms, use CAD-standard mate constraints:

from CadPy import Assembly

with Assembly("Gearbox", units="mm", material="AlSi10Mg") as asm:
    base = asm.add_box("base_plate", length=100, width=80, height=12)
    base.add_hole("mount_hole", diameter=8.5, depth=0, position=(0, 0))
    
    asm.connect(base.face("top"), "bearing:port:back_face", mate_type="FLUSH")

Result: Eliminates spatial matrix math for the LLM, reduces token usage by ~90%.

B. Built-in Standard Parts Library

Standard industrial components are called with a single line — no modeling from scratch:

from CadPy import Fastener, Bearing, Motor

bolt = Fastener.ISO4762(name="clamp_bolt", size="M8", length=35)
bearing = Bearing.SKF(name="main_bearing", code="608ZZ")
motor = Motor.NEMA17(name="drive_motor")

Result: Components that would cost 1000+ tokens are reduced to 5–10 tokens.

C. Anchor Ports & Semantic Interfaces

Parts carry their own mount points — no guessing coordinates:

asm.connect(motor.port("shaft"), wheel.port("hub"))

Result: Prevents part intersection and clash errors at the API level.

D. Cascading Parametric Variables

Entire assemblies are driven by master parameters:

with Assembly("Gearbox") as asm:
    asm.set_param("box_width", 120)
    # All child parts auto-scale to box_width

Result: Revisions require changing 1 parameter instead of rewriting the entire model (~98% token savings).

E. Reverse Engineering (STEP → Code)

Import existing industrial CAD files and convert them to CadPy code:

from CadPy import STEPReverseEngineer

re = STEPReverseEngineer()
result = re.analyze("gearbox.step")
# → Detected faces, holes, PCD patterns, materials

F. Geometry Validation Engine

All generated geometry is validated before export:

from CadPy import ValidationEngineer

validator = ValidationEngineer()
validator.check_manifold(name, solid)     # Watertight closed solid?
clashes = validator.check_clashes(solids) # Parts intersecting?
feedback = validator.diagnose_for_llm(solids)  # NL feedback for LLM

Result: Errors return structured natural-language feedback (instead of stack traces), enabling the LLM to self-correct.

G. Multi-Format Export

Export to all major CAD and visualization formats:

from CadPy import OCCTBackend

backend = OCCTBackend()
ir = asm.to_ir()
solids = backend.compile(ir)

backend.export_step(ir, "output.step")           # STEP (ISO 10303)
backend.export_stl(ir, "output.stl")             # STL mesh
backend.export_glb(ir, "output.glb")             # glTF/GLB for web
backend.export_technical_drawing(ir, "dwg.svg")  # 2D technical drawing

H. Advanced CAD Operations

  • Sketch Engine: 2D profiles with lines, arcs, circles, and constraints
  • Gear Library: Spur gears, helical gears, rack & pinion
  • Springs: Coil springs, coilovers with damper bodies
  • Loft & Sweep: Complex aerodynamic and organic shapes
  • Boolean Operations: Union, cut, intersection with adaptive fuzzy tolerance
  • Fillet & Chamfer: Edge treatments on B-Rep solids
  • Pattern: Linear and circular pattern arrays
  • Mass Properties: Volume, center of gravity, moments of inertia

Installation

pip install CadPy

Note: CadPy requires cadquery-ocp (OpenCASCADE Python bindings) as a runtime dependency. Install it via:

pip install cadquery-ocp

Quick Start

from CadPy import Assembly, OCCTBackend, ValidationEngineer

# 1. Define assembly declaratively
with Assembly("MyAssembly", units="mm", material="Steel") as asm:
    shaft = asm.add_cylinder("shaft", radius=10, height=100)
    plate = asm.add_box("plate", length=50, width=50, height=5)
    asm.connect(shaft.face("bottom"), plate.face("top"), mate_type="FLUSH")
    ir = asm.to_ir()

# 2. Compile to solid geometry
backend = OCCTBackend()
solids = backend.compile(ir)

# 3. Validate
validator = ValidationEngineer()
for name, solid in solids.items():
    assert validator.check_manifold(name, solid)

# 4. Export
backend.export_step(ir, "my_assembly.step")

Architecture

CadPy/                          # Top-level package (public API)
└── cadi_saml/                   # Core engine
    ├── core/
    │   ├── assembly.py          # Assembly builder & parametric engine
    │   ├── ports.py             # Semantic anchor ports & constraints
    │   └── sketch.py            # 2D sketch engine
    ├── backend/
    │   └── occt_backend.py      # Pure OpenCASCADE compiler & exporters
    ├── ir/
    │   ├── nodes.py             # Intermediate Representation (IR) data model
    │   └── parser.py            # CadPy DSL parser
    ├── std_parts/
    │   ├── fasteners.py         # ISO 4762 bolts, screws
    │   ├── bearings.py          # SKF deep-groove bearings
    │   ├── nuts.py              # DIN 934/985 nuts
    │   ├── washers.py           # DIN 125 washers
    │   ├── profiles.py          # V-Slot aluminum extrusions
    │   ├── motors.py            # NEMA 17/23 stepper motors
    │   └── motorsport.py        # Gears, springs, coilovers
    ├── validation/
    │   └── validation_engineer.py  # Manifold check, clash detection, LLM diagnosis
    └── reverse/
        └── step_importer.py     # STEP reverse engineering

Use Cases

  • LLM-powered CAD generation: Fine-tune or prompt LLMs to produce valid 3D models
  • Parametric design automation: Drive complex assemblies from a few master parameters
  • AI training data: Generate (instruction, code, STEP) triples for model training
  • Rapid prototyping: Build and validate assemblies faster than traditional CAD
  • Reverse engineering: Import STEP files, analyze topology, and generate editable code

License

MIT


Links

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cadpy-0.1.0.tar.gz (91.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cadpy-0.1.0-py3-none-any.whl (71.4 kB view details)

Uploaded Python 3

File details

Details for the file cadpy-0.1.0.tar.gz.

File metadata

  • Download URL: cadpy-0.1.0.tar.gz
  • Upload date:
  • Size: 91.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for cadpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c4a776257bb9733c0f490fba3cb8932df6d74acb641750f8d7fb64cd9231f0c8
MD5 a7fa699c33a951cf32d20c7fb97b8bb3
BLAKE2b-256 60edfe292a53d480649084ff4f1e0da5dc26d904c324455d5c8e588e1676f568

See more details on using hashes here.

File details

Details for the file cadpy-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cadpy-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 71.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for cadpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9e42cea18494776eb3db7e05bb9aee68da03bc9a68bae032ef24d897edc2a6d
MD5 996dbf0c0044e55e4c6cac666c1b4244
BLAKE2b-256 61007b3ba09034e8a669e0060c290189135bbff7e34afc7804133e42bd856ba7

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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