deb-pkg-tools

raw JSON →
8.4 verified Mon Apr 27 auth: no python

A Python library for creating, inspecting, and manipulating Debian packages (.deb files). Version 8.4 is stable, with infrequent releases focused on maintenance.

pip install deb-pkg-tools
error ImportError: cannot import name 'DebPackage' from 'deb_pkg_tools'
cause Trying to import DebPackage from the top-level deb_pkg_tools package, but it resides in the submodule deb_pkg_tools.package.
fix
Use: from deb_pkg_tools.package import DebPackage
error TypeError: DebPackage() takes 1 positional argument but 2 were given
cause Attempting to pass a control dictionary as a positional argument. In version 8, the constructor expects keyword arguments.
fix
Use DebPackage(control=control) or DebPackage(path='path/to.deb')
breaking Version 8 changed the API: DebPackage constructor now requires keyword arguments (e.g., control=) instead of positional.
fix Use DebPackage(control=control) instead of DebPackage(control).
gotcha When reading a .deb file, the control data is accessed via attributes (pkg.name) and not via a dictionary. Mixing up with DebPackage.control (the dict used at creation) can cause confusion.
fix Use pkg.name, pkg.version, etc. For raw control data, use pkg._control_data (private).
deprecated The function deb_pkg_tools.utils.read_control_file is deprecated in favour of DebPackage.from_control_file or the package constructor.
fix Replace with DebPackage.from_control_file(control_path) if you have a control file.

Basic usage: inspect an existing .deb or create a new one from a control dictionary.

from deb_pkg_tools.package import DebPackage

# Load an existing .deb file
pkg = DebPackage('path/to/package.deb')
print(pkg.name, pkg.version)

# Create a new basic package
control = {
    'Package': 'example',
    'Version': '1.0',
    'Architecture': 'all',
    'Maintainer': 'Example <example@example.com>',
    'Description': 'An example package'
}
new_pkg = DebPackage(control=control)
new_pkg.write('example_1.0_all.deb')