Quickstart¶
Hardware Manager¶
The entry point to HWProbe is the HardwareManager class.
When instantiated, it automatically selects the correct backend for your OS.
import hwprobe
hm = hwprobe.HardwareManager()
print(type(hm))
<class 'hwprobe.core.mac.MacHardwareManager'>
On Linux and Windows, a LinuxHardwareManager or WindowsHardwareManager
is returned instead. The API is identical regardless of platform.
All HardwareManager classes implement the following interface:
- 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 Everything¶
Collect all hardware info in one call:
from hwprobe import HardwareManager
hm = HardwareManager()
info = hm.fetch_hardware_info()
print(info.cpu.name)
print(info.model_dump_json(indent=2))
Targeted Collection¶
Fetch individual components when you only need one subsystem:
from hwprobe import HardwareManager
hm = HardwareManager()
cpu = hm.fetch_cpu_info()
memory = hm.fetch_memory_info()
storage = hm.fetch_storage_info()
graphics = hm.fetch_graphics_info()
network = hm.fetch_network_info()
Serialization¶
All component models are Pydantic models,
so they support .model_dump() for dictionaries and .model_dump_json() for JSON strings.
from hwprobe import HardwareManager
from pprint import pprint
hm = HardwareManager()
cpu = hm.fetch_cpu_info()
# As a Python dictionary
pprint(cpu.model_dump())
# As a JSON string
print(cpu.model_dump_json(indent=2))
{'arch_version': '8',
'architecture': 'ARM',
'bitness': 64,
'cores': 8,
'name': 'Apple M3',
'sse_flags': [],
'status': {'messages': [], 'string': 'success'},
'threads': 8,
'vendor': 'Apple'}
The same works for fetch_hardware_info() and all other component methods.
Next: Querying Info