PrusaSlicer-Py
PrusaSlicer-Py is a Python toolkit for automating and extending PrusaSlicer functionality through its command-line interface (CLI). This project aims to simplify slicing workflows, customize G-code generation, and provide a flexible framework for integrating PrusaSlicer into Python-based workflows.
Features
- Automate slicing operations using the PrusaSlicer CLI.
- Customize slicing parameters dynamically.
- Load and manage shapes from
.stlfiles or existing profiles from.3MFor.AMFfiles. - Support for generating G-code with fine-tuned settings for FFF and SLA printers.
Status
Pre-1.0. The API may change; what it establishes will not be overstated.
The full path -- discovery, check_version, generate_help,
get_example_shapes, and a real end-to-end slice_model -- is exercised
against a real PrusaSlicer on every supported install mode, in CI:
| platform | install mode | engine |
|---|---|---|
| Linux | Flathub Flatpak | 2.9.6 |
| Linux | distro package on PATH |
packaged build |
| macOS | Homebrew cask (.app bundle) |
latest cask |
| Windows | official portable .zip on PATH |
2.9.6 |
Those jobs set PRUSASLICER_PY_REQUIRE_ENGINE=1, so a runner that fails to
install the engine fails the job rather than quietly skipping. The CI
workflow separately runs the mocked suite on Linux 3.11/3.12/3.13 and Windows
with no engine present, where the engine tests skip and the log says how many
were withheld (docs/DECISIONS.md D3).
Not covered: SLA workflows beyond --help-sla parsing, and any printer profile
handling beyond passing arguments through.
Finding the engine
PrusaSlicer is located in this order:
- an explicit
slicer_pathyou pass in, prusa-slicer(orprusa-slicer-console.exe) onPATH,- a Flathub Flatpak (
com.prusa3d.PrusaSlicer).
PrusaSlicer().engine_kind tells you which was found. Flatpak support is not
cosmetic: a Flatpak has no binary on PATH, so discovery that only asks PATH
reports "not installed" on the most common Linux install (D9).
Getting Started
Prerequisites
-
PrusaSlicer Installation:
- Download and install PrusaSlicer.
- Ensure
prusa-slicer-console.exe(Windows) or the equivalentprusa-slicerCLI executable is installed. - Add the directory containing the executable to your system's
PATHenvironment variable (or the equivalent for your operating system).- On Windows, this is the folder containing
prusa-slicer-console.exe. - On Linux, macOS, and other Unix-like systems, this is the folder containing
prusa-slicer.
- On Windows, this is the folder containing
-
Python Setup:
Installation
-
Clone the repository:
git clone https://github.com/heibench/prusaslicer-py.git cd prusaslicer-py
-
Install it:
pip install -e .
Or, for development:
just setup # uv sync just check # fmt-check + lint + typecheck just test # run the suite
The package itself has no runtime dependencies.
Usage
from prusaslicer_py import PrusaSlicer, SliceError
slicer = PrusaSlicer() # found on PATH, or as a Flathub Flatpak
print(slicer.engine_kind) # "path" or "flatpak"
print(slicer.check_version()) # PrusaSlicer-2.9.6+flathub.org based on Slic3r ...
# PrusaSlicer ships example models; pick one to slice.
torus = next(s for s in slicer.get_example_shapes() if s.endswith("torus.stl"))
try:
result = slicer.slice_model(torus, "torus.gcode")
except SliceError as e:
# Either the engine failed, or it exited 0 without producing the file --
# a mistyped destination, an option that no-ops, an empty plate. Both
# carry output_path, returncode, stdout and stderr as attributes.
print(f"no G-code produced: {e}\n{e.stderr}")
else:
print(f"{result.output_path} ({result.size_bytes} bytes, exit {result.returncode})")
slice_model returns only once it has checked that the file exists and is not
empty. "The call did not raise" and "the artifact was produced" are not the
same claim, and this package will not conflate them.
Pass slicer_path= to point at a specific executable instead of searching:
slicer = PrusaSlicer(slicer_path="/opt/PrusaSlicer/bin/prusa-slicer")
NOTE:
- Replace slicer_path with the path to your PrusaSlicer CLI executable, if not in PATH.
- Provide the .stl file, desired output path for the .gcode, and any additional parameters as keyword arguments.
slice_modelreturns aSliceResult(output_path,size_bytes,returncode,stdout,stderr). It returns only once it has confirmed the G-code exists and is non-empty. "It did not raise" is a checked guarantee, not an assumption.- Both failures raise a
SliceError(aRuntimeError) carrying those same fields:SliceEngineErrorwhen PrusaSlicer exits non-zero,SliceOutputErrorwhen it exits 0 without producing the file.
Contributing
See AGENTS.md for repository conventions, and
docs/DECISIONS.md for the reasoning behind the ones
that were not obvious.
Contributions are welcome! Please follow these steps:
-
Fork the repository.
-
Create a feature branch:
git checkout -b feature/your-feature-name
-
Run
just check && just test, then commit your changes and open a pull request.
License
This project is licensed under the MIT License.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prusaslicer_py-0.1.0.tar.gz.
File metadata
- Download URL: prusaslicer_py-0.1.0.tar.gz
- Upload date:
- Size: 68.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7290830459c9e42b381849eef714ef88e8cd598addeec3394bcd52176e7b52d4
|
|
| MD5 |
6dee10eab1d308b73d3c3d3288a4564b
|
|
| BLAKE2b-256 |
0c2490e287fb429ca65506fa97992fd71fa7a48c16aae0cc55d90e96f4a2551b
|
Provenance
The following attestation bundles were made for prusaslicer_py-0.1.0.tar.gz:
Publisher:
release.yml on heibench/prusaslicer-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prusaslicer_py-0.1.0.tar.gz -
Subject digest:
7290830459c9e42b381849eef714ef88e8cd598addeec3394bcd52176e7b52d4 - Sigstore transparency entry: 2733127597
- Sigstore integration time:
-
Permalink:
heibench/prusaslicer-py@3955a50fe08bf8c9d82b61bd1933550392cce919 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/heibench
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3955a50fe08bf8c9d82b61bd1933550392cce919 -
Trigger Event:
release
-
Statement type:
File details
Details for the file prusaslicer_py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: prusaslicer_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4496eb5721769fe54f2473a33a4c14c64911f097c9880f2fe67fadd121724e60
|
|
| MD5 |
bfad83b4a19fa12d2050f7ad888cf7a8
|
|
| BLAKE2b-256 |
4c8849448d172b2213f1265f8ec3b408d9f08775eed6640d9b81f60ca91605e8
|
Provenance
The following attestation bundles were made for prusaslicer_py-0.1.0-py3-none-any.whl:
Publisher:
release.yml on heibench/prusaslicer-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prusaslicer_py-0.1.0-py3-none-any.whl -
Subject digest:
4496eb5721769fe54f2473a33a4c14c64911f097c9880f2fe67fadd121724e60 - Sigstore transparency entry: 2733127693
- Sigstore integration time:
-
Permalink:
heibench/prusaslicer-py@3955a50fe08bf8c9d82b61bd1933550392cce919 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/heibench
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@3955a50fe08bf8c9d82b61bd1933550392cce919 -
Trigger Event:
release
-
Statement type: