mozinfo
mozinfo is a Python library designed to retrieve system information, primarily for use within Mozilla's testing infrastructure. It acts as a bridge to normalize diverse operating system and architecture details into a consistent set of values, such as 'os', 'version', 'bits', and 'processor'. The current version is 1.2.3, and it is actively maintained as part of the broader Mozilla ecosystem.
Common errors
-
AttributeError: module 'mozinfo' has no attribute 'some_non_existent_attribute'
cause Attempting to access a system information attribute that `mozinfo` does not expose as a direct module-level variable.fixRefer to the documentation for available attributes (e.g., `os`, `version`, `bits`, `processor`). If you want to see all available keys, use `mozinfo.info.keys()`. -
print(mozinfo.os) outputs 'UNKNOWN' even though my OS is clearly Windows/Linux/macOS.
cause The `mozinfo` library relies on detecting information from the environment, including potentially a `mozinfo.json` file generated during a Mozilla build. If this file isn't found or the environment isn't typical for Mozilla testing, certain attributes may default to `mozinfo.unknown` (string representation 'UNKNOWN').fixUnderstand that `mozinfo` provides a 'Mozilla-centric' view of system info. If you require general system information outside of a Mozilla build context, consider using standard Python modules like `platform` or `os` directly.
Warnings
- gotcha The `mozinfo.unknown` singleton, used when a value cannot be determined, evaluates as `False` in boolean contexts. This can lead to unexpected behavior if not explicitly checked for `mozinfo.unknown`.
- gotcha When not executed within a Mozilla build environment (i.e., where a `mozinfo.json` file is present in the object directory), some `mozinfo` attributes might return `mozinfo.unknown` or 'UNKNOWN'. The library's full capability is realized when used in its intended context.
Install
-
pip install mozinfo
Imports
- mozinfo
import mozinfo
Quickstart
import mozinfo
print(f"Operating System: {mozinfo.os}")
print(f"OS Version: {mozinfo.version}")
print(f"Architecture Bits: {mozinfo.bits}")
print(f"Processor Type: {mozinfo.processor}")
# Access all info as a dictionary
print("\nAll mozinfo attributes:")
for key, value in mozinfo.info.items():
print(f" {key}: {value}")