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.1.tar.gz (126.7 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.1-py3-none-any.whl (126.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: klippy_stubs-0.3.1.tar.gz
  • Upload date:
  • Size: 126.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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.1.tar.gz
Algorithm Hash digest
SHA256 1c44dc40a1c2e24473481011bb99f81146acf55e8d58753cb80bccc9b6b7e74e
MD5 796816fbbe94eb988959cf015cf4ce1a
BLAKE2b-256 0f49617c9dc7c3579c77939c6e1c695a8928335842e98f1d7701c63efeb48ee7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: klippy_stubs-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 126.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2df74da1e07401e8c09ef5bbd9452622b57ef62f9fa8c0e9d8aec7ff0e6a7457
MD5 357163e2d144b8906c44568c8c71dd38
BLAKE2b-256 4f568b0524795fb220e603cb3ea747d140185bfafab694f57bb90e3cced94cf2

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