cq-cli is a Command Line Interface for executing CadQuery scripts and converting their output to various formats (STEP, STL, DXF, SVG, GLB, GLTF, ThreeJS). It is designed to be used in automation pipelines and supports stdin/stdout streams.
The project is built around the CadQuery Gateway Interface (CQGI).
- Entry Point:
src/cq_cli/main.pyhandles argument parsing, script loading, and coordination between CQGI and codecs. - Plugin System: Codecs are dynamically loaded from
src/cq_cli/cqcodecs/byloader.py. Any file matchingcq_codec_*.pyis treated as a codec. - FreeCAD Support: Integrates
cadquery_freecad_import_pluginto handle.fcstdfiles.
- Language: Python 3.11+
- Core Library: CadQuery
- Environment Management:
uv(preferred) - Build Tool: PyInstaller (for standalone binaries)
- Testing:
pytest
- Install Dependencies:
uv sync - Run CLI (Development):
python -m cq_cli.main --help - Run Tests:
pytest - Linting:
black==26.3.1,click==8.3.1(dev dependencies inpyproject.toml)
- Convert to STEP:
cq-cli --codec step --infile model.py --outfile model.step - Auto-detect Codec:
cq-cli --infile model.py --outfile model.stl - Extract Parameters:
cq-cli --getparams true --infile model.py - Pass Parameters:
cq-cli --params "width:10;height:20" --infile model.py - Evaluate Expression:
cq-cli --expression "my_part(10)" --infile models.py
- PyInstaller (One-file):
pyinstaller cq-cli_pyinstaller.spec onefile - PyInstaller (Directory):
pyinstaller cq-cli_pyinstaller.spec dir
- Create
src/cq_cli/cqcodecs/cq_codec_[name].py. - Implement a
convertfunction:def convert(build_result, outfile, errfile, output_opts): # build_result is a cqgi.BuildResult # Return string/bytes for writing to outfile (or stdout) # Return None if the codec writes directly to outfile
- Add the new codec to
hiddenimportsincq-cli_pyinstaller.specfor standalone builds. - Add a test in
tests/test_[name]_codec.py.
- 0: Success
- 1: Input file read error
- 2: Usage/Argument error
- 3: Missing/Invalid codec
- 100: CadQuery build error (script execution failure)
- 200: Codec conversion error
Tests are located in the tests/ directory and use pytest. Many tests rely on tests/test_helpers.py for CLI invocation and tests/testdata/ for sample scripts.