API - HorlogeSkynet/archey4 GitHub Wiki

From the Python package

Since v4.4.0, Archey lives as a proper Python package (archey).
This means you can use it within your own Python programs, for instance, as below :

from archey.entries.gpu import GPU

gpu = GPU()

for element in gpu.value:
    print(element)

Since v4.11.0, Archey may raise ArcheyException. You can catch it this way for instance :

from archey.exceptions import ArcheyException
from archey.entries.uptime import Uptime

try:
    uptime = Uptime()
except ArcheyException as e:
    # ...
    pass
else:
    print(uptime.value)

From JSON output

Since v4.7.2, Archey is able to output its entries as JSON :

# Use multiple `-j` flags to increase indentation level.
python3 -m archey -jjj
{
    "data": {  # Configured entries name and respective values (order is not guaranteed for Python < 3.6).
        "Distro": {
            "name": "Debian GNU/Linux 10 (buster)",
            "arch": "x86_64"
        },
        "Kernel": {
            "release": "4.19.0-13-amd64",
            "latest": null,
            "is_outdated": null
        },
        "Uptime": {
            "days": 2,
            "hours": 20,
            "minutes": 54,
            "seconds": 49
        },
        "Processes": 256
    },
    "meta": {
        "version": [4, 10, 0],                 # Version of Archey (Semver segments).
        "date": "2020-12-19T12:19:31.407505",  # Sample datetime in ISO format.
        "count": 4,                            # Number of entries in the document `data` section.
        "distro": "debian"                     # Since v4.11.0, the distribution identifier internally used.
    }
}

You can easily retrieve something valuable, for instance, this way :

archey -j | jq -r '.data.Kernel.release'
4.19.0-13-amd64