Python logo
June 17, 2019 * Python Programming

Python - Hardware and operating system information

Do you need to know if your operating system is 32 bits or 64 bits?

Do you want to keep track of system memory?

Then look no further. Here is a compilation of a few essential system information like OS version, Python and library versions and the number of processor cores and memory usage. Python libraries also provide information on floating point precision, min/max integer and floating point representation.

Show essential operating system and hardware information

import numpy
import platform
import struct
import sys
import psutil

plmdata = platform.uname()
sysbits = struct.calcsize("P") * 8
sysver = sys.version_info
sysint = sys.int_info
sysflt = sys.float_info

print('Operating system: {}'.format(plmdata.system))
print('         version: {}'.format(plmdata.release))
print('   resister size: {} bits'.format(sysbits))
print('----------------')
print('  Python version: {}.{}'.format(sysver.major, sysver.minor))
print('   numpy version: {}'.format(numpy.__version__))
print('  signed integer: {}'.format(sys.maxsize))
print('        integers: {} bits/digit'.format(sysint.bits_per_digit))
print('       max float: {}'.format(sysflt.max))
print('       precision: {}'.format(sysflt.epsilon))
print('----------------')
print('       cpu cores: {}'.format(psutil.cpu_count()))
print('    max cpu freq: {} MHz'.format(psutil.cpu_freq().max))
print(' tot virtual mem: {} bytes'.format(psutil.virtual_memory().total))
print('   tot disk size: {} bytes'.format(psutil.disk_usage('/').total))
--[Sample information retrieved]------------------
Operating system: Windows
         version: 10
   resister size: 64 bits
----------------
  Python version: 3.6
   numpy version: 1.15.4
  signed integer: 9223372036854775807
        integers: 30 bits/digit
       max float: 1.7976931348623157e+308
       precision: 2.220446049250313e-16
----------------
       cpu cores: 4
    max cpu freq: 2501.0 MHz
 tot virtual mem: 8463343616 bytes
   tot disk size: 238955417600 bytes
--------------------------------------------------

References