Minimal Python library to programmatically construct Debian .deb packages
Project description
debx
A lightweight Python library for creating, reading, and manipulating Debian package (.deb) files.
Features
- Read and extract content from Debian packages
- Create custom Debian packages programmatically
- Parse and manipulate Debian control files (RFC822-style format)
- Low-level AR archive manipulation
- No external dependencies - uses only Python standard library
Installation
pip install debx
Quick Start
Reading a Debian Package
from debx import DebReader
# Open a .deb file
with open("package.deb", "rb") as f:
reader = DebReader(f)
# Extract control file
control_file = reader.control.extractfile("control")
control_content = control_file.read().decode("utf-8")
print(control_content)
# List files in the data archive
print(reader.data.getnames())
# Extract a file from the data archive
file_data = reader.data.extractfile("usr/bin/example").read()
Creating a Debian Package
from debx import DebBuilder, Deb822
# Initialize the builder
builder = DebBuilder()
# Create control information
control = Deb822({
"Package": "example",
"Version": "1.0.0",
"Architecture": "all",
"Maintainer": "Example Maintainer <maintainer@example.com>",
"Description": "Example package\n This is an example package created with debx.",
"Section": "utils",
"Priority": "optional"
})
# Add control file
builder.add_control_entry("control", control.dump())
# Add files to the package
builder.add_data_entry(b"#!/bin/sh\necho 'Hello, world!'\n", "/usr/bin/example", mode=0o755)
# Add a symlink
builder.add_data_entry(b"", "/usr/bin/example-link", symlink_to="/usr/bin/example")
# Build the package
with open("example.deb", "wb") as f:
f.write(builder.pack())
Working with Debian Control Files
from debx import Deb822
# Parse a control file
control = Deb822.parse("""
Package: example
Version: 1.0.0
Description: Example package
This is a multi-line description
with several paragraphs.
""")
print(control["Package"]) # "example"
print(control["Description"]) # Contains the full multi-line description
# Modify a field
control["Version"] = "1.0.1"
# Add a new field
control["Priority"] = "optional"
# Write back to string
print(control.dump())
License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
debx-0.1.0.tar.gz
(9.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
debx-0.1.0-py3-none-any.whl
(7.7 kB
view details)
File details
Details for the file debx-0.1.0.tar.gz.
File metadata
- Download URL: debx-0.1.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
655d409b02d66d7e01c6aad24cece0dae4f05b49f84e14df241f6ccdc6bd6971
|
|
| MD5 |
52e82bd993fc5e2efacc722347def0c2
|
|
| BLAKE2b-256 |
26d1ddf26e9f749d9bf90cb212c79e79bed92ba3996c5b32a18e7fa25d36cbf1
|
File details
Details for the file debx-0.1.0-py3-none-any.whl.
File metadata
- Download URL: debx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef7e54471ba0532e131e312c9194cfc72c7e1bf807defc84ae1300a119693114
|
|
| MD5 |
a1879a92570b93df255ecddd9ea34e71
|
|
| BLAKE2b-256 |
b2dadfeb2979610cde5583a58bcaccd26df295d24294e061ba549c47ee3a2188
|