os-release Documentation¶
os-release is a simple Python module for reading systemd’s os-release information on modern Linux distributions.
It parses the contents of systemd’s os-release(5) files: /etc/os-release or /usr/lib/os-release.
Installation¶
os-release is available on PyPI.
Add it to your projects setup.py` ``install_requires:
install_requires=['os-release']
or install it directly via pip:
$ pip install os-release
Alternatively, clone the Git repository and run:
$ python setup.py install
Quick Start¶
The most common usage of this module is to call the os_release.current_release() method to obtain the details
of the operating system on which the calling Python program is running.
For example, on a CentOS 8 system:
>>> import os_release
>>> os_release.current_release()
OsRelease(
name='CentOS Linux',
version='8 (Core)',
id='centos',
id_like=('rhel', 'fedora'),
version_codename=None,
version_id='8',
pretty_name='CentOS Linux 8 (Core)',
ansi_color='0;31',
cpe_name='cpe:/o:centos:centos:8',
build_id=None,
variant=None,
variant_id=None,
logo=None,
urls=Urls(
home='https://www.centos.org/',
documentation=None,
support=None,
bug_report='https://bugs.centos.org/',
privacy_policy=None
),
vendor_extra={
'PLATFORM_ID': 'platform:el8',
'CENTOS_MANTISBT_PROJECT': 'CentOS-8',
'CENTOS_MANTISBT_PROJECT_VERSION': '8',
'REDHAT_SUPPORT_PRODUCT': 'centos',
'REDHAT_SUPPORT_PRODUCT_VERSION': '8'
}
)
API¶
-
class
os_release.OsRelease¶ Represents the fields of a systemd
os-releasefile.OsReleaseis atyping.NamedTuple.-
property
name¶ Equivalent to the
NAMEfield inos-release.As per os-release(5), this property will default to
LinuxifNAMEis not present inos-release.
-
property
version¶ Equivalent to the
VERSIONfield inos-release.This property is optional and will default to
NoneifVERSIONis not present inos-release.
-
property
id¶ Equivalent to the
IDfield inos-release.As per os-release(5), this property will default to
linuxifIDis not present inos-release.
-
property
id_like¶ Equivalent to the
ID_LIKEfield inos-release.The value of
ID_LIKEis automatically split on whitespace into a tuple.This property is optional and will default to an empty tuple if
ID_LIKEis not present inos-release.
-
property
version_codename¶ Equivalent to the
VERSION_CODENAMEfield inos-release.This property is optional and will default to
NoneifVERSION_CODENAMEis not present inos-release.
-
property
version_id¶ Equivalent to the
VERSION_IDfield inos-release.This property is optional and will default to
NoneifVERSION_IDis not present inos-release.
-
property
pretty_name¶ Equivalent to the
PRETTY_NAMEfield inos-release.As per os-release(5), this property will default to
LinuxifPRETTY_NAMEis not present inos-release.
-
property
ansi_color¶ Equivalent to the
ANSI_COLORfield inos-release.This property is optional and will default to
NoneifANSI_COLORis not present inos-release.
-
property
cpe_name¶ Equivalent to the
CPE_NAMEfield inos-release.This property is optional and will default to
NoneifCPE_NAMEis not present inos-release.
-
property
build_id¶ Equivalent to the
BUILD_IDfield inos-release.This property is optional and will default to
NoneifBUILD_IDis not present inos-release.
-
property
variant¶ Equivalent to the
VARIANTfield inos-release.This property is optional and will default to
NoneifVARIANTis not present inos-release.
-
property
variant_id¶ Equivalent to the
VARIANT_IDfield inos-release.This property is optional and will default to
NoneifVARIANT_IDis not present inos-release.
-
property
logo¶ Equivalent to the
LOGOfield inos-release.This property is optional and will default to
NoneifLOGOis not present inos-release.
-
property
urls¶ See
OsRelease.Urls.This property will always be an instance of
OsRelease.Urls, even if no*_URLfields are present inos-release.
-
property
vendor_extra¶ A dict of vendor-specific fields (fields that are unknown to os-release).
-
class
Urls¶ Represents the various
*_URLfields inos-release.-
property
home¶ Equivalent to the
HOME_URLfield inos-release.
-
property
documentation¶ Equivalent to the
DOCUMENTATION_URLfield inos-release.
-
property
support¶ Equivalent to the
SUPPORT_URLfield inos-release.
-
property
bug_report¶ Equivalent to the
BUG_REPORT_URLfield inos-release.
-
property
privacy_policy¶ Equivalent to the
PRIVACY_POLICY_URLfield inos-release.
-
property
-
property
-
os_release.current_release()¶ Return an
OsReleasetuple representing the contents of theos-releasefile for the current operating system.Tries to read the following files, in order (as per os-release(5)):
/etc/os-release/usr/lib/os-release
- Raises
FileNotFoundError – if no
os-releasefile can be found.OsReleaseParseException – if the
os-releasefile cannot be parsed.
- Return type