Skip to main content

decayfmt-py

This package is no longer maintained. 0.2.1 is the final release. It stays installable and works with files written by decayfmt 0.2, but it will not follow later versions of the format. The Rust crate and CLI continue at decayfmt.

A file format where decay is a first-class property: every open permanently corrupts the file.

This is the Python binding for the decayfmt format. Install it with pip install decayfmt-py; the module you import is decayfmt. Encode a clean file once, then let it decay one open at a time. Each open replaces a random slice of the payload with noise and writes it back to disk. A corrupted file cannot be restored from its own contents. The header is immutable; only the payload decays.

The binding wraps the same Rust library the CLI uses, so behavior, statistics, and errors are identical.

Install

pip install decayfmt-py

Requires Python 3.11+. Wheels are built from Rust via PyO3 (abi3), so no Rust toolchain is needed at install time.

Quickstart

import decayfmt

# Encode a clean text file. The extension carries the type and the decay rate:
# `tdcy<x>` = text, `idcy<x>` = image, `adcy<x>` = audio, x = instability
# (higher decays faster).
decayfmt.encode_file("notes.txt", "notes.tdcy5")

# Open it five times. Each open permanently corrupts the file on disk.
for _ in range(5):
    kind, dims, data = decayfmt.decay_file("notes.tdcy5")
    print(data[16:].decode("utf-8", errors="replace"))

# Work purely in memory instead: each call decays a fresh copy of the bytes.
data = b"the quick brown fox jumps over the lazy dog"
for _ in range(8):
    data = decayfmt.corrupt_bytes(data, 1.0, "text")
print(data.decode("utf-8", errors="replace"))

# Zero-copy decay of a mutable buffer:
buf = bytearray(b"some text that will decay")
decayfmt.corrupt_in_place(buf, 10.0, "text")

Corruption probability per eligible byte is p = 1 - exp(-x / 10): x = 1 corrupts roughly 9.5% per open, x = 10 roughly 63%. Image corruption touches only the R, G, and B channels, so transparency (alpha) is never damaged. Text corruption replaces bytes with printable ASCII, so at high x it can break UTF-8 sequences. Audio corruption displaces whole 16-bit samples by an amount bounded by x, so a clip keeps its length however far it decays.

API

Function Returns Notes
corrupt_bytes(data, x, kind) -> bytes corrupted copy kind is "image", "text", or "audio"; immutable bytes are copied once
corrupt_in_place(buffer, x, kind) -> None nothing mutates a bytearray in place, no copy; for a memoryview use bytearray(mv)
encode_file(source_path, output_path) -> None nothing same as the CLI encode; output name decides type and x
encode_bytes(source, output_path) -> None nothing encodes in-memory bytes (image and audio formats decoded, text validated as UTF-8)
decay_file(path) -> (kind, dims, bytes) type label, (w, h) or None, full file bytes permanently corrupts the file on disk, no display
parse_filename(name) -> (kind, x) type label, x "photo.idcy3" → ("image", 3.0)
read_header(data) -> (kind, dims) type label, (w, h) or None reads the 16-byte header
write_header(kind, width=None, height=None, sample_rate=None, channels=None) -> bytes 16-byte header image requires width and height; audio requires sample_rate and channels
decayfmt.__version__ version string matches the installed package version

x is not clamped: x <= 0 corrupts nothing, and large x approaches corrupting every byte. The CLI reads x from filenames as a positive integer; the API accepts any float.

Errors

Failures raise built-in exceptions with the exact message the CLI would print:

  • OSError for filesystem read/write failures (includes the OS error string).
  • PermissionError for a read-only target, where the corrupted payload cannot be written back.
  • ValueError for everything else: wrong magic bytes, unknown version, bad filename convention, invalid UTF-8 at encode, undecodable image or audio, and so on.

Threading

The GIL is released while corruption, encoding, and file operations run, and large payloads (≥ 1 MiB) are corrupted in parallel across cores. Corruption is drawn from generators seeded by operating system entropy, so the corruption sequence cannot be replayed.

