Developers many times need to determine information about the underlying system on which software is running like machine type, OS version, architecture, processor, python build details, etc. This kind of information can be used to make decisions about software configuration based on the underlying system. Python provides us with a module named platform which has a list of methods that provides information about the underlying system. As a part of this tutorial, we'll explain methods provided by platform module whose knowledge can be useful to developers.
We'll start by importing the platform module.
import platform
bits, linkage = platform.architecture(bits="", linkage="")
print("Processor Type : {}".format(bits if bits else "Not Found"))
print("Linkage : {}".format(linkage if linkage else "Not Found"))
machine = platform.machine()
print("Machine : {}".format(machine))
node_name = platform.node()
print("Node Name of Computer in Network : {}".format(node_name))
platform_details = platform.platform()
print("Platform Details : {}".format(platform_details))
platform_details = platform.platform(terse=True)
print("Platform Details : {}".format(platform_details))
processor = platform.processor()
print("Processor Details : {}".format(processor))
If you are interested in learning about Python's configuration details then please feel free to check out the tutorial on Python module sysconfig which provides methods for it.
build_no, build_date = platform.python_build()
print("Python Build : Build No - {}, Build Date : {}".format(build_no, build_date))
compiler = platform.python_compiler()
print("Python Compiler : {}".format(compiler))
python_implementation = platform.python_implementation()
print("Python Implementation : {}".format(python_implementation))
python_revision = platform.python_revision()
print("Python Revision : {}".format(python_revision if python_revision else "NA"))
python_version = platform.python_version()
major,minor,patch = platform.python_version_tuple()
print("Python Version : {}".format(python_version))
print("Python Version : Major-{},Minor-{},Patch-{}".format(major,minor,patch))
release_info = platform.release()
print("System Release Information : {}".format(release_info))
system = platform.system()
print("System : {}".format(system))
sys_version = platform.version()
print("System Version : {}".format(sys_version))
system_details = platform.uname()
print("System Details Instance Type : {}".format(type(system_details)))
print("System : {}".format(system_details.system))
print("Node Name : {}".format(system_details.node))
print("Release Details : {}".format(system_details.release))
print("Version Details : {}".format(system_details.version))
print("Machine Details : {}".format(system_details.machine))
print("Processor Details : {}".format(system_details.processor))
sys_alias = platform.system_alias(platform.system(), platform.release(), platform.version())
print("System Alias : {}".format(sys_alias))
c_name, c_ver = platform.libc_ver()
print("GCC Details : {}-{}".format(c_name,c_ver))
Please make a NOTE that the below-mentioned methods will work only on systems that are mentioned in their names.
This ends our small tutorial explaining methods of platform module. Please feel free to let us know your views in the comments section.