Get Your System Information - Using Python Script - GeeksforGeeks

25 Sep, 2020
Getting system information for your system can easily be done by the operating system in use, Ubuntu let’s say. But won’t it be fun to get this System information using Python script? In this article, we will look into various ways to derive your system information using Python.
There are two ways to get information:
Using Platform modulesubprocess  
Using Platform module
subprocess  
Installation of the platform module can be done using the below command:  
pip install platform


Example:  
Python3
import platform my_system = platform.uname() print(f"System: {my_system.system}")print(f"Node Name: {my_system.node}")print(f"Release: {my_system.release}")print(f"Version: {my_system.version}")print(f"Machine: {my_system.machine}")print(f"Processor: {my_system.processor}")
Output:  
System: Windows
Node Name: LAPTOP-PRKUI1Q9
Release: 10
Version: 10.0.18362
Machine: AMD64
Processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel


 
The WMI module can be used to gain system information of a windows machine and can be installed using the below command:  
pip install wmi


Example:  
Python3
import wmi c = wmi.WMI()   my_system = c.Win32_ComputerSystem()[0] print(f"Manufacturer: {my_system.Manufacturer}")print(f"Model: {my_system. Model}")print(f"Name: {my_system.Name}")print(f"NumberOfProcessors: {my_system.NumberOfProcessors}")print(f"SystemType: {my_system.SystemType}")print(f"SystemFamily: {my_system.SystemFamily}")
Output:  
Manufacturer: LENOVO
Model: 80XH
Name: LAPTOP-PRKUI1Q9
NumberOfProcessors: 1
SystemType: x64-based PC
SystemFamily: ideapad 320-15ISK


 
Example:
Python3
import os print(os.uname())
Output:  
(‘Linux’, ‘mycomputer.domain.user’, ‘2.6.18-92.1.22.el5PAE’, ‘#1 SMP Tue APR 16 12:36:25 EST 2020’, ‘i686’)
 
This is primarily used for getting runtime process information on the system. Installation of psutil module can be done using the below command:  
pip install psutil


Example:  
Python3
import psutil print(f"Memory :{psutil.virtual_memory()}")
Output:  
Memory :svmem(total=8458571776, available=2982494208, percent=64.7, used=5476077568, free=2982494208)
We will use the subprocess module to interact with cmd and to retrieve information into your python ide. we can read the cmd command through the subprocess module. It is an inbuilt module in python
Let’s see my logic, if we run this  systeminfo code into our terminal then we got like this:
Let’s write python code to get information:
Approach:
import module
Get the output for the command “systeminfo” using subprocess.check_output()
Decode the output with utf-8 split the meta data according to the line
Now get the Split the string and arrange your data with your own needs.
Implementation:
Python3
# import moduleimport subprocess # traverse the infoId = subprocess.check_output(['systeminfo']).decode('utf-8').split('\n')new = [] # arrange the string into clear infofor item in Id:    new.append(str(item.split("\r")[:-1]))for i in new:    print(i[2:-2])
Output:
 
kumar_satyam
Picked
python-utility
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Python program to convert a list to string
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Split string into list of characters
Python | Convert a list to dictionary