Package: pikvm-lib
PiKVM-Lib: A Python library for controlling/automating PiKVM DevicesPiKVM-Lib is a Python library that provides a simple and intuitive API for controlling PiKVM devices.
With PiKVM-Lib, you can easily perform various actions on your PiKVM devices, such as:Getting system informationControlling ATX powerManaging Mass Storage Device (MSD) imagesInteracting with General-Purpose Input/Output (GPIO) channelsTaking snapshots and receive imageReading snapshots with OCR and receive text representationSend keys to the serverWith PiKVM-Lib, you can automate tasks, integrate PiKVMs into your existing applications,
and extend the capabilities of your PiKVM devices.InstallationTo install PiKVM, simply run the following command in your terminal:pipinstallpikvm-libPiKVM device controlAfter installing PiKVM, you can import it into your Python script and create an instance of thePiKVMclass. ThePiKVMclass constructor takes the following parameters:hostname: The hostname or IP address of the PiKVM deviceusername: The username for authenticationpassword: The password for authenticationfrompikvm_libimportPiKVMpikvm_instance=PiKVM(hostname="192.168.1.10",username="admin",password="password")Once you have created an instance of thePiKVMclass, you can use it to interact with your PiKVM device.
For example, you can get the system information of the device:system_info=pikvm_instance.get_system_info()print(system_info)You can also control the ATX power of the device:pikvm_instance.set_atx_power(action="on")For more information on how to use PiKVM,
please refer to the official documentation:PiKVM official webandPiKVM API ReferenceUsage examplesHere are some examples of how to use PiKVM to perform common tasks:Getting system information:frompikvm_libimportPiKVMpikvm_instance=PiKVM(hostname="192.168.1.10",username="admin",password="password")system_info=pikvm_instance.get_system_info()print(system_info)Turning on the ATX power:pikvm_instance.set_atx_power(action="on")Uploading an MSD image:pikvm_instance.upload_msd_image(filepath="/path/to/image.iso")Connecting the MSD:pikvm_instance.connect_msd()Switching a GPIO channel:pikvm_instance.switch_gpio_channel(channel=1,state=1)Take snapshot and receive OCR text:pikvm_instance.get_streamer_snapshot(snapshot_path="/home/user/pikvm-snapshots",filename="test.txt",ocr=True)Take snapshot and receive image:pikvm_instance.get_streamer_snapshot(snapshot_path="/home/user/pikvm-snapshots",filename="test.jpeg",ocr=False)PiKVM websocketThe PiKVMWebsocket class is a Python class that allows you to send keyboard events to a PiKVM server over WebSocket.It provides methods for sending individual keys, key combinations, and text input.The class also handles the connection to the PiKVM server and the parsing of the WebSocket messages.Usage examplesfrompikvm_libimportPiKVMWebsockethostname="192.168.1.10"# Replace with your PiKVM server's hostname or IP addressusername="user"password="password"# Create a PiKVMWebsocket objectwebsocket=PiKVMWebsocket(hostname,username,password)# Send the Ctrl+Alt+Delete key combinationwebsocket.send_ctrl_alt_sup()# Send the text "Hello, world!"websocket.send_input("Hello, world!")frompikvm_libimportPiKVMWebsockethostname="192.168.1.10"# Replace with your PiKVM server's hostname or IP addressusername="user"password="password"# Create a PiKVMWebsocket objectwebsocket=PiKVMWebsocket(hostname,username,password)# Send the F2 keywebsocket.send_key("<F2>")# Send the Ctrl+B keywebsocket.send_key_press("ControlLeft","true")websocket.send_input("b")# or websocket.send_key("KeyB")websocket.send_key_press("ControlLeft","false")