Skip to main content

Cross-platform DMI hardware identifier reader without root/admin privileges

Project description

dmi-reader — Cross-Platform DMI Hardware Identifier Reader

License: Non-Commercial Python 3.7+ PyPI GitHub Repo stars PyPI - Downloads GitHub last commit GitHub issues

Securely retrieve unique hardware identifiers (DMI, UUID, serial numbers) across Linux, Windows, and macOS — without requiring root/admin privileges.


🚀 Features

  • Cross-Platform: Works on Linux, Windows, macOS
  • No Root/Admin Required: Reads DMI safely without elevated permissions
  • Thread-Safe Caching: Efficient, avoids repeated system calls
  • Container-Aware: Automatically detects Docker, Podman, etc.
  • Graceful Degradation: Handles missing/wrong DMI gracefully
  • Fallback Support: Uses machine-id, hostname when DMI unavailable
  • Production-Ready: Robust error handling, logging, type hints

📦 Installation

pip install -r requirements.txt

Dependencies

  • On Windows: automatically installs wmi and pywin32
  • On Linux/macOS: no additional dependencies needed

💡 Usage

Basic usage

from dmi_reader import get_dmi_info

# Get all available DMI information (with fallback)
info = get_dmi_info(include_fallback=True)
print(info)
# Example output:
# {
#   'system_uuid': '123e4567-e89b-12d3-a456-426614174000',
#   'board_serial': 'ABC123456',
#   'chassis_serial': 'CHS789012',
#   'product_name': 'VMware Virtual Platform',
#   'manufacturer': 'VMware, Inc.'
# }

# Strict mode – only DMI data, no fallback
info = get_dmi_info(include_fallback=False)

Advanced: caching and threading

The library is thread‑safe and caches results automatically. If you need fresh data on every call, use force_refresh:

from dmi_reader import get_dmi_info

# Force a fresh read (bypass cache)
info = get_dmi_info(force_refresh=True)

Integration with logging

import logging
from dmi_reader import get_dmi_info

logging.basicConfig(level=logging.DEBUG)
info = get_dmi_info()
# The library logs at DEBUG level, helpful for debugging

Use case: device fingerprinting

from dmi_reader import get_dmi_info
import hashlib
import json

def device_fingerprint() -> str:
    info = get_dmi_info(include_fallback=True)
    # Sort keys for consistent hashing
    data = json.dumps(info, sort_keys=True).encode()
    return hashlib.sha256(data).hexdigest()[:16]

print(f"Device fingerprint: {device_fingerprint()}")

Use in web applications (FastAPI example)

from fastapi import FastAPI
from dmi_reader import get_dmi_info

app = FastAPI()

@app.get("/system/info")
async def system_info():
    return get_dmi_info(include_fallback=True)

Or python test.py


🤔 Why dmi‑reader?

Feature dmi‑reader dmidecode (Linux) wmic (Windows) system_profiler (macOS)
No root/admin ✅ Yes ❌ Requires sudo ⚠️ May need admin ✅ Yes
Cross‑platform ✅ Linux, Windows, macOS ❌ Linux only ❌ Windows only ❌ macOS only
Python API ✅ Clean, typed ❌ Shell parsing ❌ Shell parsing ❌ Shell parsing
Container‑aware ✅ Skips in containers ❌ May fail ❌ N/A ❌ N/A
Thread‑safe ✅ With caching ❌ Process‑based ❌ Process‑based ❌ Process‑based
Graceful fallback ✅ Uses machine‑id, hostname ❌ Fails ❌ Fails ❌ Fails

dmi‑reader is the only library that provides a uniform, secure, and dependency‑free way to read hardware identifiers across all major platforms.


🛠️ Supported Platforms

Platform Method Requires Root/Admin
Linux /sys/class/dmi/id/ No
Windows WMI (with timeout) No
macOS system_profiler No

⚠️ License & Commercial Use

This software is free for personal and non-commercial use only.

Any commercial use — including but not limited to:

  • Integration into commercial products
  • Use in business operations
  • Distribution as part of paid services
  • Use in corporate environments

requires explicit written permission from the author.

To request a commercial license, contact:
Telegram: @saicon001


🧪 Testing

# Clone the repository
git clone https://github.com/saiconfirst/dmi_reader.git
cd dmi-reader

# Install dependencies
pip install -r requirements.txt

# Run test script
python test.py

🤝 Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.


❓ FAQ

Is this library safe to use in production?

Yes. It has zero external dependencies (except wmi/pywin32 on Windows, which are auto‑installed), handles errors gracefully, and is thread‑safe.

Does it work inside Docker containers?

Yes. It automatically detects container environments (Docker, Podman, etc.) and skips DMI reading (which would fail). Fallback identifiers (machine‑id, hostname) are used instead.

Can I use this for license key generation?

Yes, many developers use hardware identifiers as part of license validation. However, note that DMI data can be spoofed in virtualized environments. Use it as one factor in a multi‑factor validation scheme.

How does it compare to reading /sys/class/dmi/id directly?

Reading /sys/class/dmi/id requires root on some systems; dmi‑reader uses the same path but never requires elevated privileges. It also adds caching, container detection, and fallback mechanisms.

What happens if DMI data is missing or invalid?

The library falls back to machine‑id (Linux), hostname (Windows/macOS), or a combination. You can control this with include_fallback=False to get only DMI data.

Is there a performance overhead?

The first call may take a few milliseconds (WMI on Windows is slower). Subsequent calls use an in‑memory cache, making them microseconds fast.

Can I contribute?

Absolutely! See Contributing. We welcome bug reports, feature requests, and pull requests.


💖 Support

If you find this project useful, consider supporting its development:


📜 License

This project is licensed under a Non-Commercial License. Commercial use requires explicit written permission from the author. See the LICENSE file for full terms.


Made with ❤️ by saiconfirst

For commercial licensing inquiries: @saicon001

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dmi_reader-1.0.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file dmi_reader-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dmi_reader-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for dmi_reader-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c90767885d0c4ab5d09b5722fa08d0a35cf402ebb7a6a0c46019f7f0e484b65
MD5 6aed86518e36aee718ab9fdfc24b654b
BLAKE2b-256 bf8d6ee34c3e042d52aa2b6779b8cc97ee972a2fd14b8b4c1395a6a77219380e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page