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
import platform
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
import platform
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
import platform
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
import platform
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
import platform
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
import platform
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
import platform
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
import platform
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.
import platform
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
import platform
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
import platform
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
import platform
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
import platform
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.
Share your thoughts in the comments
Please Login to comment...