Distro - an OS platform information API
—
Essential functions for identifying and describing the operating system distribution. These functions provide the primary interface for getting distribution identity, names, versions, and related information.
Returns the machine-readable distribution identifier, normalized across different data sources.
def id() -> str:
"""
Return the distribution ID in lower case.
For example: 'ubuntu', 'centos', 'debian', 'fedora', 'rhel', 'opensuse'
The ID is obtained from os-release, lsb_release, or distro release files,
with normalization applied via NORMALIZED_OS_ID, NORMALIZED_LSB_ID,
and NORMALIZED_DISTRO_ID tables.
Returns:
str: Machine-readable distribution ID
"""Usage example:
import distro
dist_id = distro.id()
print(f"Distribution ID: {dist_id}") # e.g., "ubuntu"Returns the human-readable distribution name, with optional pretty formatting.
def name(pretty: bool = False) -> str:
"""
Return the distribution name.
Args:
pretty: If True, include version and codename in the output
Returns:
str: Distribution name
Examples:
name() -> "Ubuntu"
name(pretty=True) -> "Ubuntu 20.04 LTS (Focal Fossa)"
"""Usage examples:
import distro
# Basic name
print(distro.name()) # "Ubuntu"
# Pretty formatted name with version and codename
print(distro.name(pretty=True)) # "Ubuntu 20.04 LTS (Focal Fossa)"Returns the distribution version string with optional formatting and precision control.
def version(pretty: bool = False, best: bool = False) -> str:
"""
Return the distribution version.
Args:
pretty: If True, include codename in parentheses
best: If True, return the most precise version from all sources
Returns:
str: Distribution version
Examples:
version() -> "20.04"
version(pretty=True) -> "20.04 (Focal Fossa)"
version(best=True) -> "20.04.3"
"""Usage examples:
import distro
# Basic version
print(distro.version()) # "20.04"
# Pretty version with codename
print(distro.version(pretty=True)) # "20.04 (Focal Fossa)"
# Most precise version available
print(distro.version(best=True)) # "20.04.3"Returns the distribution release codename.
def codename() -> str:
"""
Return the distribution codename.
The codename is the release name given by the distribution maintainer,
such as "focal" for Ubuntu 20.04 or "buster" for Debian 10.
Returns:
str: Distribution codename, empty string if not available
Examples:
"focal", "buster", "tumbleweed", "rolling"
"""Usage example:
import distro
codename = distro.codename()
print(f"Codename: {codename}") # e.g., "focal"Returns space-separated list of distributions that this distribution is based on or similar to.
def like() -> str:
"""
Return the distribution's "like" attribute from os-release.
This indicates what other distributions this one is based on or compatible with.
Multiple distributions are space-separated.
Returns:
str: Space-separated list of like distributions
Examples:
"debian" (for Ubuntu)
"rhel centos fedora" (for Rocky Linux)
"" (empty for base distributions)
"""Usage example:
import distro
like = distro.like()
print(f"Based on: {like}") # e.g., "debian"Returns complete distribution information as a structured dictionary.
def info(pretty: bool = False, best: bool = False) -> InfoDict:
"""
Return comprehensive distribution information.
Args:
pretty: If True, use pretty formatting for name and version
best: If True, use most precise version available
Returns:
InfoDict: Dictionary containing all distribution information
Structure:
{
"id": str,
"version": str,
"version_parts": {
"major": str,
"minor": str,
"build_number": str
},
"like": str,
"codename": str
}
"""Usage example:
import distro
# Basic info
info = distro.info()
print(info)
# {
# "id": "ubuntu",
# "version": "20.04",
# "version_parts": {"major": "20", "minor": "04", "build_number": ""},
# "like": "debian",
# "codename": "focal"
# }
# Pretty formatted info
pretty_info = distro.info(pretty=True, best=True)
print(pretty_info["version"]) # "20.04.3 (Focal Fossa)"from typing import TypedDict
class VersionDict(TypedDict):
major: str
minor: str
build_number: str
class InfoDict(TypedDict):
id: str
version: str
version_parts: VersionDict
like: str
codename: strInstall with Tessl CLI
npx tessl i tessl/pypi-distro