1

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 ?

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
SrTan
  • 221
  • 3
  • 12
  • This answer might help https://stackoverflow.com/a/3103224/8636278 – Alex Aug 23 '21 at 14:56
  • @Alex Thanks, but it doesnt mention getting the OS with version (I mean specify - I want details like Ubuntu, not Linux) and details of local Timezone are not available through platform. – SrTan Aug 24 '21 at 04:10
  • System specific info is, as the name says, system-specific. Is this question specific to GNU/Linux? – FObersteiner Aug 24 '21 at 06:16
  • @MrFuppes Well, it is dynamic. Iam supposed to extract the server system info where the application is deployed. I used platform, but it gives me "Linux". Iam not sure how to extract "Ubuntu" with version info. – SrTan Aug 24 '21 at 06:28

1 Answers1

0

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
FObersteiner
  • 22,500
  • 8
  • 42
  • 72
  • Thats great..! Thanks..! I was myself looking ways to extract OS info. I came across "lsb_release" module in pythonv3.8.10. lsb_release.get_distro_information().get("DESCRIPTION", "") gave exactly what i was looking for. (Not sure about Windows in this case though) – SrTan Aug 24 '21 at 11:28
  • @SrTan yes there definitely are other options, especially if you don't mind to have something platform-specific. Cross-platform means more overhead; two third party libs - but hey, it even works on Windows ^^ I'll test (and maybe revise) on my Linux machine later. – FObersteiner Aug 24 '21 at 12:13