os.platform

Provides function to detect platform specific information.

Module Contents

Classes

SystemInfo

Gather info about the system.

CPU

Object representing a CPU.

OS

Object representing an OS.

Attributes

KNOWLEDGE_BASE

UNKNOWN

Uname

logger

os.platform.KNOWLEDGE_BASE
os.platform.UNKNOWN = 'unknown'
os.platform.Uname
os.platform.logger
class os.platform.SystemInfo

Gather info about the system.

Variables:
  • uname – instance of Uname namedtuple containing the result of uname system call.

  • core_number – integer containing the number of processor cores on the machine

uname
core_number = 1
ld_info
_platform: str | None
_os_version: tuple[str, str] | None
_hostname: tuple[str, str] | None
classmethod reset_cache() None

Reset SystemInfo cache.

classmethod fetch_system_data() None

Fetch info from the host system.

The function should be the only one that use system calls or programs to fetch information from the current system. Overriding this method should be enough for example for testing purposes as all the other methods use information retrieved in this function.

The function should set all the class attributes described at the beginning of this class.

classmethod platform() str

Guess platform name.

Internal function that guess base on uname system call the current platform

Returns:

the platform name

classmethod os_version() tuple[str, str]

Compute OS version information.

Returns:

a tuple containing os version and kernel version

classmethod hostname() tuple[str, str]

Get hostname and associated domain.

Returns:

a tuple (hostname, domain)

class os.platform.CPU

Bases: namedtuple('CPU', ['name', 'bits', 'endian', 'cores'])

Object representing a CPU.

CPU attributes are:

  • name: [str] the CPU name

  • bits: number of bits for the cpu or ‘unknown’

  • endian: big, little, or unknown

  • cores: number of cores available

__slots__ = ()
as_dict() dict[str, Any]
classmethod get(name: str, endian: str | None = None, compute_cores: bool = False) CPU

Initialize CPU instance.

Parameters:
  • name – cpu name

  • endian – if not None override endianness default settings

  • compute_cores – if True compute the number of cores

class os.platform.OS

Bases: namedtuple('OS', ['name', 'version', 'kernel_version', 'exeext', 'dllext', 'is_bareboard', 'mode'])

Object representing an OS.

Attributes are:

  • name: the OS name

  • version: the OS version

  • kernel_version: the exact version of the kernel

  • exeext: the default executable extension (e.g. .exe on Windows)

  • dllext: the default shared library extension (e.g. .dll on Windows)

  • is_bareboard: whether the system has an OS or not.

__slots__ = ()
as_dict() dict[str, Any]
classmethod get(name: str, is_host: bool = False, version: str = UNKNOWN, mode: str = UNKNOWN) OS

Initialize OS instance.

Parameters:
  • name – os name

  • is_host – if True the OS instance is for the host system

  • version – os version

  • mode – os mode