Open In App

Platform Module in Python

Improve
Improve
Like Article
Like
Save
Share
Report

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 module
import platform
  
# displaying platform processor
print('Platform processor:', platform.processor())


Output:

Output6

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 program to display platform architecture
  
# import module
import platform
  
# displaying platform architecture
print('Platform architecture:', platform.architecture())


Output:

Ouput2

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 program to display machine type
  
# import module
import platform
  
# displaying machine type
print('Machine type:', platform.machine())


Output:

Output3

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 program to display the 
# system's network name
  
# import module
import platform
  
# displaying system network name
print('System's network name:', platform.node())


Output:

Output4

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 program to display platform information
  
# import module
import platform
  
# displaying platform information
print('Platform information:', platform.platform())


Output:

Output5

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 program to display platform 
# processor name
  
# import module
import platform
  
# displaying platform processor name
print('Platform processor:', platform.platform())


Output:

Output6

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 program to display OS name
  
# import module
import platform
  
# displaying OS name
print('Operating system:', platform.system())


Output:

Output12

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 program to display System info
  
# import module
import platform
  
# displaying system info
print('System info:', platform.system())


Output:

Output13

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 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:

Output7

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 program to display python compiler info
  
# import module
import platform
  
# displaying python compiler
print('Python compiler:', platform.python_compiler())


Output:

Output8

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 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 program to display python implementation
  
# import module
import platform
  
# displaying python implementation
print('Python implementation:', platform.python_implementation())


Output:

Output10

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 program to display python version
  
# import module
import platform
  
# displaying python version
print('Python version:', platform.python_version())


Output:

output11

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.



Last Updated : 23 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads