apt.package — Classes for package handling

Functionality related to packages.

The Package class

class apt.package.Package(pcache, pkgiter)

Representation of a package in a cache.

This class provides methods and properties for working with a package. It lets you mark the package for installation, check if it is installed, and much more.

Note

Several methods have been deprecated in version 0.7.9 of python-apt, please see the Version class for the new alternatives.

architecture

Return the Architecture of the package.

Deprecated since version 0.7.9.

candidate

Return the candidate version of the package.

This property is writeable to allow you to set the candidate version of the package. Just assign a Version() object, and it will be set as the candidate version.

New in version 0.7.9.

candidateDependencies

Return a list of candidate dependencies.

Deprecated since version 0.7.9.

candidateDownloadable

Return True if the candidate is downloadable.

Deprecated since version 0.7.9.

candidateInstalledSize

Return the size of the candidate installed package.

Deprecated since version 0.7.9.

candidateOrigin

Return a list of Origin() objects for the candidate version.

Deprecated since version 0.7.9.

candidateRecord

Return the Record of the candidate version of the package.

Deprecated since version 0.7.9.

candidateVersion

Return the candidate version as string.

Deprecated since version 0.7.9.

commit(fprogress, iprogress)

Commit the changes.

The parameter fprogress refers to a FetchProgress() object, as found in apt.progress.

The parameter iprogress refers to an InstallProgress() object, as found in apt.progress.

description

Return the formatted long description.

Return the formated long description according to the Debian policy (Chapter 5.6.13). See http://www.debian.org/doc/debian-policy/ch-controlfields.html for more information.

Deprecated since version 0.7.9.

getChangelog(uri=None, cancel_lock=None)

Download the changelog of the package and return it as unicode string.

The parameter uri refers to the uri of the changelog file. It may contain multiple named variables which will be substitued. These variables are (src_section, prefix, src_pkg, src_ver). An example is the Ubuntu changelog:

"http://changelogs.ubuntu.com/changelogs/pool" \
    "/%(src_section)s/%(prefix)s/%(src_pkg)s" \
    "/%(src_pkg)s_%(src_ver)s/changelog"

The parameter cancel_lock refers to an instance of threading.Lock, which if set, prevents the download.

homepage

Return the homepage field as string.

Deprecated since version 0.7.9.

id

Return a uniq ID for the package.

This can be used eg. to store additional information about the pkg.

installed

Return the currently installed version of the package.

New in version 0.7.9.

installedDependencies

Return a list of installed dependencies.

Deprecated since version 0.7.9.

installedDownloadable

Return True if the installed version is downloadable.

Deprecated since version 0.7.9.

installedFiles

Return a list of files installed by the package.

Return a list of unicode names of the files which have been installed by this package

installedPackageSize

Return the size of the installed deb package.

Deprecated since version 0.7.9.

installedPriority

Return the priority (of the installed version).

Deprecated since version 0.7.9.

installedRecord

Return the Record of the candidate version of the package.

Deprecated since version 0.7.9.

installedSize

Return the size of the currently installed package.

Deprecated since version 0.7.9.

installedVersion

Return the installed version as string.

Deprecated since version 0.7.9.

isAutoRemovable

Return True if the package is no longer required.

If the package has been installed automatically as a dependency of another package, and if no packages depend on it anymore, the package is no longer required.

isInstalled
Return True if the package is installed.
isUpgradable
Return True if the package is upgradable.
markDelete(autoFix=True, purge=False)

Mark a package for install.

If autoFix is True, the resolver will be run, trying to fix broken packages. This is the default.

If purge is True, remove the configuration files of the package as well. The default is to keep the configuration.

markInstall(autoFix=True, autoInst=True, fromUser=True)

Mark a package for install.

If autoFix is True, the resolver will be run, trying to fix broken packages. This is the default.

If autoInst is True, the dependencies of the packages will be installed automatically. This is the default.

If fromUser is True, this package will not be marked as automatically installed. This is the default. Set it to False if you want to be able to automatically remove the package at a later stage when no other package depends on it.

