Platform Module in Python

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 program to display platform processor  # import moduleimport platform  # displaying platform processorprint('Platform processor:', platform.processor())
Output:
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 program to display platform architecture  # import moduleimport platform  # displaying platform architectureprint('Platform architecture:', platform.architecture())
Output:
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 program to display machine type  # import moduleimport platform  # displaying machine typeprint('Machine type:', platform.machine())
Output:
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 program to display the # system's network name  # import moduleimport platform  # displaying system network nameprint('System's network name:', platform.node())
Output:
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 program to display platform information  # import moduleimport platform  # displaying platform informationprint('Platform information:', platform.platform())
Output:
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 program to display platform # processor name  # import moduleimport platform  # displaying platform processor nameprint('Platform processor:', platform.platform())
Output:
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 program to display OS name  # import moduleimport platform  # displaying OS nameprint('Operating system:', platform.system())
Output:
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 program to display System info  # import moduleimport platform  # displaying system infoprint('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.
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 program to display python# build date and no.  # import moduleimport platform  # displaying python build date and no.print('Python build no. and date:', platform.python_build())
Output:
This function returns a string that displays the compiler used for compiling the Python programs.
Example 10: Displaying the python compiler info
# Python program to display python compiler info  # import moduleimport platform  # displaying python compilerprint('Python compiler:', platform.python_compiler())
Output:
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 program to display python SCM info  # import moduleimport platform  # displaying python SCM infoprint('Python SCM:', platform.python_compiler())
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 program to display python implementation  # import moduleimport platform  # displaying python implementationprint('Python implementation:', platform.python_implementation())
Output:
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 program to display python version  # import moduleimport platform  # displaying python versionprint('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:
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)
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)
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.
python-modules
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.