High-performance delta compression library with automatic algorithm selection
Project description
xpatch-rs - Python Bindings
High-performance delta compression library for Python with automatic algorithm selection.
Installation
pip install xpatch-rs
Note: The package is named xpatch-rs on PyPI, but you import it as xpatch in your code.
Or build from source:
cd crates/xpatch-python
pip install maturin
maturin develop
Quick Start
import xpatch
# Create a delta patch
base = b"Hello, World!"
new = b"Hello, Rust!"
delta = xpatch.encode(tag=0, base_data=base, new_data=new)
# Apply the patch
reconstructed = xpatch.decode(base_data=base, delta=delta)
assert reconstructed == new
# Extract metadata tag
tag = xpatch.get_tag(delta)
print(f"Tag: {tag}")
API Reference
encode(tag, base_data, new_data, enable_zstd=True) -> bytes
Creates a delta patch between base_data and new_data.
Parameters:
tag(int): Metadata tag to embed (0-15 for no overhead, larger values supported)base_data(bytes): Original datanew_data(bytes): New dataenable_zstd(bool): Enable zstd compression (default: True)
Returns: bytes - The encoded delta patch
decode(base_data, delta) -> bytes
Reconstructs new_data from base_data and a delta patch.
Parameters:
base_data(bytes): Original datadelta(bytes): Delta patch created byencode()
Returns: bytes - The reconstructed new data
Raises: ValueError if delta is invalid
get_tag(delta) -> int
Extracts the metadata tag from a delta patch without decoding.
Parameters:
delta(bytes): Delta patch
Returns: int - The embedded tag
Raises: ValueError if delta is invalid
Performance
Native Python bindings provide excellent performance:
- Small data (~13 bytes): ~7 µs encode, <0.1 µs decode
- Medium data (10KB): ~8 µs encode, ~0.5 µs decode
- Large data (100KB): ~12 µs encode, ~4 µs decode
- Tag extraction: <0.1 µs
Compression ratios on test data:
- 1 byte change in 10KB file: 11 bytes delta (99.89% compression)
- 1 byte change in 100KB file: 14 bytes delta (99.99% compression)
Use Cases
Perfect for:
- Version control systems
- Document synchronization
- Incremental backups
- Network-efficient updates
- Real-time collaborative editing
License
This project is dual-licensed:
- AGPL-3.0-or-later for open-source use
- Commercial license available at xpatch-commercial@alias.oseifert.ch
See LICENSE-AGPL.txt and LICENSE-COMMERCIAL.txt for details.
Links
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
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
File details
Details for the file xpatch_rs-0.4.0.tar.gz.
File metadata
- Download URL: xpatch_rs-0.4.0.tar.gz
- Upload date:
- Size: 114.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56e1152876e08985bff226d60573b767281492cdc50e111ab17aae565118c2de
|
|
| MD5 |
98be6982ad0253d4f2ca4b8d2ea1c695
|
|
| BLAKE2b-256 |
073cab31eefd0b2a4f67225ec3e879a0458a4a28ebef15a64d25280c078788c0
|
File details
Details for the file xpatch_rs-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: xpatch_rs-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 746.9 kB
- Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d1191e55662a1db741e06084c7d4de514de9db9e43083b5a76be17d1ad5b80c
|
|
| MD5 |
f0c154c9464b53aff9b468f7d5cf0bd7
|
|
| BLAKE2b-256 |
762b1e5393cdafcab61c36b519515ea0e76d4421b9a46123f137869d59b0605b
|