Skip to content

About

Resources

Code of conduct

Contributing

Stars

2 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

562 Commits

Folders and files

Repository files navigation

pyldraw3

PyPI Lint and Test Codecov Ruff Formatter: Ruff

Create, read, validate, and inspect LEGO models in Python using the LDraw format. Python 3.12–3.14 is supported.

Quick start

uv add pyldraw3

Build 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 --yes
from 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.

Workflows

Development

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 --strict

See 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.

License

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]>

Trademarks

LDraw is a trademark of the Estate of James Jessiman. LEGO is a registered trademark of the LEGO Group.

Credits

This repository was extracted from the original Mercurial repository and modernized for current Python practices.

About

Resources

Code of conduct

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages