Get specific System Info using python

553 views Asked by At

I have to get system specific info as shown. I was checking out the platform module, but I was not able to get the information exactly as shown.

    “OS”: “Ubuntu 20.04",
    “Memory”: 232423423434,
    “system Time”: “15:02:13 +0530”,
    “Timezone”: “Asia/Kolkata”

Any standard libraries in Python which would give me the output as specified ?

1

There are 1 answers

2
FObersteiner On BEST ANSWER

here's something cross-platform, close to what you describe (collected from various sources):

from platform import uname
print(f"OS: {uname().system} {uname().release}, {uname().version}")

from psutil import virtual_memory # pip install psutil
print(f"Memory: {virtual_memory().total}")

from datetime import datetime
print(f"System Time: {datetime.now().astimezone().strftime('%H:%M:%S %z')}")

from tzlocal import get_localzone # pip install tzlocal
print(f"Timezone: {get_localzone()}")

Example outputs

  • on GNU/Linux / Ubuntu:
OS: Linux 5.11.0-27-generic, #29~20.04.1-Ubuntu SMP Wed Aug 11 15:58:17 UTC 2021
Memory: 33314279424
System Time: 17:22:20 +0200
Timezone: Europe/Berlin
  • my Windows machine:
OS: Windows 10, 10.0.19041
Memory: 20796862464
System Time: 17:18:31 +0200
Timezone: Europe/Berlin
  • on my WSL Ubuntu:
OS: Linux 5.10.16.3-microsoft-standard-WSL2, #1 SMP Fri Apr 2 22:23:49 UTC 2021
Memory: 16252194816
System Time: 17:20:07 +0200
Timezone: Europe/Berlin