Moonraker API Client

raw JSON →
2.0.6 verified Mon Apr 27 auth: no python

Async websocket API client for Moonraker, the Klipper 3D printer backend. Provides both HTTP and WebSocket interfaces for printer control and monitoring. Current version 2.0.6, updated August 2024.

pip install moonraker-api
error ModuleNotFoundError: No module named 'moonraker'
cause Using wrong import name; the package is 'moonraker-api' but import is from 'moonraker_api'.
fix
Use 'from moonraker_api import MoonrakerAPI'
error AttributeError: module 'moonraker_api' has no attribute 'WEBSOCKET_STATE_READY'
cause Removed in v2.0.0 breaking change.
fix
Remove usage of WEBSOCKET_STATE_READY; rely on async connect()
breaking Since v2.0.0, MoonrakerAPI no longer uses WEBSOCKET_STATE_READY constant. State management changed.
fix Remove references to WEBSOCKET_STATE_READY; use async connect() instead
breaking In v2.0.0, the connect() method became async and now blocks until the connection is ready.
fix Use await api.connect() instead of synchronous call
gotcha WebSocket receive timeout was added in v2.0.3; slow printers may cause timeout errors.
fix Increase the receive timeout via aiohttp ClientTimeout or patch if needed

Create an async client connecting to a local Moonraker instance via WebSocket.

import asyncio
from moonraker_api import MoonrakerAPI

async def main():
    api = MoonrakerAPI("ws://192.168.1.100:7125/websocket")
    await api.connect()
    print(await api.get_server_info())
    await api.disconnect()

asyncio.run(main())