# Klipper RPC Shim library

**URL:** https://klipper.discourse.group/t/klipper-rpc-shim-library/25404
**Category:** Developers
**Created:** [December 24, 2025, 9:06pm UTC](https://klipper.discourse.group/t/klipper-rpc-shim-library/25404 "2025-12-24T21:06:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nefelim4ag](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/nefelim4ag/32/2387_2.png) [@nefelim4ag](https://klipper.discourse.group/u/nefelim4ag)
#### Post date: [December 24, 2025, 9:06pm UTC](https://klipper.discourse.group/t/klipper-rpc-shim-library/25404/1 "2025-12-24T21:06:34Z")

</div>

Shortly speaking, sometimes I think custom extensions can live outside of the Klippy/Klipper process.  
Here is the API, and it should be enough for most basic stuff.

> **[GitHub - nefelim4ag/KlippyRPCShim: Simple klipper raw API wrapper](https://github.com/nefelim4ag/KlippyRPCShim)**
>
> Simple klipper raw API wrapper

I see the Moonraker as the perfect example of a klipper extension.  
This library is supposed to be used as part of the daemon/service that connects to the Klipper socket.  
Declares supported functions and probably loads macros to call those methods.

Some missing pieces, for now:

- Macros should be loaded by the external installer into the printer config.
- The only way to communicate with the user and the UI consoles is to use `RESPOND` g-code.

This example should cover something; it is also available inside the repo:

```python
from queue import Queue
from KlippyRPCShim import KlippyRPCShim

def main():
    krpc = KlippyRPCShim()
    info = {
        "method": "info",
        "params": {
            "client_info": {
                "program": "KRPC", "version": "0.0.1"
            }
        }
    }
    # Register itself and test connection
    resp = krpc.query(info)
    print(f"sync response: {resp}")
    promise = krpc.query_async(info)
    print(f"async response: {promise()}")

    # Test subscription
    import statistics
    request = {"method": "adxl345/dump_adxl345", "params": {"sensor": "adxl345"}}
    pkgs = 5
    generator, cancel = krpc.subscribe(request)
    for resp in generator():
        params = resp.get("params")
        if params is None:
            continue
        d = params["data"]
        val = [row[1] for row in d]

        # Compute mean and standard deviation
        mean_val = statistics.mean(val)
        stddev_val = statistics.stdev(val) if len(val) > 1 else 0.0

        print(f"Mean value: {mean_val:.3f}, StdDev: {stddev_val:.3f}")
        pkgs -= 1
        if pkgs <= 0:
            cancel()

    params_q = Queue(1)
    krpc.register_remote_method(callback=params_q.put, remote_method="noop")
    while True:
        print(f"{params_q.get()}")

if __name__ == " __main__":

```

And so the call of the custom method is:

```auto
[gcode_macro NOOP]
gcode:
  {action_call_remote_method("noop", frequency=300, duration=1.0)}

```

_Probably it would be nice if Klippy would print call errors in the console of gcode is called from the console._

I think the next step would be to implement a simple server to generate `calibrate_shaper` graphs, as an example.  
Because my initial motivation was help shake tune be less intrusive and less dependent on the Klipper internals.

Hope someone finds it useful.

-Timofey

---

<div class="post-metadata">

### Author: ![nefelim4ag](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/nefelim4ag/32/2387_2.png) [@nefelim4ag](https://klipper.discourse.group/u/nefelim4ag)
#### Post date: [December 25, 2025, 11:13pm UTC](https://klipper.discourse.group/t/klipper-rpc-shim-library/25404/2 "2025-12-25T23:13:21Z")

</div>

Said, done: [GitHub - nefelim4ag/KlippyResonanceGraphs: Example project to generate graphs from Klipper test resonances in the external daemon](https://github.com/nefelim4ag/KlippyResonanceGraphs/tree/main)  
Pure proof of concept.  
Upon call of the new macro, the external daemon does all things:

1. Move to the testing point
2. Subscribe/store ADXL data
3. Run resonance test
4. Generate a graph using the existing script over stored data.

(Ah, and it stores data/graphs to the printer config directory).

Hope that helps someone.

-Timofey.
