Python Reference ยท Standard Library: Concurrency, Network and Tools
The platform module
Reference for Python's platform module: system, release, machine, python_version, python_implementation, platform(), uname and how it differs from sys.platform.
platform reports facts about the machine and the interpreter running your code: the operating system, its release, the CPU architecture and the Python version. It is useful for diagnostics ("please paste your environment into the bug report"), for choosing a download that matches the machine, and for the occasional OS-specific code path.
The answers describe where the program is running, so they change from computer to computer. Examples here show the values for the in-browser runner, which reports itself as a WebAssembly system; on your own machine you will see Windows, Linux or Darwin instead.
import platform print(platform.system(), platform.machine()) print(platform.python_version())
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.
Syntax
platform.system() platform.platform(aliased=False, terse=False) platform.python_version() platform.uname()
| Function | Description |
|---|---|
system() |
OS name such as 'Windows', 'Linux', 'Darwin' (macOS) or 'Emscripten'; an empty string if unknown. |
release(), version() |
OS release and detailed version strings. |
machine() |
Hardware type, for example 'x86_64', 'AMD64', 'arm64' or 'wasm32'. |
processor() |
Processor name; often empty or just the machine type. |
node() |
Network name of the computer. |
platform() |
One descriptive string combining system, release and more. |
uname() |
Named tuple with system, node, release, version, machine, processor. |
python_version() |
Version as '3.14.0'; python_version_tuple() gives it as strings. |
python_implementation() |
'CPython', 'PyPy', and so on. |
python_compiler(), python_build() |
Compiler and build details. |
architecture() |
(bits, linkage), like ('64bit', 'ELF'). |
freedesktop_os_release() |
Contents of /etc/os-release as a dictionary (Linux, Python 3.10+). |
win32_ver(), mac_ver(), libc_ver() |
OS-specific details. |
Return value: strings, tuples or a uname_result. Functions never raise for unknown values; they return empty strings.
Usage notes
platform.system()versussys.platform:sys.platformis a short identifier fixed at build time ('win32','linux','darwin','emscripten'), cheap to read and suited toif sys.platform.startswith("linux").platform.system()is friendlier text and may query the OS.- Compare versions as tuples. Use
sys.version_info >= (3, 10)rather than comparing the strings frompython_version(), because"3.9" > "3.10"as text. 'Darwin'means macOS. Usemac_ver()for the marketing release number.- Don't test for features by OS name when you can test for the feature itself (
hasattr(os, "fork"),shutil.which("git")). It survives unusual systems. - Values can be empty. Minimal containers and sandboxes often return
''forprocessor()orversion(). - Machine names differ:
AMD64on Windows,x86_64on Linux for the same CPU family;arm64on macOS,aarch64on Linux. - Privacy:
node()is the computer's host name. Leave it out of logs or reports that you publish. - Windows 11 may still report release
'10'on older Python builds; checkplatform.version()(build number 22000 or higher) when it matters.
Related
sys,os,shutilsubprocess- Lessons: Running Python, OS and shutil