pydoc > apt_pkg

πŸ“› NAME

apt_pkg - Classes and functions wrapping the apt-pkg library.

πŸš€ Quick Reference

Use CaseCommandDescription
πŸ—‚οΈ Open package cachecache = apt_pkg.Cache(progress)Load APT cache, optionally with progress reporting
πŸ” Access a packagepkg = cache['apt']Get a Package object by name (or tuple name, arch)
πŸ“¦ List all packagesfor pkg in cache.packages:Iterate over every package in the cache
βš™οΈ Mark for installdepcache.mark_install(pkg)Mark a package for installation (with auto_inst, from_user)
πŸ—‘οΈ Mark for removaldepcache.mark_delete(pkg, purge=True)Mark package for deletion (or purging)
βœ… Commit changesdepcache.commit(acquire_progress, install_progress)Fetch and install marked packages
πŸ”§ Read configurationval = apt_pkg.config.find('APT::Get::Assume-Yes')Retrieve a configuration value with optional default
πŸ“‹ Parse dependenciesdeps = apt_pkg.parse_depends('apt (>= 1.0)')Return parsed dependency lists
πŸ”’ System lockwith apt_pkg.SystemLock():Context manager for global dpkg/apt lock
πŸ“₯ Fetch filesacquire = apt_pkg.Acquire(progress)Coordinate network/copy file retrieval

πŸ“– DESCRIPTION

The apt_pkg module provides several classes and functions for accessing the functionality provided by the apt-pkg library. Typical uses might include reading APT index files and configuration files and installing or removing packages.

πŸ“¦ CLASSES

_PackageManager(builtins.object) β†’ PackageManager
builtins.SystemError(builtins.Exception) β†’ Error
builtins.ValueError(builtins.Exception) β†’ CacheMismatchError
builtins.object
   Acquire
   AcquireItem β†’ AcquireFile
   AcquireItemDesc
   AcquireWorker
   ActionGroup
   Cache
   Cdrom
   Configuration
   DepCache
   Dependency
   DependencyList
   Description
   FileLock
   Group
   GroupList
   HashString
   HashStringList
   Hashes
   IndexFile
   MetaIndex
   OrderList
   Package
   PackageFile
   PackageList
   PackageRecords
   Policy
   ProblemResolver
   SourceList
   SourceRecordFiles
   SourceRecords
   SystemLock
   Tag β†’ TagRemove, TagRename, TagRewrite
   TagFile
   TagSection
   Version

πŸ—οΈ Acquire

Acquire([progress: apt.progress.base.AcquireProgress])

πŸ“₯ Coordinate file retrieval via network or local (copy:/). Optional progress object reports progress.

πŸ“Š Data descriptors:

🏷️ Constants:

πŸ“„ AcquireFile

AcquireFile(owner, uri[, hash, size, descr, short_descr, destdir, destfile])

πŸ“₯ Represent a file to be fetched. Owner is an Acquire object. Optional parameters for hashes, size, descriptions, and destination.

Inherits from AcquireItem. See that class for common descriptors.

πŸ“¦ AcquireItem

❗ Cannot be instantiated directly; use AcquireFile.

πŸ“Š Data descriptors:

🏷️ Constants:

πŸ“ AcquireItemDesc

πŸ“‹ Provide description and URI of an item. Used by progress classes.

πŸ“Š Data descriptors:

πŸ‘· AcquireWorker

πŸ‘· Represent a sub-process fetching files using methods from Dir::Bin::Methods.

πŸ“Š Data descriptors:

⚑ ActionGroup

ActionGroup(depcache)

⚑ Disable cleanup actions for faster batch modifications. Use as context manager or call release(). Example:

with apt_pkg.ActionGroup(depcache):
    depcache.markInstall(pkg)

πŸ—‚οΈ Cache

Cache([progress]) -> Cache() object.

πŸ“‡ In‑core representation of the APT cache. Provides access to available packages, mapping names to Package objects. Optional progress for loading.

πŸ“Š Data descriptors:

🚫 CacheMismatchError

❌ Raised when an object from a different cache is passed to DepCache methods. Inherits from ValueError.

πŸ’Ώ Cdrom

Cdrom()

πŸ’Ώ Identify and add Debian installation media to /etc/apt/sources.list.

βš™οΈ Configuration

Configuration()

πŸ”§ Map option keys to values, reading from config files. The global apt_pkg.config is the most important instance.

πŸ“¦ DepCache

DepCache(cache: apt_pkg.Cache)

πŸ“¦ Holds extra state on packages: marks, broken status, etc. Required for package manipulation.

πŸ“Š Data descriptors:

πŸ”— Dependency

πŸ”— Represent a dependency from one package version to a package, optionally with a version relation.

πŸ“Š Data descriptors:

🏷️ Constants:

πŸ“‹ DependencyList

πŸ“‹ Efficient list-like type for Dependency objects. Supports __getitem__ and __len__.

πŸ“„ Description

πŸ“„ Represent a package description and attributes (e.g., for translations).

πŸ“Š Data descriptors:

❌ Error

❌ Exception class for most python-apt exceptions. Inherits from SystemError (catch this first). Introduced in 1.1.

πŸ”’ FileLock

