Python import layer for the LibreHardwareMonitorLib assembly.
Project description
PyHardwareMonitor
Python Harware Monitor is a thin package layer for LibreHardwareMonitorLib
using pythonnet
.
Libre Hardware Monitor, a fork of Open Hardware Monitor, is free software that can monitor the temperature sensors, fan speeds, voltages, load and clock speeds of your computer.
This package is mostly auto generated using the pythonstubs
generator tool for .NET libraries.
Scripts for generating, altering and extending package resources are located in the scripts folder.
The purpose of this layer is the ability to provide extensive typing information and additional utilities around the LibreHardwareMonitorLib.
Note: Python must have admin privileges for
HardwareMonitor
to be able to access all available sensors properly!
Prerequisites
- Python 3.6+
- pythonnet
- .NET 4.7
Installation
Install from PyPi directly
pip3 install HardwareMonitor
or install locally from source
git clone https://github.com/snip3rnick/PyHardwareMonitor
cd PyHardwareMonitor
pip3 install .
Basic Usage
This simple example is a python adaptation of the C# example of the LibreHardwareMonitor repository.
from HardwareMonitor.Hardware import * # equivalent to 'using LibreHardwareMonitor.Hardware;'
class UpdateVisitor(IVisitor):
__namespace__ = "TestHardwareMonitor" # must be unique among implementations of the IVisitor interface
def VisitComputer(self, computer: IComputer):
computer.Traverse(self);
def VisitHardware(self, hardware: IHardware):
hardware.Update()
for subHardware in hardware.SubHardware:
subHardware.Update()
def VisitParameter(self, parameter: IParameter): pass
def VisitSensor(self, sensor: ISensor): pass
computer = Computer() # settings can not be passed as constructor argument (following below)
computer.IsMotherboardEnabled = True
computer.IsControllerEnabled = True
computer.IsCpuEnabled = True
computer.IsGpuEnabled = True
computer.IsBatteryEnabled = True
computer.IsMemoryEnabled = True
computer.IsNetworkEnabled = True
computer.IsStorageEnabled = True
computer.Open()
computer.Accept(UpdateVisitor())
for hardware in computer.Hardware:
print(f"Hardware: {hardware.Name}")
for subhardware in hardware.SubHardware:
print(f"\tSubhardware: {subhardware.Name}")
for sensor in subhardware.Sensors:
print(f"\t\tSensor: {sensor.Name}, value: {sensor.Value}")
for sensor in hardware.Sensors:
print(f"\tSensor: {sensor.Name}, value: {sensor.Value}")
computer.Close()
Utilities
Utilities are located in the HardwareMonitor.Util
module.
Function OpenComputer
The OpenComputer
function provides a shorthand for creating the HardwareMonitor.Hardware.Computer
instance including the settings and update visitor.
Settings are given as keyword arguments, the following example enables just the cpu
and motherboard
component.
computer = OpenComputer(cpu=True, motherboard=True) # use 'all=True' to enable every component
# Access sensors
...
computer.Update() # Updates all sensors
...
computer.Close()
Function ToBuiltinTypes
Instances from the HardwareMonitor
module can be reduced to primitive python types instead of HardwareMonitor
object instances with the ToBuiltinTypes
function.
Objects are recursively converted to Python builtin types (dict
, list
, ...).
This can be useful for applications that serialized the data (e.g. with json).
computer = OpenComputer(cpu=True)
data = ToBuiltinTypes(computer.Hardware)
# [{'Type': 'Hardware', 'HardwareType': 'Cpu', 'Name': 'Intel Core i5-8265U', 'Sensors': [...], 'SubHardware': [...]}]
Function GroupSensorsByType
Sensors of an instance of HardwareMonitor.Harware.Hardware
are held in a flat list.
The helper function GroupSensorsByType
converts the sensor list into a list of lists grouping sensors by type.
GroupSensorsByType(sensors: Iterable[ISensor]) -> List[List[ISensor]]
Function SensorValueToString
The helper function SensorValueToString
converts sensor values to strings appending with the appropriate unit.
SensorValueToString(value: float, type: SensorType) -> str
# returns "3100.0 MHz" for value=3100.0 with type=SensorType.Clock
Dictionary HardwareTypeString
and SensorTypeString
These two mappings convert values for HardwareType
(or SensorType
) to a string.
Both the integer value for the enum or the instances of the enum value (e.g. HardwareType.Cpu
) are present as keys.
In some environments the type fields were set to integers in others to the corresponding type instance.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hardwaremonitor-1.0.0.tar.gz
.
File metadata
- Download URL: hardwaremonitor-1.0.0.tar.gz
- Upload date:
- Size: 462.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9db2de2a01d2d12342f4809bd6e0b0c2f3b2167dfb36d93243d6a49f884a75f5 |
|
MD5 | cda3fde9044f2959f754c62f0af249b5 |
|
BLAKE2b-256 | 115922cd1a33464db6d6c6d45bff83a57d0590517f8259311950432f4fe11bef |
Provenance
The following attestation bundles were made for hardwaremonitor-1.0.0.tar.gz
:
Publisher:
release.yaml
on snip3rnick/PyHardwareMonitor
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
hardwaremonitor-1.0.0.tar.gz
- Subject digest:
9db2de2a01d2d12342f4809bd6e0b0c2f3b2167dfb36d93243d6a49f884a75f5
- Sigstore transparency entry: 147582459
- Sigstore integration time:
- Predicate type:
File details
Details for the file HardwareMonitor-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: HardwareMonitor-1.0.0-py3-none-any.whl
- Upload date:
- Size: 462.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61b8d9335f411c085c0b2ff5546256586dfdf7ebc4676bc0c74be623d5a4aecd |
|
MD5 | becd23fa944f9e6b3e162ece5be5efbe |
|
BLAKE2b-256 | f86a28dedd86cd6e7c37408b41301d519d11b343a969bf8a9ecd88f5ed8e4b69 |
Provenance
The following attestation bundles were made for HardwareMonitor-1.0.0-py3-none-any.whl
:
Publisher:
release.yaml
on snip3rnick/PyHardwareMonitor
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
hardwaremonitor-1.0.0-py3-none-any.whl
- Subject digest:
61b8d9335f411c085c0b2ff5546256586dfdf7ebc4676bc0c74be623d5a4aecd
- Sigstore transparency entry: 147582461
- Sigstore integration time:
- Predicate type: