py-cpuinfo

Get detailed CPU information in pure Python, with no external dependencies

Library
PyPI
v9.0.0
343stars
MIT License

Repository Health

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

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
76/100Good
Architecture72
Code Quality74
Innovation70
Learning Curve90

py-cpuinfo retrieves detailed CPU information using pure Python, without requiring any extra programs, libraries, or compilation. It gathers processor details such as brand, vendor, architecture, clock speed, cache sizes, and the full set of supported instruction flags, exposing them as a plain dictionary.

Because it relies only on what the operating system already provides, py-cpuinfo runs consistently across Windows, macOS, Linux, BSD, and other platforms. It can be used as an importable library, a command-line tool, or a runnable module, making it easy to fingerprint hardware or gate features on specific CPU capabilities.

What You Get

  • A single get_cpu_info() call returning a dictionary of normalized CPU facts
  • Vendor, brand, architecture, clock speed, cache sizes, and instruction flags
  • Cross-platform support across Windows, macOS, Linux, BSD, and more
  • A command-line interface with JSON output for scripts and diagnostics
  • Zero external dependencies and no compilation required to install or run

Common Use Cases

  • Detecting CPU instruction-set flags before enabling optimized code paths
  • Collecting hardware fingerprints for diagnostics, telemetry, or bug reports
  • Reporting processor details in benchmarking or environment-audit tooling

Under The Hood

Architecture - Nearly all logic lives in a single ~2,800-line module, cpuinfo/cpuinfo.py, exposed via get_cpu_info() in cpuinfo/__init__.py and a python -m cpuinfo entry point in __main__.py. It tries a cascade of OS-specific data sources (CPUID via a generated assembly stub, /proc/cpuinfo, sysctl, lscpu, kstat, dmesg, Windows registry/WMIC) and merges the first successful readings into a normalized info dictionary, keeping both verified and raw fields.

Tech Stack - Pure Python 3 with no third-party runtime dependencies; it shells out to platform tools and OS files rather than binding native code. Packaging uses setuptools via setup.py/setup.cfg/pyproject.toml.

Code Quality - A tests/ directory plus a top-level test_suite.py cover many OS-specific parsing paths with recorded fixtures. The code is procedural and centralized in one large module, which trades modularity for portability and self-containment; the project is currently in low-activity maintenance.

API Design - The surface is intentionally tiny and hard to misuse: call get_cpu_info() and read keys from the returned dict, or run the CLI with --json. Field names are descriptive and documented in the README, so onboarding is nearly instant, though the returned schema is dynamic (keys may be absent on some platforms).

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