Python IPMI Library
The `python-ipmi` library provides a pure Python API for interacting with devices via the Intelligent Platform Management Interface (IPMI) protocol. It supports IPMI version 2.0 and offers multiple communication interfaces, including native RMCP (IPMI over LAN), legacy RMCP (requiring the external `ipmitool`), IPMB (requiring a Total Phase Aardvark or Linux `ipmb-dev` driver), and a mock interface for testing. The current version is 0.5.8, released in December 2025, and it actively supports Python > 3.6, with Python 2.x deprecated.
Common errors
-
Error. timeout: timed out
cause The IPMI target (BMC) did not respond within the expected timeframe during session establishment or command execution. This often indicates network issues, an incorrect target IP, or an unresponsive BMC.fixVerify the IPMI host IP address and network connectivity. Check if the BMC is powered on and its IPMI services are enabled. Consider increasing the timeout settings if network latency is expected, though this specific error message implies a hard timeout has been reached. -
pyipmi.errors.CompletionCodeError: cc=0xYY desc=Invalid data field in Request
cause A command was sent with invalid or improperly formatted data for the specific BMC or IPMI version, or the BMC returned a non-success completion code indicating an invalid request.fixConsult the IPMI specification and your BMC's specific documentation to ensure the command parameters are correct. Verify the arguments passed to `python-ipmi` methods match the expected format for your target device. Check GitHub issues for similar problems with your specific BMC model. -
ImportError: cannot import name 'pyipmi'
cause The `python-ipmi` library was not installed correctly or is not accessible in the current Python environment.fixEnsure the library is installed with `pip install python-ipmi`. Verify that the Python environment where you are running your script is the same one where the library was installed. If using virtual environments, activate it before running your script.
Warnings
- deprecated Python 2.x support is deprecated. While older documentation mentions Python 3.x support being in beta, the latest PyPI and GitHub README state that Python > 3.6 is currently supported.
- gotcha Using the 'ipmitool' interface type requires the external `ipmitool` binary to be installed and accessible in the system's PATH. This is not a pure Python solution and introduces an external dependency.
- gotcha The library may occasionally hang during `session.establish()` or certain IPMI command calls (e.g., `get_chassis_status()`), especially if the BMC is under heavy load or unresponsive.
- gotcha Installing `python-ipmi` via `conda install python-ipmi` is explicitly warned against in the documentation and will not work.
Install
-
pip install python-ipmi
Imports
- pyipmi
import pyipmi
- pyipmi.interfaces
import pyipmi.interfaces
Quickstart
import os
import pyipmi
import pyipmi.interfaces
# Environment variables for IPMI connection details
IPMI_HOST = os.environ.get('IPMI_HOST', '192.168.1.100')
IPMI_USER = os.environ.get('IPMI_USER', 'admin')
IPMI_PASSWORD = os.environ.get('IPMI_PASSWORD', 'password')
interface = None
connection = None
try:
# Using the native RMCP interface (IPMI over LAN)
interface = pyipmi.interfaces.create_interface('rmcp')
connection = pyipmi.create_connection(interface)
connection.target = pyipmi.Target(IPMI_HOST)
connection.session.set_session_type_rmcp(username=IPMI_USER, password=IPMI_PASSWORD)
print(f"Attempting to establish session to {IPMI_HOST}...")
connection.session.establish()
print("Session established successfully.")
# Get Device ID command
device_id_response = connection.get_device_id()
print(f"Device ID: {device_id_response.device_id_string}")
print(f"Manufacturer ID: {hex(device_id_response.manufacturer_id)}")
print(f"Product ID: {hex(device_id_response.product_id)}")
print(f"Firmware Revision: {device_id_response.firmware_revision.major}.{device_id_response.firmware_revision.minor}")
except pyipmi.errors.IpmiError as e:
print(f"IPMI Error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
finally:
if connection:
try:
connection.session.close()
print("Session closed.")
except Exception as e:
print(f"Error closing session: {e}")