markKeep()
Mark a package for keep.
markUpgrade()
Mark a package for upgrade.
markedDelete
Return True if the package is marked for delete.
markedDowngrade
Package is marked for downgrade
markedInstall
Return True if the package is marked for install.
markedKeep
Return True if the package is marked for keep.
markedReinstall
Return True if the package is marked for reinstall.
markedUpgrade
Return True if the package is marked for upgrade.
name
Return the name of the package.
packageSize

Return the size of the candidate deb package.

Deprecated since version 0.7.9.

priority

Return the priority (of the candidate version).

Deprecated since version 0.7.9.

rawDescription

return the long description (raw).

Deprecated since version 0.7.9.

section
Return the section of the package.
sourcePackageName

Return the source package name as string.

Deprecated since version 0.7.9.

summary

Return the short description (one line summary).

Deprecated since version 0.7.9.

versions

Return a list of versions.

New in version 0.7.9.

The Version class

class apt.package.Version(package, cand)

Representation of a package version.

New in version 0.7.9.

architecture
Return the architecture of the package version.
dependencies
Return the dependencies of the package version.
description

Return the formatted long description.

Return the formated long description according to the Debian policy (Chapter 5.6.13). See http://www.debian.org/doc/debian-policy/ch-controlfields.html for more information.

downloadable
Return whether the version of the package is downloadable.
fetch_binary(destdir='', progress=None)

Fetch the binary version of the package.

The parameter destdir specifies the directory where the package will be fetched to.

The parameter progress may refer to an apt.progress.FetchProgress() object. If not specified or None, apt.progress.TextFetchProgress() is used.

New in version 0.7.10.

fetch_source(destdir='', progress=None, unpack=True)

Get the source code of a package.

The parameter destdir specifies the directory where the source will be fetched to.

The parameter progress may refer to an apt.progress.FetchProgress() object. If not specified or None, apt.progress.TextFetchProgress() is used.

The parameter unpack describes whether the source should be unpacked (True) or not (False). By default, it is unpacked.

If unpack is True, the path to the extracted directory is returned. Otherwise, the path to the .dsc file is returned.

filename

Return the path to the file inside the archive.

New in version 0.7.10.

homepage
Return the homepage for the package.
installed_size
Return the size of the package when installed.
md5

Return the md5sum of the binary.

New in version 0.7.10.

origins
Return a list of origins for the package version.
priority
Return the priority of the package, as string.
raw_description
return the long description (raw).
record
Return a Record() object for this version.
section
Return the section of the package.
sha1

Return the sha1sum of the binary.

New in version 0.7.10.

sha256

Return the sha256sum of the binary.

New in version 0.7.10.

size
Return the size of the package.
source_name
Return the name of the source package.
summary
Return the short description (one line summary).
uri

Return a single URI for the binary.

New in version 0.7.10.

uris

Return a list of all available uris for the binary.

New in version 0.7.10.

version
Return the version as a string.

Dependency Information

class apt.package.BaseDependency

The BaseDependency class defines various attributes for accessing the parts of a dependency. The attributes are as follows:

name
The name of the dependency
relation
The relation (>>,>=,==,<<,<=,)
version
The version or None.
preDepend
Boolean value whether this is a pre-dependency.
class apt.package.Dependency

The dependency class represents a Or-Group of dependencies. It provides an attribute to access the BaseDependency object for the available choices.

or_dependencies
A list of BaseDependency objects which could satisfy the requirement of the Or-Group.

Origin Information

class apt.package.Origin

The Origin class provides access to the origin of the package. It allows you to check the component, archive, the hostname, and even if this package can be trusted.

archive
The archive (eg. unstable)
component
The component (eg. main)
label
The Label, as set in the Release file
origin
The Origin, as set in the Release file
site
The hostname of the site.
trusted
Boolean value whether this is trustworthy. An origin can be trusted, if it provides a GPG-signed Release file and the GPG-key used is in the keyring used by apt (see apt-key).

Examples

import apt

cache = apt.Cache()
pkg = cache['python-apt'] # Access the Package object for python-apt
print 'python-apt is trusted:', pkg.candidate.origins[0].trusted

# Mark python-apt for install
pkg.markInstall()

print 'python-apt is marked for install:', pkg.markedInstall

print 'python-apt is (summary):', pkg.candidate.summary

# Now, really install it
cache.commit()