Python Platform Module

Python has a built-in module named platform that provides information about the system Python is running on. The Platform module is used to retrieve as much possible information about the platform on which the program is currently being executed. Platform information means information about the device, its OS, node, OS version, Python version, etc. This module plays an important 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.

To Use Platform First Import It

import platform

Once the module is imported, you can access all of the functions below.

platform.architecture()

For different architectural information, the platform.architecture() method queries the specified executable (defaults to the Python interpreter binary). The return value is a tuple of size two. The first element indicates the bit architecture (the number of bits in the processor), and the second shows the linkage format used for the executable.

platorm.architecture()

# ('64bit', '')

platform.machine()

The platform.machine() method is used to return the machine type of the underlying platform—for example, i386, i686, and x86_64.

platform.machine()

# arm64

platform.platform()

This function returns a single string containing as much helpful information that is retrievable about the system. The output may differ in different systems.

platform.platform()

# macOS-12.6-arm64-arm-64bit

platform.processor()

platform.processor() returns the (real) processor name, e.g. ‘amdk6’.

An empty string is returned if the processor() cannot determine the value. Many platforms do not provide this information or return the same value as for machine().

platform.processor()

# arm

platform.python_build()

The python_build() function returns a tuple (buildno, build date) stating the Python build number and date as strings.

platform.python_build()

# ('v3.10.4:9d38120e33', 'Mar 23 2022 17:29:05')

platform.python_compiler()

The python_compiler() function returns a string identifying the compiler used for compiling Python.

platform.python_compiler()

# Clang 13.0.0 (clang-1300.0.29.30)

platform.python_implementation()

The python_implementation() function returns a string identifying the Python implementation. Possible return values are: ‘CPython’, ‘IronPython’, ‘Jython’, ‘PyPy’.

platform.python_implementation()

# CPython

platform.python_version()

The python_version() function returns a string identifying the Python implementation SCM revision.

platform.python_version()

# 3.10.4

platform.python_version_tuple()

The python_version_tuple() function returns the Python version as a tuple (major, minor, patch level) of strings.

Unlike the Python sys.version, the returned value will always include the patch level (it defaults to ‘0’).

platform.python_version_tuple()

# ('3', '10', '4')

platform.release()

The platform.release() function returns the system’s release, e.g. ‘2.2.0’ or ‘NT’. An empty string is returned if python_release() cannot determine the value.

platform.release()

# 21.6.0

platform.system()

The platform.system() function returns the system/OS name, such as ‘Linux’, ‘Darwin’, ‘Java’, ‘Windows’. An empty string is returned if python_system() cannot determine the value.

platform.system()

# Darwin

platform.version()

The platform.version() function returns the system’s release version. An empty string is returned if python_verrsion() cannot determine the value.

platform.uname()

Fairly portable uname interface. This function returns a named tuple containing six attributes: system, node, release, version, machine, and processor.

platform.win32_ver()

Get additional version information from the Windows Registry and return a tuple (release, version, csd, ptype) referring to OS release, version number, CSD level (service pack), and OS type (multi/single processor). Values that win32_ver() cannot determine are set to the defaults given as parameters (all default to an empty string).

platform.libc_ver()

Tries to determine the libc version against which the file executable (defaults to the Python interpreter) is linked. Returns a tuple of strings (lib, version) that defaults to the given parameters in case the lookup fails.

platform.mac_ver()

Get macOS version information and return it as a tuple (release, version info, machine) with versioninfo being a tuple (version, dev_stage, non_release_version).

platform.mac_ver()

# ('12.6', ('', '', ''), 'arm64')

Python Platform Module Summary

Python offers the Platform module, which retrieves all information about the platform you are running. You can fetch all this information by running a Python program. In this tutorial, we learned about the platform module of Python and how you can implement it to gather information from your system. You can get all the details regarding the system on which you are running Python by using the functions of this module in a Python program and running the program. Platform module is helpful to software developers whenever they are working on a system in which information is not known, but they want to know these details about it. This module plays a crucial role whenever software engineers need to install different software and applications in their system. They want to check whether their system is compatible with that application. Engineers can check the system’s compatibility by checking its version, type of machine, and several other properties before installing any application.