Distro - OS Platform Information API

raw JSON →
1.9.0 verified Tue May 12 auth: no python install: verified quickstart: verified

Distro is a Python library that provides information about the operating system distribution it runs on, such as a reliable machine-readable ID and version information. It serves as a recommended replacement for Python's original platform.linux_distribution function, which was removed in Python 3.8. The current version is 1.9.0, released on October 5, 2023. The library is actively maintained with a stable release cadence, with the latest release being v1.9.0.

pip install distro
error ModuleNotFoundError: No module named 'distro'
cause The 'distro' library has not been installed in your Python environment or is not accessible within your current Python path.
fix
Install the 'distro' library using pip: pip install distro
error AttributeError: module 'platform' has no attribute 'linux_distribution'
cause The `platform.linux_distribution()` function was deprecated in Python 3.5 and removed in Python 3.8, and code or dependencies are still attempting to use it. The `distro` library is its recommended replacement.
fix
Install the 'distro' library (pip install distro) and replace calls to platform.linux_distribution() with distro.linux_distribution(), or preferably with distro.id(), distro.name(), and distro.version() for more granular information.
error distro.linux_distribution() is deprecated
cause The `distro.linux_distribution()` function itself has been deprecated in `distro` version 1.6.0 and later, in favor of more specific accessor functions.
fix
Replace distro.linux_distribution() calls with distro.id(), distro.version(), and distro.name() to retrieve specific distribution information.
error AttributeError: module 'distro' has no attribute 'id'
cause This error typically occurs if an older version of the `distro` library is installed that does not yet include the `id()` (or `version()`, `name()`) consolidated accessor functions, or if there is a typo in the function call.
fix
Ensure you have a recent version of the distro library installed: pip install --upgrade distro. If the error persists, double-check the function name for typos.
error AttributeError: module 'distro' has no attribute 'linux_distribution'
cause The `distro` library's API does not include a `linux_distribution` method; it uses distinct methods like `id()` or `name()`.
fix
Replace distro.linux_distribution() with appropriate distro API calls such as distro.id(), distro.name(), or distro.version().
breaking The platform.linux_distribution function was removed in Python 3.8. Distro serves as its recommended replacement.
fix Use Distro's id(), version(), and name() functions instead.
deprecated Python 2.7, 3.4, and 3.5 support was deprecated in Distro v1.6.0.
fix Upgrade to Python 3.6 or later.
gotcha Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead.
fix Use a virtual environment instead (https://pip.pypa.io/warnings/venv). If running pip as root is intentional and its implications are understood, use the --root-user-action option to suppress this warning.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.04s 17.9M
3.10 slim (glibc) - - 0.03s 18M
3.11 alpine (musl) - - 0.09s 19.7M
3.11 slim (glibc) - - 0.07s 20M
3.12 alpine (musl) - - 0.09s 11.6M
3.12 slim (glibc) - - 0.06s 12M
3.13 alpine (musl) - - 0.06s 11.3M
3.13 slim (glibc) - - 0.06s 12M
3.9 alpine (musl) - - 0.04s 17.4M
3.9 slim (glibc) - - 0.03s 18M

A simple script to print the distribution ID, version, and name using the Distro library.

import distro
print(distro.id())
print(distro.version())
print(distro.name())