tuxalot
tuxalot

Reputation: 313

Python platform independent way to get system information

I was wondering if there was a platform independent way of getting system information for linux, windows, mac. I know you can use platform module to get some basic information. I am looking for more detailed information like

  1. CPU information like number of logical cores, number of physical cores, number of sockets, frequency, capabilities
  2. Total amount of physical memory
  3. Disk space -- total, free for each disk
  4. Network interfaces, mac address, ip address (ipv4/ipv6), speed, hostname
  5. OS information

Upvotes: 1

Views: 1169

Answers (1)

Kien Truong
Kien Truong

Reputation: 11381

I recommend using psutil library for this. Not everything you require is available, but it's a good place to start. For example, to get the CPU count, you can use the following code.

>>> import psutil
>>> psutil.cpu_count() # Logical core
4
>>> psutil.cpu_count(logical=False) # Physical core
2

Upvotes: 1

Related Questions