Platform Module in Python
Last Updated :
23 Jan, 2020
Python defines an in-built module
platform that provides system information.
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 the device, it's OS, node, OS version, Python version, etc. This module plays a crucial role when you want to check whether your program is compatible with the python version installed on a particular system or whether the hardware specifications meet the requirements of your program.
This module already exists in the python library and does not require any installation using
pip.
It can be imported using the following syntax:
import platform
Example 1: Displaying the platform processor
Python
# Python program to display platform processor
# import module
import platform
# displaying platform processor
print('Platform processor:', platform.processor())
Output:
Platform Functions
platform.architecture()
This function returns a tuple that stores information about the
bit architecture(number of bits in the platform processor) and
linkage format( defines how names can or can not refer to the same entity throughout the whole program or one single translation unit).
Example 2: Displaying the platform architecture
Python
# Python program to display platform architecture
# import module
import platform
# displaying platform architecture
print('Platform architecture:', platform.architecture())
Output:
platform.machine()
This function returns a string that displays the machine type, by machine type here it means the information that tells the width or size of registers available in the core.
Example 3: Displaying the machine type
Python
# Python program to display machine type
# import module
import platform
# displaying machine type
print('Machine type:', platform.machine())
Output:
platform.node()
This function returns a string that displays the information about the node basically the system's network name.
Example 4: Displaying the system's network name
Python
# Python program to display the
# system's network name
# import module
import platform
# displaying system network name
print('System's network name:', platform.node())
Output:
platform.platform()
This function returns a single string containing as much useful information that is to retrievable about the system.The output may differ on different systems.
Example 5: Displaying the platform information
Python
# Python program to display platform information
# import module
import platform
# displaying platform information
print('Platform information:', platform.platform())
Output:
platform.processor()
This function returns a string that displays the information about the platform processor basically the real name of the system's processor
Note: Many platforms do not provide this information. eg-NetBSD
Example 6: Displaying the platform processor
Python
# Python program to display platform
# processor name
# import module
import platform
# displaying platform processor name
print('Platform processor:', platform.platform())
Output:
platform.system()
This function returns a string that displays the name of the operation system on the current device being used to run the program.
Example 7: Displaying the OS name
Python
# Python program to display OS name
# import module
import platform
# displaying OS name
print('Operating system:', platform.system())
Output:
platform.uname()
This function returns a tuple that stores information regarding the system. Basically this function can be used to replace the individual functions to retrieve information about the system, node, release, version, machine, version and processor. Thus, a single function serving many purposes.
Example 8: Displaying the System info
Python
# Python program to display System info
# import module
import platform
# displaying system info
print('System info:', platform.system())
Output:
Note: Platform module not only retrieves system information, but it can also be used to retrieve information about the Python software running on the system.
platform.python_build()
This function returns a tuple that stores information about the python build date and build no. This information is stored in the tuple as a string datatype.
Example 9: Displaying the python build date and no.
Python
# Python program to display python
# build date and no.
# import module
import platform
# displaying python build date and no.
print('Python build no. and date:', platform.python_build())
Output:
platform.python_compiler()
This function returns a string that displays the compiler used for compiling the Python programs.
Example 10: Displaying the python compiler info
Python
# Python program to display python compiler info
# import module
import platform
# displaying python compiler
print('Python compiler:', platform.python_compiler())
Output:
platform.python_branch()
This function returns a string displaying information about the python SCM branch,
SCM here stands for
Source Code Manager , it is a tool used by programmers to manage source code. SCM is used to track revisions in software.
Example 11: Displaying the python SCM info
Python
# Python program to display python SCM info
# import module
import platform
# displaying python SCM info
print('Python SCM:', platform.python_compiler())
platform.python_implementation()
This function returns a string that displays information about the python implementation. The possible outputs of this function are CPython, JPython, PyPy, IronPython.
To know more about these implementations visit:
Various Implementations of Python
Example 12: Displaying the python implementation
Python
# Python program to display python implementation
# import module
import platform
# displaying python implementation
print('Python implementation:', platform.python_implementation())
Output:
platform.python_version()
This function returns a string that displays the version of Python running currently on the system. The python version is returned in the following manner:
'major.minor.patchlevel'
Example 13: Displaying the python version
Python
# Python program to display python version
# import module
import platform
# displaying python version
print('Python version:', platform.python_version())
Output:
Note: Since python is a platform-independent language, it's modules also have functionalities that are specific to operating systems. Some of them from platform module are mentioned below:
For Mac OS
platform.mac_ver()
This function returns a tuple containing information such as release, version, machine about the Mac OS. The output is in the following manner:
(release, versioninfo, machine)
In this
versioninfo itself is a tuple storing information in the following manner:
(version, dev_stage, non_release_version)
For Unix OS
platform.libc_ver()
This function returns a tuple storing information such as library and version of the Unix OS. The output is in the following manner:
(lib, version)
For Windows OS
platform.win32_ver()
This function returns a tuple containing additional information about Windows OS such as OS release, version number, service pack, OS type(single/ multi processor). The output is in the following format:
(release, version, csd, ptype)
where
csd is service pack and
ptype is OS type.
Similar Reads
Python Module Index
Python has a vast ecosystem of modules and packages. These modules enable developers to perform a wide range of tasks without taking the headache of creating a custom module for them to perform a particular task. Whether we have to perform data analysis, set up a web server, or automate tasks, there
4 min read
Python | platform.uname() Method
In this article, we will learn how to detect the operating system that is currently being used in your system using Python. Detect OS Using the platform Module in Python The platform.uname() method in python is used to get information about the current operating system. This method returns informati
1 min read
Python Fire Module
Python Fire is a library to create CLI applications. It can automatically generate command line Interfaces from any object in python. It is not limited to this, it is a good tool for debugging and development purposes. With the help of Fire, you can turn existing code into CLI. In this article, we w
3 min read
Python Introduction
Python was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with focus on code readability and its syntax allows us to express concepts in fewer lines of code.Key Features of PythonPythonâs simple and readable syntax makes it beginner-frien
3 min read
External Modules in Python
Python is one of the most popular programming languages because of its vast collection of modules which make the work of developers easy and save time from writing the code for a particular task for their program. Python provides various types of modules which include built-in modules and external m
5 min read
Built-in Modules in Python
Python is one of the most popular programming languages because of its vast collection of modules which make the work of developers easy and save time from writing the code for a particular task for their program. Python provides various types of modules which include Python built-in modules and ext
9 min read
OS Module in Python with Examples
The OS module in Python provides functions for interacting with the operating system. OS comes under Python's standard utility modules. 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 fil
10 min read
Python sys Module
The sys module in Python provides various functions and variables that are used to manipulate different parts of the Python runtime environment. It allows operating on the interpreter as it provides access to the variables and functions that interact strongly with the interpreter. Let's consider the
6 min read
Multithreading in Python
This article covers the basics of multithreading in Python programming language. Just like multiprocessing , multithreading is a way of achieving multitasking. In multithreading, the concept of threads is used. Let us first understand the concept of thread in computer architecture. What is a Process
8 min read
Python Time Module
In this article, we will discuss the time module and various functions provided by this module with the help of good examples. As the name suggests Python time module allows to work with time in Python. It allows functionality like getting the current time, pausing the Program from executing, etc. S
7 min read