SystemLock(filename: str)

πŸ”’ Context manager for file-based locking. Usage:

with apt_pkg.FileLock(filename):
    ...

πŸ“¦ Group

Group(cache, name)

πŸ“¦ Group of packages sharing the same name. Supports iteration and find_package(architecture), find_preferred_package(prefer_non_virtual=True).

πŸ“‹ GroupList

πŸ“‹ Efficient internal representation for the groups attribute of Cache. Supports __getitem__ and __len__.

πŸ” HashString

HashString(type, hash) or HashString('type:hash')

πŸ” Store a hash and its type (MD5Sum, SHA1, SHA256). Supports comparison operators and verify_file(filename).

πŸ“Š Data descriptors:

πŸ“‹ HashStringList

HashStringList()

πŸ“‹ Manage a list of HashString objects. Knows the best hash and provides verify_file(filename).

πŸ“Š Data descriptors:

πŸ” Hashes

Hashes([object: (bytes, file)])

πŸ” Calculate all supported hashes for a given object (bytes, file descriptor, or file-like with fileno()).

πŸ“Š Data descriptors:

πŸ“‘ IndexFile

πŸ“‘ Represent an index file (package indexes, translation indexes, source indexes).

πŸ“Š Data descriptors:

🌐 MetaIndex

🌐 Provide information about meta-indexes (Release files): trusted status, URI, distribution, and list of IndexFile objects.

πŸ“Š Data descriptors:

πŸ“‹ OrderList

OrderList(depcache: DepCache)

πŸ“‹ Sequence type for packages with ordering methods for configuration and unpacking.

🏷️ Flags:

πŸ“¦ Package

πŸ“¦ Represent a package. Access versions via version_list, and manipulate with DepCache.

πŸ“Š Data descriptors:

πŸ“‘ PackageFile

πŸ“‘ An index file stored in the cache with extra metadata.

πŸ“Š Data descriptors:

πŸ“‹ PackageList

πŸ“‹ Efficient internal representation for the packages attribute of Cache. Supports __getitem__ and __len__.

πŸ“¦ PackageManager

PackageManager(depcache: apt_pkg.DepCache)

πŸ“¦ Fetch and install packages marked in the depcache. Override methods to implement custom behavior.

🏷️ Constants:

πŸ“„ PackageRecords

PackageRecords(cache: apt_pkg.Cache)

πŸ“„ Retrieve package metadata like maintainer, filename, hashes, and raw record.

πŸ“Š Data descriptors:

🎯 Policy

Policy(cache)

🎯 Representation of the cache policy; creates pins, reads pin files, and overrides priorities.

πŸ”§ ProblemResolver

ProblemResolver(depcache: apt_pkg.DepCache)

πŸ”§ Resolve dependency problems by marking packages for installation/removal.

πŸ“‹ SourceList

SourceList()

πŸ“‹ Represent the list of sources from /etc/apt/sources.list and similar files.

πŸ“Š Data descriptors:

πŸ“„ SourceRecordFiles

SourceRecordFile()

πŸ“„ Look up source package file records. Supports __getitem__ and __len__.

πŸ“Š Data descriptors:

πŸ“„ SourceRecords

SourceRecords()

πŸ“„ Look up source package records. Iterate with lookup() or step().

πŸ“Š Data descriptors:

πŸ”’ SystemLock

SystemLock()

πŸ”’ Context manager for the global dpkg/apt lock. Usage:

with apt_pkg.SystemLock():
    ...

🏷️ Tag

🏷️ Abstract base for actions on a tag section. Subclasses: TagRemove, TagRename, TagRewrite.

πŸ“Š Data descriptors:

🏷️ Constants:

🏷️ TagRemove

TagRemove(name: str) – πŸ—‘οΈ Remove the tag name from the section.

🏷️ TagRename

TagRename(old_name: str, new_name: str) – πŸ”„ Rename old_name to new_name.

🏷️ TagRewrite

TagRewrite(name: str, data: str) – ✏️ Change the tag value to data.

πŸ“„ TagFile

TagFile(file, [bytes: bool = False])

πŸ“„ Access debian control files (multiple RFC822 sections). Iterate to get TagSection objects, or use step() / jump().

πŸ“Š Data descriptors:

πŸ“„ TagSection

TagSection(text: str, [bytes: bool = False])

πŸ“„ Access a single RFC822-style section. Read‑only dictionary with additional methods.

🏷️ Version

🏷️ Represent a package version. Supports comparison operators.

πŸ“Š Data descriptors:

🏷️ Multi‑arch constants:

πŸ”§ FUNCTIONS

πŸ” base64_encode

base64_encode(value: bytes) -> str

πŸ” Encode a bytestring to Base64. Input must not contain a null byte.

πŸ”— check_dep

check_dep(pkg_ver: str, dep_op: str, dep_ver: str) -> bool

πŸ”— Check that version pkg_ver matches dep_ver under operator dep_op (<,<=,=,>=,>). Example:

apt_pkg.check_dep('1', '
apt_pkg
πŸ“› NAME πŸš€ Quick Reference πŸ“– DESCRIPTION πŸ“¦ CLASSES πŸ”§ FUNCTIONS

Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 16:13 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^