psutil-home-assistant Wrapper

0.0.1 · active · verified Thu Apr 16

psutil-home-assistant is a Python wrapper for the `psutil` library, designed to allow `psutil` to be used multiple times within the same process without conflicts arising from `psutil`'s reliance on global variables for state management. This library provides an object-oriented interface, encapsulating `psutil` functionality for isolated usage. It is currently at version 0.0.1 and has a slow release cadence, with the initial release over a year ago.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate `PsutilWrapper` and access common `psutil` functions like `cpu_percent`, `virtual_memory`, and `disk_usage` through the wrapper instance. The wrapper isolates `psutil`'s state, allowing multiple instances to operate independently within the same process.

from psutil_home_assistant import PsutilWrapper

# Create an instance of the wrapper
ps_wrapper = PsutilWrapper()

# Access psutil functions through the wrapper instance

# Get CPU usage
cpu_percent = ps_wrapper.cpu_percent(interval=None)
print(f"CPU Percent (non-blocking): {cpu_percent}%")

# Get virtual memory info
mem_info = ps_wrapper.virtual_memory()
print(f"Total Memory: {mem_info.total / (1024**3):.2f} GB")
print(f"Available Memory: {mem_info.available / (1024**3):.2f} GB")

# Get disk usage for a specific path
# Note: On some systems, you might need to specify a valid path, e.g., '/'
disk_usage = ps_wrapper.disk_usage('/')
print(f"Disk Usage (root): {disk_usage.percent}%")

view raw JSON →