Using Python to check for APT updates
The python3-apt library that comes with Debian can be used to do most of what apt does from Python. Read only operations can even be performed by unprivileged users. For example to check if there are pending updates:
import apt
with apt.Cache() as cache:
cache.upgrade() # Only reads the packages to upgrade
packages_to_upgrade = cache.get_changes()
Note that the library is not available on PyPI. To use it in a virtual environment install it with apt and create the venv with:
python3 -m venv --system-site-packages venv