Create, read, validate, and inspect LEGO models in Python using the LDraw format. Python 3.12–3.14 is supported.
uv add pyldraw3Build a model directly from LDraw part codes. Construction and file I/O do not require a downloaded parts library:
from pathlib import Path
from ldraw import Matrix, Model, Piece, Vector
from ldraw.units import BRICK_HEIGHT
model = Model(name="scene.ldr")
model.add(Piece.place("3001", colour=4))
model.add(
Piece.place(
"3001",
colour=14,
position=Vector(0, -BRICK_HEIGHT, 0),
matrix=Matrix.rotation(y=90),
)
)
model.save(Path("scene.ldr"))For catalog searches, geometry, and connections, download a library and load it through a session:
uv run ldraw download --yesfrom ldraw import LDrawSession
parts = LDrawSession().load()
brick = parts.get_entry_by_description("Brick 1 x 1")
print(brick.code)
print(parts.bounding_box(brick.code))Generated ldraw.library.* names remain available after uv run ldraw generate --yes.
- Guide: construction, transformations, submodels, geometry, and session setup.
- CLI reference: validation, BOM and inventory comparison, inspection, previews, and instruction exports.
- API reference: public types and functions.
- Examples and upgrade guides.
- pyldraw3-tui: interactive catalog browsing and model inspection.
uv sync --all-groups --locked
source .venv/bin/activate
uv run pytest
uv run pytest --cov=ldraw --cov-config=pyproject.toml
uv run ruff check .
uv run ruff format --check .
uv run python scripts/check_function_budget.py
uv run zensical build --clean --strictSee CONTRIBUTING.md for integration tests, snapshot regeneration, coverage policy, and performance measurements.
For manual comparisons between Git tags or against your working files, see API compatibility checks.
This project is licensed under the GNU General Public License v3.0 or later - see the license (COPYING) file for details.
pyldraw, a Python package for creating LDraw format files.
Copyright (C) 2008 David Boddie <[email protected]>
Some parts Copyright (C) 2021 Matthieu Berthomé <[email protected]>
Some parts Copyright (C) 2025 Harold Martin <[email protected]>
LDraw is a trademark of the Estate of James Jessiman. LEGO is a registered trademark of the LEGO Group.
- Original Author: David Boddie
- Previous Maintainer: Matthieu Berthomé
- Current Maintainer: Harold Martin
This repository was extracted from the original Mercurial repository and modernized for current Python practices.