ddp_utils.machine_info¶
import ddp_utils.machine_info
Expose portable host, user, operating-system, and installation identities.
The machine identifier comes from an operating-system-managed source and can therefore fail on unsupported platforms or restricted hosts. The other helpers return descriptive values reported by the Python standard library.
Examples
Inspect the current host through the public package API:
from ddp_utils import get_machine_name, get_machine_os
hostname = get_machine_name()
platform_description = get_machine_os()
- ddp_utils.machine_info.get_machine_name() str¶
Return the hostname reported by the local operating system.
Returns
Type
Description
str
Hostname for the machine on which the current Python process runs.
Examples
Read the local hostname:
from ddp_utils import get_machine_name hostname = get_machine_name()
- ddp_utils.machine_info.get_machine_user() str¶
Return the operating-system user associated with the current process.
The value follows
getpass.getuserand may come from theLOGNAME,USER,LNAME, orUSERNAMEenvironment variable before the platform account database is consulted.Returns
Type
Description
str
Login name selected by the standard-library user lookup.
Raises
Exception
Description
ImportError
No supported environment variable is set and the platform does not provide the
pwdaccount database.KeyError
The account database has no entry for the current process user identifier.
Examples
Read the current login name:
from ddp_utils import get_machine_user username = get_machine_user()
- ddp_utils.machine_info.get_machine_id() str¶
Return the installation identifier maintained by the operating system.
Windows reads
MachineGuidfromSOFTWARE\Microsoft\Cryptography. Linux reads the first non-empty value from/etc/machine-idor/var/lib/dbus/machine-id. macOS runsioregwith a five-second timeout and extractsIOPlatformUUID.Returns
Type
Description
str
Non-empty native machine identifier from the platform-specific source.
Raises
Exception
Description
RuntimeError
The platform is unsupported, the native source cannot be read, both Linux files are absent or empty, or macOS does not report
IOPlatformUUIDwithin the command timeout.UnicodeDecodeError
A Linux machine-ID file contains non-ASCII bytes.
Note
The function never fabricates a fallback identifier. Callers that require stable machine identity must treat
RuntimeErroras a failed precondition rather than substituting an empty string.Examples
Require a native identifier while handling unsupported hosts:
from ddp_utils import get_machine_id try: machine_id = get_machine_id() except RuntimeError: machine_id = None
- ddp_utils.machine_info.get_machine_os() str¶
Return a descriptive operating-system platform string.
Returns
Type
Description
str
Platform description produced by
platform.platformfor the current host.Examples
Read the current platform description:
from ddp_utils import get_machine_os platform_description = get_machine_os()