VOOZH about

URL: https://www.geeksforgeeks.org/python/platform-module-in-python/

⇱ Platform Module in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Platform Module in Python

Last Updated : 26 Jul, 2025

Platform module is a built-in library that provides a portable way to access information about underlying platform (hardware and operating system) on which your Python program is running.

Since it is part of Python’s library, no additional installation is required. User can simply import it as:

import platform

Why do we need Platform Module?

  1. Provides detailed information about system’s OS, hardware and Python version.
  2. Useful for writing cross-platform compatible code.
  3. Helps detect the underlying platform (Windows, Linux, macOS, etc.) at runtime.
  4. Allows conditional execution based on system architecture or OS type.
  5. Essential for debugging, logging and system-specific configurations in scripts.

Platform functions

These functions provide information about the operating system, processor, node and general system details. They're useful when writing code that needs to behave differently depending on the environment.

1. platform.processor(): Returns the processor name or identifier of your system. Helpful when you want to know what CPU the program is running on.

Output

Intel64 Family 6 Model 154 Stepping 4, GenuineIntel

2. platform.architecture(): Tells whether your Python is running in 32-bit or 64-bit mode. Useful for compatibility checks.

Output

('64bit', 'WindowsPE')

3. platform.machine(): Returns the machine type (e.g., ‘x86_64’, ‘AMD64’, etc.). It's handy for identifying the hardware architecture.

Output

AMD64

4. platform.node(): Gives the network name (hostname) of the computer. Good for identifying the device in networks.

Output

GFG0578-VISHAKSHI

5. platform.platform(): Returns a single string describing the platform (OS name and version). Great for logging system info.

Output

Windows-10-10.0.26100-SP0

6. platform.system(): Returns the name of the operating system. It’s commonly used for OS-based decisions in scripts.

Output

Windows

7. platform.uname(): Returns a named tuple with detailed system information: system, node, release, version, machine. More detailed than other functions.

Output

uname_result(system='Windows', node='GFG0578-VISHAKSHI', release='10', version='10.0.26100', machine='AMD64')

Python runtime information

These functions give details about the currently running Python interpreter, its version, build, compiler and implementation. Useful when ensuring compatibility or diagnosing environment issues.

1. platform.python_version(): Returns the Python version as a string. Useful for ensuring compatibility with your code.

Output

3.11.9

2. platform.python_build(): Shows when and how the Python interpreter was built. Useful for debugging or understanding build history.

Output

('tags/v3.11.9:de54cf5', 'Apr 2 2024 10:12:12')

3. platform.python_compiler(): Tells which compiler was used to build Python (e.g., MSC for Windows). Helpful for advanced debugging.

Output

MSC v.1938 64 bit (AMD64)

4. platform.python_implementation(): Returns the Python implementation in use like CPython, PyPy, or Jython.

Output

CPython

5. platform.python_branch(): Shows the branch from which Python was built. Mostly relevant for developers working with Python source.

Output

tags/v3.11.9

OS specific functions

These platform-specific methods provide details relevant to particular operating systems. They're useful for tailoring behavior to macOS, Windows or Linux environments.

1. For macOs: platform.mac_ver() gives macOS version details. Only relevant when running the script on a Mac.

Output

('10.15.7', ('', '', ''), 'x86_64')

2. For unix/Linux: platform.libc_ver() returns the version of the C library (glibc) used by the OS. Useful for deep Linux debugging.

Output

('glibc', '2.31')

3. For windows: platform.win32_ver() gives detailed Windows version info. Use it to fine-tune compatibility on different Windows editions.

Output

('10', '10.0.19041', 'SP0', 'Multiprocessor Free')

Related Articles:

Comment
Article Tags: