Skip to main content

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 .stl files or existing profiles from .3MF or .AMF files.
  • 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:

  1. an explicit slicer_path you pass in,
  2. prusa-slicer (or prusa-slicer-console.exe) on PATH,
  3. 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

  1. PrusaSlicer Installation:

    • Download and install PrusaSlicer.
    • Ensure prusa-slicer-console.exe (Windows) or the equivalent prusa-slicer CLI executable is installed.
    • Add the directory containing the executable to your system's PATH environment 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.
  2. Python Setup:

    • Python 3.11 or newer.
    • uv and just for development (not needed to use the package).

Installation

  1. Clone the repository:

    git clone https://github.com/heibench/prusaslicer-py.git
    cd prusaslicer-py
    
  2. Install it:

    pip install -e .
    

    Or, for development:

    just setup     # uv sync --locked
    just lock      # re-resolve uv.lock after a dependency change
    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:

  1. Replace slicer_path with the path to your PrusaSlicer CLI executable, if not in PATH.
  2. Provide the .stl file, desired output path for the .gcode, and any additional parameters as keyword arguments.
  3. slice_model returns a SliceResult (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.
  4. Both failures raise a SliceError (a RuntimeError) carrying those same fields: SliceEngineError when PrusaSlicer exits non-zero, SliceOutputError when 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:

  1. Fork the repository.

  2. Create a feature branch:

    git checkout -b feature/your-feature-name
    
  3. 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

prusaslicer_py-0.2.0.tar.gz (111.9 kB view details)

Uploaded Source

Built Distribution

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

prusaslicer_py-0.2.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file prusaslicer_py-0.2.0.tar.gz.

File metadata

  • Download URL: prusaslicer_py-0.2.0.tar.gz
  • Upload date:
  • Size: 111.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for prusaslicer_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0d42f363f245d1450c06b501dc95c5eca4ca4cfd08bc10aa2c0e99e33e498543
MD5 e828a323f19d3b2cdfdb8dc107244fbc
BLAKE2b-256 8f1250dafc10eed0303e553170a1618308b14b8699a48d78b01fe8e57dfa3bde

See more details on using hashes here.

Provenance

The following attestation bundles were made for prusaslicer_py-0.2.0.tar.gz:

Publisher: release.yml on heibench/prusaslicer-py

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

File details

Details for the file prusaslicer_py-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: prusaslicer_py-0.2.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

Hashes for prusaslicer_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c4ce09e0f7f67404e66fa146b5c2108b4badaaaf2ef9e69f0a838c1f42e8569
MD5 dccb47c67f5ead59b32be929f3fdfa54
BLAKE2b-256 8f3490472b1f8696176385568ab275b2e6d3633d3049ce0612609633b9cd8cb2

See more details on using hashes here.

Provenance

The following attestation bundles were made for prusaslicer_py-0.2.0-py3-none-any.whl:

Publisher: release.yml on heibench/prusaslicer-py

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

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

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