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 ?

4
  • This answer might help stackoverflow.com/a/3103224/8636278 Commented Aug 23, 2021 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. Commented Aug 24, 2021 at 4:10
  • System specific info is, as the name says, system-specific. Is this question specific to GNU/Linux? Commented Aug 24, 2021 at 6: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. Commented Aug 24, 2021 at 6:28

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

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 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.