Pyghmi: Python General Hardware Management Initiative

1.6.15 · active · verified Thu Apr 16

Pyghmi is a pure Python implementation of the Intelligent Platform Management Interface (IPMI) protocol, also supporting other hardware management initiatives. It enables programmatic control over server hardware, including power management, sensor monitoring, and console redirection (SOL). The library is actively maintained as part of OpenStack projects, with the current version 1.6.15 released on April 10, 2026, indicating a regular release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a connection to an IPMI BMC and retrieve its current power state using `pyghmi`. It relies on environment variables for BMC IP address, username, and password for secure configuration. The `command.Command` object manages the IPMI session lifecycle automatically.

import os
from pyghmi.ipmi import command

# Environment variables for BMC connection
BMC_IP = os.environ.get('PYGHMI_BMC_IP', '192.168.1.100')
BMC_USER = os.environ.get('PYGHMI_BMC_USER', 'admin')
BMC_PASS = os.environ.get('PYGHMI_BMC_PASSWORD', 'password')

try:
    # Establish an IPMI command session
    # The `command.Command` object automatically manages session lifecycle.
    ipmi_cmd = command.Command(
        bmc=BMC_IP,
        userid=BMC_USER,
        password=BMC_PASS
    )

    print(f"Connected to BMC at {BMC_IP}...")

    # Get power state
    power_state = ipmi_cmd.get_power_state()
    print(f"Power State: {power_state['powerstate']}")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Ensure PYGHMI_BMC_IP, PYGHMI_BMC_USER, and PYGHMI_BMC_PASSWORD environment variables are set correctly.")
    print("Also verify network connectivity to the BMC and correct IPMI port (default 623).")

view raw JSON →