Skip to main content

Library to control PiKVM with Python

Project description

PiKVM: A Python API for Controlling PiKVM Devices

codecov

PiKVM is a Python library that provides a simple and intuitive API for controlling PiKVM devices. With PiKVM, you can easily perform various actions on your PiKVM devices, such as:

  • Getting system information
  • Controlling ATX power
  • Managing Mass Storage Device (MSD) images
  • Interacting with General-Purpose Input/Output (GPIO) channels
  • Taking snapshots and receive image
  • Reading snapshots with OCR and receive text representation
  • Send keys to the server

With PiKVM, you can automate tasks, integrate PiKVMs into your existing applications, and extend the capabilities of your PiKVM devices.

Installation

To install PiKVM, simply run the following command in your terminal:

pip install pikvm-lib

PiKVM device control

After installing PiKVM, you can import it into your Python script and create an instance of the PiKVM class. The PiKVM class constructor takes the following parameters:

  • hostname: The hostname or IP address of the PiKVM device
  • username: The username for authentication
  • password: The password for authentication
from pikvm_lib import PiKVM

pikvm_instance = PiKVM(hostname="192.168.1.10", username="admin", password="password")

Once you have created an instance of the PiKVM class, 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 web and PiKVM API Reference

Usage examples

Here are some examples of how to use PiKVM to perform common tasks:

  • Getting system information:
from pikvm_lib import PiKVM

pikvm_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 websocket

The 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 examples

from pikvm_lib import PiKVMWebsocket

hostname = "192.168.1.10"  # Replace with your PiKVM server's hostname or IP address
username = "user"
password = "password"

# Create a PiKVMWebsocket object
websocket = PiKVMWebsocket(hostname, username, password)

# Send the Ctrl+Alt+Delete key combination
websocket.send_ctrl_alt_sup()

# Send the text "Hello, world!"
websocket.send_input("Hello, world!")
from pikvm_lib import PiKVMWebsocket

hostname = "192.168.1.10"  # Replace with your PiKVM server's hostname or IP address
username = "user"
password = "password"

# Create a PiKVMWebsocket object
websocket = PiKVMWebsocket(hostname, username, password)

# Send the F2 key
websocket.send_key("<F2>")

# Send the Ctrl+B key
websocket.send_key_press("ControlLeft", "true")
websocket.send_input("b") # or websocket.send_key("KeyB")
websocket.send_key_press("ControlLeft", "false")

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

pikvm_lib-0.4.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

pikvm_lib-0.4.0-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file pikvm_lib-0.4.0.tar.gz.

File metadata

  • Download URL: pikvm_lib-0.4.0.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pikvm_lib-0.4.0.tar.gz
Algorithm Hash digest
SHA256 99da27d664d85064b994038d5dec58a5812cb03bdab10230e420eedb3565a90d
MD5 0949c0952c1221ca7d1c199d4807454b
BLAKE2b-256 75a3aa1d3b5aa6a69484f96dad40c8ff14436241cc5462ef4880e3e70041ea8b

See more details on using hashes here.

File details

Details for the file pikvm_lib-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pikvm_lib-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for pikvm_lib-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc57ee33f7aecb6716c9b6ca2bab0b55678ef43ec77c5a96e4b48eb8e9f7ebed
MD5 cde76326599119af1806ed5c58893fb2
BLAKE2b-256 3d692ce4c1ba9be355f635c3d6319d9841a82694204f30e52200503fb2d2c079

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page