Skip to main content

PEP 561 type stubs for Klipper's klippy package, with hand-refined overloads

Project description

PyPI version

klippy-stubs

PEP 561 type stubs for Klipper's klippy package.

Most stubs come from mypy stubgen. Selected APIs get hand-refined overloads where stubgen loses precision (config getters, G-code param parsing, printer object lookup, pin setup, and similar).

Install

uv add klippy-stubs
# or
pip install klippy-stubs

Stubs install under klippy/ (PEP 561). Pyright, basedpyright, ty, and mypy resolve from klippy.* imports with no extra configuration.

from klippy.configfile import ConfigWrapper
from klippy.klippy import Printer
from klippy.gcode import GCodeCommand

gcode = printer.lookup_object("gcode")  # typed as GCodeDispatch
toolhead = printer.lookup_object("toolhead")  # typed as ToolHead

Hand-refined APIs

Module What stubgen misses
configfile.ConfigWrapper Required vs optional getters (get, getint, getfloat, getboolean, lists, choices)
gcode.GCodeCommand Param parsers and sentinel defaults
klippy.Printer Named lookup_object targets (gcode, configfile, toolhead, gcode_move)
toolhead.ToolHead manual_move partial coords (None = keep axis); set_max_velocities return tuple
extras.ldc1612.LDC1612 Bulk-sensor client callback signature
pins / mcu setup_pin discriminated by pin type
webhooks.WebRequest Typed request field getters
msgproto MCU constant getters with sentinel default

See CHANGELOG.md for release notes.

Hand-refined sections are marked # hand-refined: in the .pyi files — grep before running stubgen.

Development

uv sync --dev
pre-commit install
uv run ty check smoke_check.py

Verify the wheel:

uv build
uv pip install dist/klippy_stubs-*.whl --force-reinstall
uv run ty check smoke_check.py
uv run mypy smoke_check.py
npx pyright smoke_check.py

The demo/ package is a minimal Klipper extra that exercises common stub paths.

Pull Requests

PRs that simply re-run mypy stubgen and touch any # hand-refined: sections will be rejected. If a refinement looks wrong, open a PR with an example from the Klipper source code that demonstrates that shows the incorrect typing.

PRs that add new # hand-refined: sections are strongly encouraged. I don't have time, nor the understanding, to go through and hand-refine every API. Make a decent case for the refinement, as more hand-refined sections means more to maintain, so they need to add value.

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

klippy_stubs-0.3.0.tar.gz (126.5 kB view details)

Uploaded Source

Built Distribution

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

klippy_stubs-0.3.0-py3-none-any.whl (126.5 kB view details)

Uploaded Python 3

File details

Details for the file klippy_stubs-0.3.0.tar.gz.

File metadata

  • Download URL: klippy_stubs-0.3.0.tar.gz
  • Upload date:
  • Size: 126.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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 klippy_stubs-0.3.0.tar.gz
Algorithm Hash digest
SHA256 aeb6a3e3d9b8963607c408910dc962b352ad39c452e37e975282e5f9c7b34fdc
MD5 ae23ea0ed9e67471ac82d636bd969be8
BLAKE2b-256 81785ea52872b5d3e4341a3851445aa1156a1e539d7ab8b3b3ab5d59a0bbcead

See more details on using hashes here.

File details

Details for the file klippy_stubs-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: klippy_stubs-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 126.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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 klippy_stubs-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0a4068243a200a13243dc1e6a4ce514cbdd032970df26f5aad39a12db9f2b8c
MD5 7b3e4291ece0fdfe2fdc92f8d96901a6
BLAKE2b-256 dc544daa3840d268a8b52abd352b5489742ae8ba81dff64877f967a577841b44

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