Skip to content

System Module ​

Provides OS-level integration and system environment utilities.
Features include OS and hardware detection, environment PATH manipulation, privilege elevation, process restarting, and runtime dependency checking.

is_elevated() ​

python
def is_elevated() -> bool

Whether the current process has elevated privileges or not.

is_win() ​

python
def is_win() -> bool

Whether the current operating system is Windows or not.

is_linux() ​

python
def is_linux() -> bool

Whether the current operating system is Linux or not.

is_mac() ​

python
def is_mac() -> bool

Whether the current operating system is macOS or not.

is_unix() ​

python
def is_unix() -> bool

Whether the current operating system is a Unix-like OS (Linux, macOS, BSD, …) or not.

get_hostname() ​

python
def get_hostname() -> str

The network hostname of the current machine.

get_username() ​

python
def get_username() -> str

The name of the current user.

get_os_name() ​

python
def get_os_name() -> str

The name of the operating system (e.g., Windows, Linux, …).

get_os_version() ​

python
def get_os_version() -> str

The version of the operating system.

get_architecture() ​

python
def get_architecture() -> str

The CPU architecture (e.g., x86_64, ARM, …).

get_cpu_count() ​

python
def get_cpu_count() -> int

The number of CPU cores available.

get_python_version() ​

python
def get_python_version() -> str

The version string of the currently running Python interpreter (e.g., 3.10.4).

get_env_path() ​

python
def get_env_path(*, as_list: bool = False) -> Path | list[Path]

Get the PATH environment variable.


  • as_list – If true, returns the paths as a list of Paths; otherwise, as a single Path.

has_env_path() ​

python
def has_env_path(path: Path | str | None = None, /, *, cwd: bool = False, base_dir: bool = False) -> bool

Check if a path is present in the PATH environment variable.


  • path – The path to check for.
  • cwd – If true, uses the current working directory as the path.
  • base_dir – If true, uses the script's base directory as the path.

add_env_path() ​

python
def add_env_path(path: Path | str | None = None, /, *, cwd: bool = False, base_dir: bool = False) -> None

Add a path to the PATH environment variable.


  • path – The path to add.
  • cwd – If true, uses the current working directory as the path.
  • base_dir – If true, uses the script's base directory as the path.

remove_env_path() ​

python
def remove_env_path(path: Path | str | None = None, /, *, cwd: bool = False, base_dir: bool = False) -> None

Remove a path from the PATH environment variable.


  • path – The path to remove.
  • cwd – If true, uses the current working directory as the path.
  • base_dir – If true, uses the script's base directory as the path.

elevate() ​

python
def elevate(win_title: str | None = None, args: Sequence[str] | None = None) -> bool

Attempts to start a new process with elevated privileges.


  • win_title – The window title of the elevated process (only on Windows).
  • args – A list of additional arguments to be passed to the elevated process.

After the elevated process started, the original process will exit.
This means, that this method has to be run at the beginning of the program or or else the program has to continue in a new window after elevation.


Returns True if the current process already has elevated privileges and raises a PermissionError if the user denied the elevation or the elevation failed.


Example Usage ​

python
import xulbux as xx

# Request administrator / root privileges:
if xx.system.elevate(win_title="Elevated Setup"):
    print("Running with elevated permissions.")
else:
    print("Elevation failed or was denied.")

restart() ​

python
def restart(prompt: object = "", /, *, wait: int = 0, continue_program: bool = False, force: bool = False) -> None

Restarts the system with some advanced options


  • prompt – The message to be displayed in the systems restart notification.
  • wait – The time to wait until restarting in seconds.
  • continue_program – Whether to continue the current Python program after calling this function.
  • force – Whether to force a restart even if other processes are still running.

check_libs() ​

python
def check_libs(
    lib_names: list[str],
    /,
    *,
    install_missing: bool = False,
    missing_libs_msgs: MissingLibsMsgs | None = None,
    confirm_install: bool = True,
) -> list[str] | None

Checks if the given list of libraries are installed and optionally installs the missing ones.


  • lib_names – A list of library names to check.
  • install_missing – Whether to directly install missing libraries using pip.
  • missing_libs_msgs – Two messages:
    • The first one is displayed when missing libraries are found.
    • The second one is the confirmation message before installing missing libraries.
  • confirm_install – Whether the user will be asked for confirmation before installing missing libraries.

If some libraries are missing or they could not be installed, their names will be returned as a list.
If all libraries are installed (or were installed successfully), None will be returned.


Example Usage ​

python
import xulbux as xx

# Check and prompt to install missing packages:
missing = xx.system.check_libs(
    ["requests", "pytest"],
    install_missing=True,
    confirm_install=True,
)

Released under the MIT License.