py-machineid

Get the unique machine ID of any host in Python without admin privileges

Library
PyPI
v1.0.0
98stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
28/100Needs Attention
Development Activity0
Maintenance0
Community40
Maturity52
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture78
Code Quality80
Innovation72
Learning Curve90

py-machineid is a small cross-platform Python library that returns a stable, unique identifier for the machine it runs on, without requiring administrator or root privileges. It reads the native per-device GUID on Windows, macOS, and Linux and exposes it through a simple id() call.

Beyond the raw GUID, it can produce an anonymized, hashed identifier that is optionally scoped to an application ID, so the same device yields a different stable ID per application. This makes it well suited to licensing, device fingerprinting, and analytics use cases where you need a durable machine identity but want to avoid exposing the raw hardware GUID.

What You Get

  • An id() function returning the host’s raw native machine GUID as a string
  • A hashed_id() function that returns an anonymized, optionally app-scoped hash of the GUID
  • Cross-platform support for Windows, macOS, and Linux from a single API
  • Operation without administrator or root privileges, with a winregistry toggle on Windows

Common Use Cases

  • Binding a software license or activation to a specific device
  • Generating a stable, privacy-preserving device fingerprint for analytics
  • Producing per-application unique device identifiers via app-scoped hashing
  • Detecting or limiting installations across machines without a login system

Under The Hood

Architecture - The whole library is a single module, machineid/init.py (about 125 lines). It detects the current platform and reads the corresponding native identity source: the MachineGuid value from the Windows registry (or wmic as a fallback), the IOPlatformUUID via ioreg on macOS, and /var/lib/dbus/machine-id or /etc/machine-id on Linux. id() returns that raw GUID, while hashed_id() runs it through an HMAC-SHA256 keyed by an optional application ID and returns the hex digest. A custom exception type is raised when the platform GUID cannot be read.

Tech Stack - Pure Python with no third-party runtime dependencies, relying only on the standard library (subprocess, hashlib/hmac, winreg on Windows). It is packaged with a conventional setup.py and supports modern Python 3 versions.

Code Quality - Despite its small size, the project ships tests (tests/test_exceptions.py) and runs CI on GitHub Actions. The code is straightforward and readable, isolating each platform’s lookup and handling failures through a dedicated exception rather than silently returning empty values.

API Design - The public surface is just two functions, id() and hashed_id(), both returning plain strings, so getting a machine identifier is a one-line call. hashed_id() takes an optional app-id argument and both accept a winregistry kwarg to control the Windows lookup, keeping common use trivial while still exposing platform nuance when needed.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search