Python has a Platform Module that contains functions for dealing with the platform the code is being run on. In this tutorial, we will discuss the module and look at most of its useful functions.
About the Platform Module
The platform module is used to retrieve information about the system or platform. We can use this module to perform compatibility checks. When we have a Python program that requires certain conditions to be met, e.g., the architecture of the processor, the operating system in use, or the Python version the system has, then this module can be used.
These specifications are used to determine how well the Python code will run on the system.
Not only for compatibility checks, but the module can also be used for the sake of it. We have many programs that tell us our platform specifications and any such program written in Python can use this module.
The module is named “platform”, so to import it without an alias we can do this:
Functions offered by the platform module
Now let us begin with the available functions. For each function, the examples are run on a Linux virtual machine.
Read also – Python os module
1. Platform Architecture
Returns a tuple containing the bit architecture (number of bits in the processor bus) and the linkage format of the processor used by the platform. Both values are returned as strings.
2. Machine Type
Returns a string containing the machine type (size of registers used in the processor) of the platform.
3. Network Name
Returns a string containing the platform’s network name (the name displayed for the platform if it is in a network).
4. Platform Information
Returns a single string containing useful information about the underlying platform. The function retrieves as much information as possible and then returns a string that is human-readable, so it may look different for different platforms.
5. Processor Name
Returns a single string containing the actual name of the processor used by the platform.
'Intel64 Family 6 Model 158 Stepping 10, GenuineIntel'
6. Python Build
Returns a tuple containing the build number and the build date of the Python installation on the platform. Both values in the tuple are strings.
('default', 'Jan 27 2021 15:41:15')
7. Python Compiler
Returns a string containing the name of the compiler used for compiling Python on the platform.
8. Python Implementation
Returns a string containing the information about the implementation of Python installed on the platform.
9. Python Version
Returns a string identifying the version of Python installed on the platform.
The string is of the format “
10. Python Version Tuple
Returns the version of Python installed on the platform as a tuple.
The tuple is of the format “
(major, minor, patchlevel)“.
('3', '8', '5')
11. OS Release
Returns the release information of the operating system as a string.
12. OS Name
Returns the name of the operating system on the platform as a string.
13. OS Release Version
Returns the release version of the operating system on the platform as a string.
'#64-Ubuntu SMP Wed Dec 9 08:16:25 UTC 2020'
14. Platform Information Tuple
Returns a named tuple with six attributes: system, node, release, version, machine, and processor. All these attributes have individual functions, so this function can be used to get all the information we get from the other functions.
uname_result(system='Linux', node='sumeet-VirtualBox', release='5.4.0-58-generic', version='#64-Ubuntu SMP Wed Dec 9 08:16:25 UTC 2020', machine='x86_64', processor='Intel64 Family 6 Model 158 Stepping 10, GenuineIntel')
In this tutorial, we studied the platform module in python. We discussed many of its important functions and saw their output.
I hope you had a great time learning and see you in the next tutorial.