Skip to main content

Pack OpenSCAD includes into an efficient single file.

Project description

OpenSCAD Packer

PyPI - Version codecov

Pack an OpenSCAD entry file and all its use/include dependencies into a single self-contained .scad file.

Instead of distributing a project as a directory tree of files (and requiring recipients to have the same libraries installed), OpenSCAD Packer bundles everything into one file. It uses tree-shaking to include only the functions and modules that are actually called — directly or transitively — so the output stays lean even when pulling from large libraries.

How it works

  • use <lib.scad> — the library is parsed and only the reachable function and module definitions are inlined. Variables and top-level calls are discarded (matching OpenSCAD's own use semantics).
  • include <file.scad> — function and module definitions are tree-shaken into the output; top-level assignments and module calls are always preserved (they affect variables and rendered geometry).
  • Libraries that cannot be found cause an immediate error with a clear message. Pass extra search directories with -L if your libraries live outside the standard OpenSCAD path.

Installation

Requires Python 3.11+ and uv.

uv tool install openscad-packer

This installs the openscad-packer command globally via uv's tool isolation.

Alternatively, add it as a dependency in your own uv project:

uv add openscad-packer

Usage

openscad-packer pack [OPTIONS] INPUT

Arguments:
  INPUT                   Entry .scad file to pack.

Options:
  -o, --output PATH       Output file. Defaults to stdout.
  -L, --library-path PATH Extra library search directory (repeatable).
  --help

Examples

Pack to a file:

openscad-packer pack my_model.scad -o my_model_packed.scad

Pack to stdout (useful for piping or inspection):

openscad-packer pack my_model.scad

Point to libraries that are not on the standard OpenSCAD path:

openscad-packer pack my_model.scad -o packed.scad -L ./vendor/BOSL2 -L ./vendor/NopSCADlib

Library search order

For each use/include path, the tool searches in this order:

  1. Directories supplied via -L (in the order given)
  2. The directory containing the file that references the library
  3. Directories in the OPENSCADPATH environment variable
  4. The platform default: ~/Documents/OpenSCAD/libraries

Developer guide

Prerequisites

  • Python 3.11 or later
  • uv — used for environment management and running the tool

Clone and set up

git clone https://github.com/NascentMaker/OpenSCAD-Packer.git
cd OpenSCAD-Packer
uv sync --dev

uv sync --dev creates a virtual environment at .venv/, installs all runtime dependencies, and installs the dev group (pytest, pytest-cov, coverage).

Note: uv sync without --dev omits the dev group and will not install pytest.

Run the CLI locally

uv run openscad-packer pack entry.scad -o packed.scad

Run the tests

uv run pytest

Branch coverage is enabled automatically. After the run, an HTML report is written to htmlcov/index.html.

To run a subset of tests:

uv run pytest -v -k "tree_shak"

Project structure

openscad_packer/
    cli.py        # click entry point — pack command
    packer.py     # Packer class: collect phase + assemble phase
    shaker.py     # AST walker, tree-shaking, reachability analysis
    resolver.py   # Library path resolution
tests/
    conftest.py
    test_cli.py
    test_packer.py
    test_resolver.py
    test_shaker.py

Building a distribution

uv build

This produces a wheel and sdist in dist/. To publish to PyPI:

uv publish

License

OpenSCAD Packer is released under the GNU Affero General Public License v3.0.

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

openscad_packer-2026.6.5.tar.gz (45.5 kB view details)

Uploaded Source

Built Distribution

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

openscad_packer-2026.6.5-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file openscad_packer-2026.6.5.tar.gz.

File metadata

  • Download URL: openscad_packer-2026.6.5.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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}

File hashes

Hashes for openscad_packer-2026.6.5.tar.gz
Algorithm Hash digest
SHA256 9914b570fcfc1589dff5284d28819b78e5d90662b82188ab98da2a75ae4def04
MD5 a3add0a00f5b04324d8afc65d14539b0
BLAKE2b-256 d9d3e7450be90cf39f0558b778911d4a1f75cfaa935a9d3ddad39aed6c39eb32

See more details on using hashes here.

File details

Details for the file openscad_packer-2026.6.5-py3-none-any.whl.

File metadata

  • Download URL: openscad_packer-2026.6.5-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","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}

File hashes

Hashes for openscad_packer-2026.6.5-py3-none-any.whl
Algorithm Hash digest
SHA256 070a367fea31027eaf1aaa66de3a3cc2b84da618791eeffca62f6641a61e3f1d
MD5 6a828f79734e363d01c326d5145d63eb
BLAKE2b-256 b55b06bf0f63f5c5f9166de10f42bc016b5a6e66e79f60a6c96ba0fb7e9ac446

See more details on using hashes here.

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