python-debian: Debian Data Format Manipulation

1.1.0 · active · verified Sun Apr 12

The `python-debian` library provides modules for reading and manipulating various Debian-related data formats, such as `debian/changelog`, `Packages` files, control files (e.g., `debian/control`, `.changes`, `.dsc`, `Packages`, `Sources`, `Release`), and raw `.deb` and `.ar` files. It supports both reading and editing for some formats. The current version is 1.1.0, and the project maintains an active release schedule, typically with updates every 1-2 years.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse a `debian/control` file using the `Deb822` module, which treats RFC822-style control data as a dictionary-like object, allowing easy access to package metadata.

from debian.deb822 import Deb822

# Example content of a debian/control file
control_content = """\
Package: my-package
Version: 1.0-1
Section: python
Priority: optional
Architecture: all
Depends: python3, python3-some-dependency (>= 1.2)
Description: A sample Python package.
 This is a longer description for the sample package.
"""

# In a real scenario, you'd open a file:
# with open("debian/control", "r") as f:
#     control_data = Deb822(f)

# For this quickstart, we use the string directly
control_data = Deb822(control_content.splitlines())

print(f"Package: {control_data['Package']}")
print(f"Version: {control_data['Version']}")
print(f"Dependencies: {control_data.get('Depends', 'N/A')}")

# The Deb822 object behaves like a dictionary
print("\nAll control fields:")
for key, value in control_data.items():
    print(f"  {key}: {value}")

view raw JSON →