Skip to main content

Python wrapper for LDraw library.

Project description

pyldraw3

PyPI Lint and Test Coverage Status Ruff Code style: black

A modern Python package for creating and manipulating LDraw format files - the standard for CAD applications that create LEGO models. It is a drop-in replacement for the unmaintained pyldraw library.

Features

  • 🧱 Complete LDraw Support: Full compatibility with the LDraw standard format
  • 🐍 Pythonic API: Import LEGO parts directly as Python modules
  • 📦 Dynamic Library Generation: Automatically generate Python modules from LDraw libraries
  • 📜 Comprehensive Guide: Jump into example or the quick start below, or read a detailed usage guide

Table of Contents

Quick Start

Installation

uv add pyldraw3

Setup

Activate your virtual environment and set up the LDraw library - this will download the LDraw library and create the parts classes:

source .venv/bin/activate
ldraw

Examples

Check the examples/ directory for sample scripts demonstrating various features:

# Run an example
python examples/figures.py > my_model.ldr

Basic Usage

This package allows users to create LDraw scene descriptions using Pieces which are Parts that have a specific position and orientation.

from ldraw.library.colours import Light_Grey
from ldraw.library.parts.minifig.accessories import Seat2X2
from ldraw.library.parts.bricks import Brick1X2WithClassicSpaceLogoPattern
from ldraw.pieces import Piece
from ldraw.geometry import Vector, Identity

# Create a simple model
rover = group()
Piece(Light_Grey, Vector(-10, -32, -90), Identity(), "3957a", rover)

You can also reference parts by their LDraw codes:

from ldraw.parts import Parts

parts = Parts("parts.lst")
cowboy_hat = parts.minifig.hats["Hat Cowboy"]
head = parts.minifig.heads["Head with Solid Stud"]
brick1x1 = parts.others["Brick  1 x  1"]

Requirements

  • Python 3.12+

Development

This project uses uv for dependency management and packaging.

Setup Development Environment

# Clone the repository
git clone https://github.com/rienafairefr/python-ldraw.git
cd python-ldraw

# Install dependencies
uv sync

# Activate virtual environment
source .venv/bin/activate

# Download and set up LDraw library
uv run ldraw

Development Commands

# Run tests
uv run pytest                 # All tests
uv run pytest --cov=ldraw     # With coverage
uv run pytest --integration   # Integration tests only

# Code formatting and linting
uv run black .               # Format code
uv run ruff check            # Lint code
uv run ruff check --fix      # Fix linting issues

# Build package
uv build

Architecture

Core Components

  • CLI Interface (ldraw/cli.py): Command-line interface for library management
  • Dynamic Library Generation (ldraw/generation/): Converts LDraw libraries to Python modules
  • Import System (ldraw/imports.py): Custom meta path hook for dynamic imports
  • Writers (ldraw/writers/): Export to various formats (PNG, SVG, POV-Ray)
  • Tools (ldraw/tools/): Command-line conversion utilities

Key Classes

  • Parts - Manages parts catalog and loading
  • Piece - Represents individual LEGO pieces in models
  • Figure - High-level minifigure construction
  • Geometry classes - Matrix operations and 3D mathematics

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests and ensure they pass (uv run pytest)
  5. Format your code (uv run black .)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

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 <david@boddie.org.uk>
Some parts Copyright (C) 2021 Matthieu Berthomé <matthieu@mmea.fr>
Some parts Copyright (C) 2025 Harold Martin <harold.martin@gmail.com>

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.

Project details


Download files

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

Source Distribution

pyldraw3-0.11.0.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

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

pyldraw3-0.11.0-py3-none-any.whl (38.9 kB view details)

Uploaded Python 3

File details

Details for the file pyldraw3-0.11.0.tar.gz.

File metadata

  • Download URL: pyldraw3-0.11.0.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyldraw3-0.11.0.tar.gz
Algorithm Hash digest
SHA256 165d8ece704370552c863cd097af58574376188faf083e42021f55c6b0fdd29b
MD5 9f51ce81adedc644a5a5f1e171a602cd
BLAKE2b-256 1a479e19a8d71013839fbbf781cfe7f896dd3a658d24f39949d4418bb615dde9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyldraw3-0.11.0.tar.gz:

Publisher: publish.yml on hbmartin/pyldraw3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyldraw3-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: pyldraw3-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 38.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyldraw3-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9450bb498b9f8637b3549b0d74d332be470ee4edbb6aa4b3ab4bd537dd9e08f6
MD5 b9360ff542f35315d474c43e6532856b
BLAKE2b-256 d0a4a9f78d017aa1562ed269577971d30c94f12c3851971284d51e3c4dbaedfc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyldraw3-0.11.0-py3-none-any.whl:

Publisher: publish.yml on hbmartin/pyldraw3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page