Using the Platform module in Python

What is it used for?

The platform module in Python is used to access the underlying platform’s data, such as, hardware, operating system, and interpreter version information.

The platform module includes tools to see the platform’s hardware, operating system, and interpreter version information where the program is running.

How do I use it?

You start with importing the platform module in your program, like this:
import platform
You then specify what you want to find out (more on that below).

For example, if you want to find out which python version you are using, simply add python_version() to the platform, like so:
print platform.python_version()

This will return the Python version as a string.

On my computer it looks like this:

Platform Functions

Let’s have a look at the different platform functions we can use

returns information about the bit architecture

returns the machine type, e.g. ‘i386’.

returns the computer’s network name (may not be fully qualified!)

returns a single string identifying the underlying platform with as much useful
information as possible.

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

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

returns a string identifying the compiler used for compiling Python.

returns the Python version as string ‘major.minor.patchlevel’

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

returns the system’s release, e.g. ‘2.2.0’ or ‘NT’

returns the system/OS name, e.g. ‘Linux’, ‘Windows’, or ‘Java’.

returns the system’s release version, e.g. ‘#3 on degas’

returns a tuple of strings (system, node, release, version, machine, processor)
identifying the underlying platform.

Operating System and Hardware Info

Let’s show some examples with an output, to see how this works.

(you can find more examples here)

import platform

print 'uname:', platform.uname()

print 'system   :', platform.system()
print 'node     :', platform.node()
print 'release  :', platform.release()
print 'version  :', platform.version()
print 'machine  :', platform.machine()
print 'processor:', platform.processor()


uname: (‘Linux’, ‘Mwork’, ‘3.5.0-21-generic’, ‘#32-Ubuntu SMP Tue Dec 11 18:51:59
UTC 2012’, ‘x86_64’, ‘x86_64’)

system : Linux
node : Mwork
release : 3.5.0-21-generic
version : #32-Ubuntu SMP Tue Dec 11 18:51:59 UTC 2012
machine : x86_64
processor: x86_64

Leave a Reply

Your email address will not be published. Required fields are marked *