Hardware Managers

The first step to retrieving hardware information is to instantiate a HardwareManager.

Depending on the OS present, PySysInfo can automatically load the appropriate Hardware Manager class. The Hardware Manager classes implement the structure of HardwareManagerInterface.

Instantiating a Hardware Manager

Instantiating a hardware manager is the same regardless of the OS. The following codeblock shows how a HardwareManager is instantiated.

import pysysinfo
from pysysinfo.models.info_models import HardwareManagerInterface

hm = pysysinfo.HardwareManager()

print(type(hm))
print(isinstance(hm, HardwareManagerInterface))

Output:

<class 'pysysinfo.core.mac.MacHardwareManager'>
True

The type of HardwareManager instantiated depends on the OS. On macOS, as we can see, the MacHardwareManager was instantiated.


Depending on your OS, when HardwareManager() is called, one of the following classes will be instantiated:

class WindowsHardwareManager

Uses Registry and WMI to extract info.

class MacHardwareManager

Uses sysctl and IOreg to extract info.

class LinuxHardwareManager

Uses the sysfs pseudo file system to extract info.


All HardwareManager classes have the following property and methods:

class HardwareManagerInterface

The hardware manager of every OS follows this structure.

info: HardwareInfo

When any component’s data is queried, the data is stored here.

fetch_hardware_info() HardwareInfo

Fetches all hardware Information.

fetch_cpu_info() CPUInfo

Fetches CPU Information.

fetch_graphics_info() GraphicsInfo

Fetches GPU Information.

fetch_memory_info() MemoryInfo

Fetches RAM Information.

fetch_storage_info() StorageInfo

Fetches Disk Information.

fetch_network_info() NetworkInfo

Fetches Network Information.

fetch_display_info() DisplayInfo

Fetches Display Information.

fetch_audio_info() AudioInfo

Fetches Audio Information.

fetch_baseboard_info() BaseboardInfo

Fetches Baseboard Information.


We can now use this knowledge to query information about the hardware.

import pysysinfo

hm = pysysinfo.HardwareManager()

info = hm.fetch_hardware_info()
print(type(info))

Output on a macOS machine:

<class 'pysysinfo.models.info_models.MacHardwareInfo'>

Information can be queried all at once, or on a per-component basis.

fetch_hardware_info() can be used to query all info.

The other methods in the HardwareManagerInterface class can be used to query each component.

We explore this in the Querying Info section.