os.platform

Provides function to detect platform specific information.

Module Contents

Classes

Uname

System uname information.

SystemInfo

Gather info about the system.

CPU

Object representing a CPU.

OS

Object representing an OS.

Attributes

KNOWLEDGE_BASE

UNKNOWN

logger

WINDOWS_VERSION_VISTA

WINDOWS_VERSION_8_1

WINDOWS_VERSION_10

WINDOWS_BUILD_2016

WINDOWS_BUILD_2019

WINDOWS_BUILD_2022

WINDOWS_BUILD_11

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

Bases: NamedTuple

System uname information.

system: str
node: str
release: str
version: str
machine: str
processor: str
os.platform.logger
os.platform.WINDOWS_VERSION_VISTA = 6.2
os.platform.WINDOWS_VERSION_8_1 = 6.3
os.platform.WINDOWS_VERSION_10 = 10.0
os.platform.WINDOWS_BUILD_2016 = 17763
os.platform.WINDOWS_BUILD_2019 = 20348
os.platform.WINDOWS_BUILD_2022 = 26100
os.platform.WINDOWS_BUILD_11 = 22000
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, 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 _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]

Os version.

classmethod full_os_version() str

Full os version.

classmethod hostname() tuple[str, str]

Get hostname and associated domain.

Returns:

a tuple (hostname, domain)

class os.platform.CPU

Bases: NamedTuple

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

name: str
bits: int
endian: str
cores: int
as_dict() dict[str, Any]

Serialize object to dictionary representation.

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

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.

name: str
version: str
kernel_version: str
exeext: str
dllext: str
is_bareboard: bool
mode: str
as_dict() dict[str, Any]

Serialize object to dictionary representation.

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