debian-inspector

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

Utilities to parse Debian package, control, and copyright files. Current version 31.1.1, with a recent release cadence (multiple minor releases in 2025). Requires Python >=3.9.

pip install debian-inspector
error AttributeError: module 'debian_inspector' has no attribute 'DpkgHandler'
cause Old import path `from debian_inspector.dpkg import DpkgHandler` used; DpkgHandler is now at top level.
fix
Use from debian_inspector import DpkgHandler instead.
error TypeError: DpkgHandler.__init__() takes 1 positional argument but 2 were given
cause Passed a file path string instead of file content. DpkgHandler expects a single string content.
fix
Open the file, read its content, and pass the content string: DpkgHandler(open('file').read()).
error KeyError: 'licence'
cause In v31.0.0, the 'licence' field in Debian copyright files is normalized to 'license'.
fix
Access the field using 'license' instead of 'licence'.
breaking In v31.0.0, the function `get_license_detection_from_nameless_paragraph` was renamed from a previous name? Actually it's a fix: the `licence` field in copyright files is now normalized to `license`. Code relying on the old field name `licence` may break.
fix Update any code that references 'licence' field in copyright paragraphs to use 'license'.
deprecated Direct import from submodules like `debian_inspector.dpkg` or `debian_inspector.copyright` is discouraged. Use top-level imports.
fix Change imports to `from debian_inspector import DpkgHandler, Copyright, get_license_detection_from_nameless_paragraph`.
gotcha The class `DpkgHandler` expects a single string (the full control file content), not a file path. Passing a file path will raise an error.
fix Read the file content first: `with open('control') as f: text = f.read(); handler = DpkgHandler(text)`.

Parses a control file and a copyright file using top-level API.

from debian_inspector import DpkgHandler, Copyright

# Parse a Debian control file (e.g., debian/control)
with open('control', 'r') as f:
    control_text = f.read()
handler = DpkgHandler(control_text)
print(handler.paragraphs[0].get('Package'))

# Parse a copyright file (e.g., /usr/share/doc/*/copyright)
with open('copyright', 'r') as f:
    copyright_text = f.read()
copyright_obj = Copyright(copyright_text)
print(copyright_obj.paragraphs_license_expression())