Get Your System Information - Using Python Script
Last Updated :
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 module
- subprocess
1. Using Platform module:
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
Using WMI module (only for Windows):
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
Using os module (only for Unix):
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')
Using psutil module:
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)
2. Using the subprocess module:
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 module
import subprocess
# traverse the info
Id = subprocess.check_output(['systeminfo']).decode('utf-8').split('\n')
new = []
# arrange the string into clear info
for item in Id:
new.append(str(item.split("\r")[:-1]))
for i in new:
print(i[2:-2])
Output:
Similar Reads
Write Os.System Output In File Using Python Python is a high-level programming language. There are many modules. However, we will use os.system module in this Program. This module provides a portable way of using operating system-dependent functionality. The "os" and "os.path()" modules include many functions to interact with the file system.
3 min read
Python Program to Get Country Information This tutorial will show you how to use Python modules to obtain the country's information. We will utilize the countryinfo module for this purpose, which will assist in obtaining information about the capital, currencies, official language, and numerous other types of things that are probably presen
3 min read
How Use Linux Command In Python Using System.Os Using the system module from the os library in Python allows you to interact with the Linux command line directly from your Python script. This module provides a way to execute system commands, enabling you to automate various tasks by integrating Linux commands seamlessly into your Python code. Whe
3 min read
Uses of OS and Sys in Python In this article, we will see where we use Os and Sys in Python with the help of code examples. What is Os Module?Python OS module in Python furnishes a versatile means of engaging with the operating system. It facilitates a range of operations, including the creation, deletion, renaming, movement, a
4 min read
Print Output from Os.System in Python In Python, the os.system() function is often used to execute shell commands from within a script. However, capturing and printing the output of these commands can be a bit tricky. This article will guide you through the process of executing a command using os.system() and printing the resulting valu
3 min read
Python Program to Generate Disk Usage Report in CSV File In this article, we will see how we could generate disk usage reports and store them in a CSV file using Python using multiple methods.Required ModulesWe will be using 4 methods here, the modules required would be Shutil, pandas, WMI, OS, and subprocess.WMI - WMI is a set of specifications from Micr
7 min read
Finding IP Address using Python An IP(Internet Protocol) address is an identifier assigned to each computer and other device(e.g., router, mobile, etc.) connected to a TCP/IP network that is used to locate and identify the node in communication with other nodes on the network. IP addresses are usually written and displayed in huma
2 min read
Os Module Vs. Sys Module In Python Python provides a lot of libraries to interact with the development environment. If you need help using the OS and Sys Module in Python, you have landed in the right place. This article covers a detailed explanation of the OS and Sys Module including their comparison. By the end of this article, you
5 min read
Python - Getting all the Wifi Devices the system has connected In this article we will see how we can all those wifi network on which the system is ever connected to. Wi-Fi is a wireless networking technology that allows devices such as computers (laptops and desktops), mobile devices (smart phones and wearables), and other equipment (printers and video cameras
2 min read
Python - Get Hardware and System information using platform module In this article, we will see how we can show information about our system i.e processor name, name of system etc. The Platform module is used to retrieve as much possible information about the platform on which the program is being currently executed. Now by platform info, it means information about
2 min read