Skip to main content

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
  • PawnIO (for system sensors)

Installation

Install from PyPi directly

pip3 install HardwareMonitor

or install locally from source

git clone https://github.com/snip3rnick/PyHardwareMonitor
cd PyHardwareMonitor
pip3 install .

PawnIO Input/Output Driver

For many system sensors (eg. motherboard) it is required to install the PawnIO driver.
The driver can be installed using winget

winget install PawnIO

Alternatively you may download the latest version from the GitHub release page.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hardwaremonitor-1.2.0.tar.gz (2.9 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

hardwaremonitor-1.2.0-py3-none-win_amd64.whl (1.5 MB view details)

Uploaded Python 3Windows x86-64

hardwaremonitor-1.2.0-py3-none-win32.whl (1.5 MB view details)

Uploaded Python 3Windows x86

File details

Details for the file hardwaremonitor-1.2.0.tar.gz.

File metadata

  • Download URL: hardwaremonitor-1.2.0.tar.gz
  • Upload date:
  • Size: 2.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hardwaremonitor-1.2.0.tar.gz
Algorithm Hash digest
SHA256 b258c5f620b37a26c845354b885a354a529be52d1840fe09aae09b2af525e99e
MD5 940125bb29705e509f361347e9096eb2
BLAKE2b-256 317beb9d66f4173662e7baa524cbb8186bf5f3773e811305f2d67b9eb52d0a92

See more details on using hashes here.

Provenance

The following attestation bundles were made for hardwaremonitor-1.2.0.tar.gz:

Publisher: release.yaml on snip3rnick/PyHardwareMonitor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hardwaremonitor-1.2.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for hardwaremonitor-1.2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 bc6cae6be4aed32c430e8451a81f4663d58b3a853ba48d7eedd314610719c945
MD5 491746aea147571b77f1c374540ea114
BLAKE2b-256 65694ecb1176659999934746f7f227cf9a30c189c499a8d394fc1c647227b95e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hardwaremonitor-1.2.0-py3-none-win_amd64.whl:

Publisher: release.yaml on snip3rnick/PyHardwareMonitor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hardwaremonitor-1.2.0-py3-none-win32.whl.

File metadata

  • Download URL: hardwaremonitor-1.2.0-py3-none-win32.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for hardwaremonitor-1.2.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 8cfa4546469181ad4330ef1fe1201d0c14126863b593e1f36c584e4121982723
MD5 ff1bc37bdad7cbad1c9bb59f65e39a9b
BLAKE2b-256 8f20a4b16793090edc33405bbcf040bdc33464f1dad1977851b11062054493a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for hardwaremonitor-1.2.0-py3-none-win32.whl:

Publisher: release.yaml on snip3rnick/PyHardwareMonitor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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