py-machineid

1.0.0 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →