Programmatically get update list

I am trying to create a tool to inspect changes in updated packages. DNF doesn’t provide any JSON or CSV or output templates, and the best output I could find is dnf check-update -q.

The output is not ideal. First there is an empty string, and then a specially artcrafted obsoleted section.

adwaita-cursor-theme.noarch         3.34.3-2.fc31              updates               
adwaita-icon-theme.noarch           3.34.3-2.fc31              updates               
at-spi2-atk.x86_64                  2.34.2-1.fc31              updates               
autocorr-en.noarch                  1:           updates               
conky.x86_64                        1.11.5-3.fc31              updates               
wine-filesystem.noarch              5.3-1.fc31                 updates               
wireless-tools.x86_64               1:29-25.fc31               updates               
youtube-dl.noarch                   2020.03.01-1.fc31          updates               
Obsoleting Packages
fonts-filesystem.noarch             2.0.1-3.fc31               updates               
    fontpackages-filesystem.noarch  1.44-25.fc31               @fedora               
kernel-headers.x86_64               5.5.8-200.fc31             updates               
    kernel-headers.x86_64           5.5.6-200.fc31             @updates   

Is there an (better) API for that?

dnf is written in Python, so it effectively is a Python API. If you write Python code using the dnf module, you can pretty much do anything command-line dnf does, and output it in whatever format you like. (If you even need to output it at all, since working in Python there’d be no need to bother.)

So, for instance, the dnf check-update command is implemented in dnf.cli.commands — it’s actually the CheckUpdateCommand class in the __init__py file, which is probably located at:


For my tool I am using go and the command line API is all I have. I don’t think it is possible to call Python API from go.

Mmm, probably not. But a Python script that output results in e.g. JSON, using the dnf package APIs and the json module (part of the Python3 standard lib), wouldn’t be too painful to write.

And if you are/were planning (or willing) to call command-line dnf and parse its output, also no different.

I tried once writing Python script to make queries like this and it was painful. It was not some well formatted OpenAPI spec, but almost one to one wrapper over underlying C libraries.

Parsing output doesn’t require sudo installation of plugin. The ideal case is if dnf command line provided generalized query interface to output desired CSV or JSON using Go templates.