{"id":7530,"library":"py-machineid","title":"py-machineid","description":"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.","status":"active","version":"1.0.0","language":"en","source_language":"en","source_url":"https://github.com/keygen-sh/py-machineid","tags":["machine-id","device-id","fingerprinting","system-info","cross-platform","guid","uuid","security"],"install":[{"cmd":"pip install py-machineid","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Imports the library and calls the 'id' function to get the raw machine ID.","symbol":"id","correct":"import machineid\nmachineid.id()"},{"note":"Imports the library and calls the 'hashed_id' function with an application ID for an anonymized, application-specific identifier.","symbol":"hashed_id","correct":"import machineid\nmachineid.hashed_id('your-application-id')"}],"quickstart":{"code":"import machineid\n\n# Get the raw, native machine ID (GUID/UUID)\ntry:\n    device_id = machineid.id()\n    print(f\"Raw Machine ID: {device_id}\")\nexcept Exception as e:\n    print(f\"Error getting raw machine ID: {e}\")\n\n# Get an anonymized (hashed) version of the ID for a specific application\napp_id = \"my-unique-application\"\ntry:\n    hashed_device_id = machineid.hashed_id(app_id)\n    print(f\"Hashed Machine ID (for '{app_id}'): {hashed_device_id}\")\nexcept Exception as e:\n    print(f\"Error getting hashed machine ID: {e}\")\n\n# Disable Windows registry query (if applicable) for id()\ntry:\n    win_id_no_reg = machineid.id(winregistry=False)\n    print(f\"Raw Machine ID (no winregistry): {win_id_no_reg}\")\nexcept Exception as e:\n    print(f\"Error getting raw machine ID (no winregistry): {e}\")","lang":"python","description":"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."},"warnings":[{"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.","message":"The `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.","severity":"breaking","affected_versions":">=1.0.0"},{"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)`.","message":"On 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Machine 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"A `SyntaxWarning: invalid escape sequence '\\S'` may be emitted when importing `machineid` with Python 3.12 due to a regex pattern.","severity":"gotcha","affected_versions":"Python 3.12+"},{"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.","message":"The machine ID uniquely identifies the host and should be treated as confidential information. Directly exposing it in untrusted environments is a security risk.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install py-machineid` in your terminal to install the library.","cause":"The `py-machineid` package has not been installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'machineid'"},{"fix":"Call the functions with parentheses: `machineid.id()` or `machineid.hashed_id('your-app-id')`.","cause":"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.","error":"TypeError: 'str' object is not callable"},{"fix":"Ensure that the `app_id` argument passed to `machineid.hashed_id()` is always a string, for example: `machineid.hashed_id('my_application')`.","cause":"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.","error":"ValueError: Invalid application ID, must be a string."}]}