Announcing klipper-repl: the missing Klipper command line

I’m happy to announce the initial release of klipper-repl, a command line frontend for Klipper that uses the same socket API as Fluidd and Mainsail to provide an efficient G-Code REPL interface.

Its features include:

  • Automatic reconnection if Klipper restarts or is unavailable
  • Support for running G-Code commands as part of shell scripts
  • Multiple G-Code commands per line – use , as a separator
  • Syntax highlighting for both G-Code and user-defined macros
  • Tab autocompletion for user-defined macros
  • M112 emergency stop processing
  • Support for multiple printers via GNU Parallel

Known bugs:

  • Sometimes Python will throw an exception when klipper-repl quits via a KeyboardInterrupt (^C)
  • Probably many more; this works for my (fairly strange) Klipper deployment, but needs testing against other systems

Planned features:

  • A lot more configuration options
  • Some form of live prompt updates with extruder/bed/chamber temperatures during printing
  • An option to display a progress bar while a print is running
  • REPL-specific commands for non-G-Code functionality, like toggling power plugs.

Thank you for your work on this! This looks really useful. It will be a while before I have a chance to test it but I can already think of several ways it would help me.

1 Like

Thank you! Definitely let me know if you run into any install problems when you give it a try – my Klipper host uses NixOS, so the pip instructions in the readme haven’t been tested yet.

I am using CB1. I am not able to install klipper-repl.
Method 1:|
biqu@BTT-CB1:~$ cd klipper-repl/
biqu@BTT-CB1:~/klipper-repl$ pip install klipper-repl
ERROR: Could not find a version that satisfies the requirement klipper-repl
ERROR: No matching distribution found for klipper-repl

biqu@BTT-CB1:~/klipper-repl$ pip install .
Processing /home/biqu/klipper-repl
Installing build dependencies … done
Getting requirements to build wheel … done
Preparing wheel metadata … done
Collecting prompt-toolkit<4.0.0,>=3.0.38
Using cached prompt_toolkit-3.0.38-py3-none-any.whl (385 kB)
Collecting pygments<3.0.0,>=2.15.1
Using cached Pygments-2.15.1-py3-none-any.whl (1.1 MB)
ERROR: Package ‘klipper-repl’ requires a different Python: 3.9.2 not in ‘<4.0,>=3.10’

FYI: I am accessing CB1 using sudo minicom -D /dev/ttyUSB0 -b 115200

I’m not familiar with the CB1, but method 2 is failing because the CB1’s version of python is slightly older than what klipper-repl supports. Whichever package manager the CB1’s OS uses may have a newer version available.

First I tried this command as mentioned in Readme.

biqu@BTT-CB1:~nix run github:unjordy/klipper-replpl
error: experimental Nix feature ‘nix-command’ is disabled; use ‘–extra-experimental-features nix-command’ to override

It didnt wqork, so i tried:
biqu@BTT-CB1:~$ nix run --extra-experimental-features ‘flakes nix-command’ github:unjordy/klipper-repl – /tmp/klippy_uds
/nix/store/844w1zapdic2pfq489dp9lz60s4q51j7-bash-5.2-p15/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

12:41:40 PM ## Disconnected. Waiting for Klipper…

Its disconnecting klipper.

I never tried klipper-repl. Sounds pretty interesting.

Your CB1 is probably running Debian 11 Releases · bigtreetech/CB1 · GitHub.

So your package manager is probably “apt”.

Did you try pip install klipper-repl?


Debian based Linux distributions use “apt” (can be considered as a frontend to dpkg). NixOS uses its own packet manager “Nix”.

I guess, that’s why you run into

I didn’t find requirements for klipper-repl (Python version) here GitHub - unjordy/klipper-repl: The missing Klipper command line. A CLI G-Code REPL for 3D printers running on Klipper firmware.

klipper-repl · PyPI says
Requires: Python >=3.10, <4.0

First, you might check, what Python version is installed on your CB1.

If you have problems with pip install, you might read Installing Packages — Python Packaging User Guide when getting errors using pip install.

Good luck, hcet14

1 Like

biqu@BTT-CB1:~/klipper-repl/result/bin$ ./klipper-repl ~/printer_data/comms/klippy.sock
/nix/store/844w1zapdic2pfq489dp9lz60s4q51j7-bash-5.2-p15/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
10:04:06 AM ## Connected to Klipper at BTT-CB1:/home/biqu/printer_data/comms/klippy.sock
^C or ^D to quit; type M112 for emergency stop

It is running successfully now. with nix flake

1 Like