corrupt_in_place holds a buffer export on the bytearray for the duration of the call, so resizing it from another thread meanwhile raises BufferError in that thread.

Image formats

encode_file / encode_bytes accept whatever the underlying Rust image library decodes: PNG, JPEG, GIF, WebP, TIFF, QOI, BMP, DDS, EXR, HDR, ICO, PNM, TGA, and farbfeld. Images are stored as raw RGBA, so any format the library can decode becomes a decaying image.

Audio formats

WAV, FLAC, MP3, and OGG Vorbis sources are decoded to raw interleaved signed 16-bit PCM, so an encoded audio file is much larger than a compressed source.

License

MIT. Same license as the decayfmt project.

Metadata

Release files for decayfmt-py 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for decayfmt-py 0.2.1
File Actions
decayfmt_py-0.2.1-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for decayfmt_py-0.2.1-cp311-abi3-win_amd64.whl
decayfmt_py-0.2.1-cp311-abi3-manylinux_2_34_x86_64.whl CPython 3.11 abi3 Linux glibc 2.34+ x86-64 Details for decayfmt_py-0.2.1-cp311-abi3-manylinux_2_34_x86_64.whl
decayfmt_py-0.2.1-cp311-abi3-manylinux_2_34_aarch64.whl CPython 3.11 abi3 Linux glibc 2.34+ ARM64 Details for decayfmt_py-0.2.1-cp311-abi3-manylinux_2_34_aarch64.whl
decayfmt_py-0.2.1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for decayfmt_py-0.2.1-cp311-abi3-macosx_11_0_arm64.whl

Total release size: 5.4 MB

Release files / decayfmt_py-0.2.1-cp311-abi3-win_amd64.whl

Download URL decayfmt_py-0.2.1-cp311-abi3-win_amd64.whl
Size 1.3 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
bbf2750bfead7bc5e624e986d7c740d8496edb0db9b267ce3abf20b91b14bdfc
BLAKE2b-256 checksum
How to use checksums
93a0248c576a9bf15b1236bbcf9daf49be004e29d4b5e89cf4f9440e4ee3b303
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / decayfmt_py-0.2.1-cp311-abi3-manylinux_2_34_x86_64.whl

Download URL decayfmt_py-0.2.1-cp311-abi3-manylinux_2_34_x86_64.whl
Size 1.4 MB
Tags CPython 3.11 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
1f616bd51a8105b1bd2e0e1643b8a13a77f0d5c2a14c9088d0a412831a6b1c2b
BLAKE2b-256 checksum
How to use checksums
0f4605756c6805e4cba06c0b385cf3d8d253f34fa64d0fabfb1db38e9423ae88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / decayfmt_py-0.2.1-cp311-abi3-manylinux_2_34_aarch64.whl

Download URL decayfmt_py-0.2.1-cp311-abi3-manylinux_2_34_aarch64.whl
Size 1.3 MB
Tags CPython 3.11 Linux glibc 2.34+ ARM64 abi3
SHA-256 checksum
How to use checksums
c150d96b32eead1b56fc521b85b7508546ad65d3c44efe5d163e3e410abaf00b
BLAKE2b-256 checksum
How to use checksums
71607e1534d71d1d2aaa1f3c97249ddd32c858c3989754b502f187bb9bc0a0bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Release files / decayfmt_py-0.2.1-cp311-abi3-macosx_11_0_arm64.whl

Download URL decayfmt_py-0.2.1-cp311-abi3-macosx_11_0_arm64.whl
Size 1.3 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
bfcfa9ba094eb7350a6f3eec1ae233e8874aac465db2c414bcf94ef5f534cca9
BLAKE2b-256 checksum
How to use checksums
4c9e8c165f3300f9aa7a32a2a1612956b53fe4eda07b307daf40b0eb9cb251e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.16.0

Security for decayfmt-py 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

4 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page