Skip to main content

brepy

Build, export and preview build123d model scripts from the command line.

A model is a Python script with a build() function. brepy runs it, writes the parts to STEP, STL, 3MF or BREP, draws dimensioned preview sheets without a GPU or display, and can show the model in a live viewer that rebuilds on save.

Install

uv tool install "brepy[viewer]"

The viewer extra adds --view and --watch. Leave it out on headless machines. OCP needs the system library libGL.so.1 (Debian: libgl1). Releases are published to PyPI.

A container image with brepy, pytest, ruff and ty preinstalled is published as ghcr.io/brhelwig-dev/brepy:<version> for each release, and as :latest, rebuilt from main on every push and nightly:

docker run --rm -v "$PWD:/work" -w /work ghcr.io/brhelwig-dev/brepy:latest \
    brepy -f step models/bracket/bracket.py

Usage

brepy models/bracket/bracket.py                     # STEP beside the script
brepy -f stl -f 3mf -o out/ models/bracket/bracket.py
brepy -f png models/bracket/bracket.py              # preview sheets
brepy --part lid models/box/box.py                  # one part
brepy -p width=30 models/bracket/bracket.py         # a build() argument
brepy --watch models/bracket/bracket.py             # live preview

The script is imported by its path relative to --root, the current directory by default. models/bracket/bracket.py imports as models.bracket.bracket, so scripts can share code by importing each other or helper modules under the root.

Model scripts

from build123d import Box, Cylinder, Pos

SEPARATE_PRINTS = False


def build(width: float = 40.0) -> dict:
    base = Box(width, 20, 5)
    pin = Pos(0, 0, 5) * Cylinder(3, 10)
    return {"base": base, "pin": pin}


def preview_spec() -> dict:
    return {"parts": {"bracket_base": {"build_up": [0, 0, 1]}}}

build() returns parts by name. A part may itself be a mapping of shells, {"red": shape, "white": shape}, for one print in several colours. Its arguments can be set with -p NAME=VALUE, converted to the annotated type.

Output files are named after the script:

  • one plain part: <name>
  • several parts: <name>_<part> each, plus a combined <name> holding all of them, unless the script sets SEPARATE_PRINTS = True
  • shells: <name>_<part>_<shell> each, plus <name>_<part> holding the shells

Preview sheets

-f png writes one sheet per output file to previews/, with six orthographic views (isometric, underside, front, right, top, bottom) at one shared scale. preview_spec() adds to them:

{
    "parts": {
        "<stem>": {
            "build_up": [0, 0, 1],
            "dimensions": [
                {"label": "pin dia", "view": "top", "a": [-3, 0, 15], "b": [3, 0, 15]},
                {"label": "slot", "view": "front", "a": [...], "b": [...], "detail": "slot"},
            ],
        }
    },
    "assemblies": {
        "<name>": {
            "seat": [
                {"stem": "<stem>", "at": [0, 0, 0], "build_up": [0, 0, 1]},
                {"stem": "../<other model>/<stem>"},
            ],
            "dimensions": [],
        }
    },
}
  • build_up is the direction away from the build plate. With it, faces that would print without support are shaded orange.
  • A dimension is drawn in the view it names, between points a and b. One with a detail name gets its own zoomed, sectioned tile.
  • An assembly places output files, or files from a sibling script (../<other model>/<other model>.py), on one sheet.

When the spec is present, -f step also writes it to preview.json.

Printability

brepy.printability measures a solid the same way the sheets shade it, for use in a model's tests:

from brepy import printability

assert printability.unsupported_area(part, build_up=(0, 0, 1)) < 0.01
assert printability.island_area(part, layer_height=0.2, build_up=(0, 0, 1)) < 0.01

A face is unsupported where it faces down more than 42 degrees from vertical and does not rest on the plate. An island is an area printed in some layer with nothing below it. printability.section(part, z) returns the plan section at height z.

Development

uv sync --extra viewer
uv run pytest
uv run ruff check && uv run ruff format --check
uv run ty check

To release, run the Release workflow from the Actions tab. It versions the release YY.DOY.MMMM (UTC year, day of the year, minute of the day, e.g. 26.287.570), commits and tags it on main, and publishes it to PyPI and ghcr.

License

MIT

Metadata

Release files for brepy 26.292.1014

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for brepy 26.292.1014
File Size Uploaded Provenance Actions
brepy-26.292.1014.tar.gz 126.6 kB Without provenance Details for brepy-26.292.1014.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for brepy 26.292.1014
File Interpreter ABI Platform Actions
brepy-26.292.1014-py3-none-any.whl Python 3 none any Details for brepy-26.292.1014-py3-none-any.whl

Total release size: 149.9 kB

Release files / brepy-26.292.1014.tar.gz

Download URL brepy-26.292.1014.tar.gz
Size 126.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6aeda1aa1661fe988aea1be17cc54f2d7243d4b70d97a150ec4e257746924cf8
BLAKE2b-256 checksum
How to use checksums
2c30df1ffdb2ad2c2e867ab975091ea42c3a3a14df4a72ad218bac04a570c8b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / brepy-26.292.1014-py3-none-any.whl

Download URL brepy-26.292.1014-py3-none-any.whl
Size 23.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3c502a3d62532d31a5387ee456da7746c5d98002b976a6e9309c73675efd305b
BLAKE2b-256 checksum
How to use checksums
e7d32291951529dc1b3098ca1ee5636a616c2f2bf52b1c8f95de7b24a094950c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for brepy 26.292.1014

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

26.292.1014 This release

2 release files No provenance

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