Registry / devops / py-machineid

py-machineid

JSON →
library1.0.0pypypi✓ verified 87d ago

py-machineid is a Python library designed to retrieve the unique machine ID (UUID/GUID) of any host without requiring administrative privileges. It extracts the operating system's native machine identifier, which is generally stable for a given OS installation. The library also offers a cryptographically hashed version of the ID, useful for application-specific identification. The current version is 1.0.0, and it maintains an active development status, with updates released as needed for bug fixes and feature enhancements.

pip install py-machineid
INSTALL
IMPORT
SIG · PY-MACHINEID
P
py-machineid
devopspythonv1.0.0
Install
1.5s avg
Import
21ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.023s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.020s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

id
import machineid machineid.id()
Imports the library and calls the 'id' function to get the raw machine ID.
hashed_id
import machineid machineid.hashed_id('your-application-id')
Imports the library and calls the 'hashed_id' function with an application ID for an anonymized, application-specific identifier.

This quickstart demonstrates how to retrieve both the raw, native machine ID and an anonymized, application-specific hashed ID. It also shows how to optionally disable the Windows registry query for added control over fingerprinting. Error handling is included for robust usage.

import machineid # Get the raw, native machine ID (GUID/UUID) try: device_id = machineid.id() print(f"Raw Machine ID: {device_id}") except Exception as e: print(f"Error getting raw machine ID: {e}") # Get an anonymized (hashed) version of the ID for a specific application app_id = "my-unique-application" try: hashed_device_id = machineid.hashed_id(app_id) print(f"Hashed Machine ID (for '{app_id}'): {hashed_device_id}") except Exception as e: print(f"Error getting hashed machine ID: {e}") # Disable Windows registry query (if applicable) for id() try: win_id_no_reg = machineid.id(winregistry=False) print(f"Raw Machine ID (no winregistry): {win_id_no_reg}") except Exception as e: print(f"Error getting raw machine ID (no winregistry): {e}")
Debug
Known issues
breakingThe `hashed_id()` function's order of operations for HMAC computation was fixed in v1.0.0 to match the Go `machineid` package. This is a breaking change for all previously generated hashed IDs.
fix
If you were using `hashed_id()` prior to v1.0.0 and relied on its persistence, note that existing hashed IDs will no longer match. Update any systems or databases that depend on these values accordingly.
affects: >=1.0.0
gotchaOn Windows, `id()` and `hashed_id()` query the registry by default. This behavior can be disabled using the `winregistry=False` keyword argument. Disabling it might prevent manual modification of machine fingerprints but could alter the ID generated.
fix
Consider your security posture and desired ID consistency. If you need to prevent potential fingerprint tampering via registry modification, use `machineid.id(winregistry=False)` or `machineid.hashed_id(app_id, winregistry=False)`.
affects: All versions
gotchaMachine IDs, while generally stable per OS installation, can be changed by a root/admin user (e.g., by modifying `/var/lib/dbus/machine-id` on Linux or using `sysprep` on Windows). Cloned or imaged systems might also retain the original ID if not properly prepared.
fix
Be aware that the ID is not immutable. For application-specific, non-admin-alterable unique IDs, consider using `hashed_id()` with a unique `app_id` to add an additional layer of distinction.
affects: All versions
gotchaA `SyntaxWarning: invalid escape sequence '\S'` may be emitted when importing `machineid` with Python 3.12 due to a regex pattern.
fix
This is typically a warning and doesn't prevent the library from functioning correctly. It can be ignored or suppressed. A future library update may address this directly.
affects: Python 3.12+
gotchaThe machine ID uniquely identifies the host and should be treated as confidential information. Directly exposing it in untrusted environments is a security risk.
fix
For identifying an application instance on a machine, use `machineid.hashed_id('your_application_identifier')` instead of `machineid.id()`. The hashed ID is cryptographically secure and suitable for public-facing use.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'machineid'
The `py-machineid` package has not been installed in your current Python environment.
fix
Run `pip install py-machineid` in your terminal to install the library.
TypeError: 'str' object is not callable
You are attempting to use `machineid.id` or `machineid.hashed_id` as a variable or property rather than calling it as a function. Functions require parentheses `()` to be executed.
fix
Call the functions with parentheses: `machineid.id()` or `machineid.hashed_id('your-app-id')`.
ValueError: Invalid application ID, must be a string.
You passed a non-string value (e.g., `None` or an integer) to the `hashed_id()` function as the application ID. The `app_id` parameter must be a string.
fix
Ensure that the `app_id` argument passed to `machineid.hashed_id()` is always a string, for example: `machineid.hashed_id('my_application')`.
Upgrade
Version history
1.0.0latest on PyPI · released Dec 2, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
31 hits · last 30 days
node
28
OpenAI (training)
1
Resources
py-machineid — pip install py-machineid · libregistry