os.platform

Provides function to detect platform specific information.

Attributes

KNOWLEDGE_BASE

UNKNOWN

logger

Classes

Uname

SystemInfo

Gather info about the system.

CPU

Object representing a CPU.

OS

Object representing an OS.

Module Contents

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

Bases: tuple

system
node
release
version
machine
processor
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 = None
core_number = 1
ld_info = None
_platform: str | None = None
_os_version: tuple[str, str, str] | None = None
_hostname: tuple[str, str] | None = 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 _get_os_version() tuple[str, str, str]

Compute all OS version information.

Returns:

a tuple containing os version (maybe partial), kernel version and a full os version.

classmethod os_version() tuple[str, str]
classmethod full_os_version() str
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, cores: int | None = None) 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

  • cores – if not None force the apparent number of cpu to that value.

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