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.1.tar.gz
(12.1 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.1-py3-none-any.whl
(10.1 kB
view details)
File details
Details for the file debx-0.1.1.tar.gz.
File metadata
- Download URL: debx-0.1.1.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78671ecedfcbf6461a9b39e0296561f7f27198459e451d8e2135f7be97ca64e5
|
|
| MD5 |
fb6f667aa7727615340b1affb2e45499
|
|
| BLAKE2b-256 |
4a3b9dbba8309dd5befd1e520a25255605aaeaff8515382ce2da9829c8b46780
|
File details
Details for the file debx-0.1.1-py3-none-any.whl.
File metadata
- Download URL: debx-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a92929e7e8193c921754d35d5bf003d290cdcde6f417b2fbce56d0c6df27c8f
|
|
| MD5 |
ee33aca460f802bea45080b292950096
|
|
| BLAKE2b-256 |
a9bbedf5fd3ad13994fbc33cedc8d69a5838e9b0234ef92e4cfa674a022a9acd
|