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-release
file.OsRelease
is atyping.NamedTuple
.-
property
name
¶ Equivalent to the
NAME
field inos-release
.As per os-release(5), this property will default to
Linux
ifNAME
is not present inos-release
.
-
property
version
¶ Equivalent to the
VERSION
field inos-release
.This property is optional and will default to
None
ifVERSION
is not present inos-release
.
-
property
id
¶ Equivalent to the
ID
field inos-release
.As per os-release(5), this property will default to
linux
ifID
is not present inos-release
.
-
property
id_like
¶ Equivalent to the
ID_LIKE
field inos-release
.The value of
ID_LIKE
is automatically split on whitespace into a tuple.This property is optional and will default to an empty tuple if
ID_LIKE
is not present inos-release
.
-
property
version_codename
¶ Equivalent to the
VERSION_CODENAME
field inos-release
.This property is optional and will default to
None
ifVERSION_CODENAME
is not present inos-release
.
-
property
version_id
¶ Equivalent to the
VERSION_ID
field inos-release
.This property is optional and will default to
None
ifVERSION_ID
is not present inos-release
.
-
property
pretty_name
¶ Equivalent to the
PRETTY_NAME
field inos-release
.As per os-release(5), this property will default to
Linux
ifPRETTY_NAME
is not present inos-release
.
-
property
ansi_color
¶ Equivalent to the
ANSI_COLOR
field inos-release
.This property is optional and will default to
None
ifANSI_COLOR
is not present inos-release
.
-
property
cpe_name
¶ Equivalent to the
CPE_NAME
field inos-release
.This property is optional and will default to
None
ifCPE_NAME
is not present inos-release
.
-
property
build_id
¶ Equivalent to the
BUILD_ID
field inos-release
.This property is optional and will default to
None
ifBUILD_ID
is not present inos-release
.
-
property
variant
¶ Equivalent to the
VARIANT
field inos-release
.This property is optional and will default to
None
ifVARIANT
is not present inos-release
.
-
property
variant_id
¶ Equivalent to the
VARIANT_ID
field inos-release
.This property is optional and will default to
None
ifVARIANT_ID
is not present inos-release
.
-
property
logo
¶ Equivalent to the
LOGO
field inos-release
.This property is optional and will default to
None
ifLOGO
is not present inos-release
.
-
property
urls
¶ See
OsRelease.Urls
.This property will always be an instance of
OsRelease.Urls
, even if no*_URL
fields 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
*_URL
fields inos-release
.-
property
home
¶ Equivalent to the
HOME_URL
field inos-release
.
-
property
documentation
¶ Equivalent to the
DOCUMENTATION_URL
field inos-release
.
-
property
support
¶ Equivalent to the
SUPPORT_URL
field inos-release
.
-
property
bug_report
¶ Equivalent to the
BUG_REPORT_URL
field inos-release
.
-
property
privacy_policy
¶ Equivalent to the
PRIVACY_POLICY_URL
field inos-release
.
-
property
-
property
-
os_release.
current_release
()¶ Return an
OsRelease
tuple representing the contents of theos-release
file 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-release
file can be found.OsReleaseParseException – if the
os-release
file cannot be parsed.
- Return type