Skip to content

Adding python bindings - #4

Merged
aravpanwar merged 6 commits into
aravpanwar:mainfrom
AAVision:main
Sep 4, 2026
Merged

aravpanwar merged 6 commits into
aravpanwar:mainfrom
AAVision:main

Conversation

@AAVision

@AAVision AAVision commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Added

  • Python bindings via PyO3 — new python/ crate publishing the decayfmt-py package on PyPI (import name: decayfmt).
    • corrupt_bytes(data, x, kind) — decayed copy of immutable bytes
    • corrupt_in_place(buffer, x, kind) — zero-copy decay of a bytearray
    • encode_file(source, output) / encode_bytes(source, output) — encode clean files
    • decay_file(path) — open without display: permanently corrupts on disk, returns (kind, dims, bytes)
    • parse_filename(name), read_header(data), write_header(kind, width, height), __version__
    • Errors map to built-ins: OSError (I/O), PermissionError (read-only target), ValueError (everything else) — messages match the CLI exactly
    • abi3 wheels for Python 3.11+; requires-python >=3.11
  • GitHub Actions workflow (python.yml) — builds and smoke-tests wheels on 5 platforms (manylinux x86_64 + aarch64, macOS arm64 + x86_64, Windows), publishes to PyPI via trusted publishing on py-v* tags
  • Docs — python/README.md (PyPI long description), python/examples/example.py (every function + every exception), python/RELEASE.md (release checklist), new ## Python and ## Performance sections in root README

Changed

  • Corruption loop rewritten for throughput — bulk u16 RNG pools replace per-byte f64 draws, exact-replacement tables replace rejection sampling, payloads ≥ 1 MiB corrupt in parallel (rayon) across cores. Measured on this machine (macOS arm64, 64 MiB payload): text x=1 142 → 1366 MiB/s (9.6x), text x=10 85.6 → 754 MiB/s (8.8x), image x=1 187 → 1421 MiB/s (7.6x), image x=10 116 → 950 MiB/s (8.2x)
    • Statistics unchanged: per-byte probability stays 1 - exp(-x/10) (quantization ≤ 1/65536), image alpha never touched, trailing non-pixel bytes untouched, randomness stays OS-entropy-seeded and never replayable
  • Encode path — dropped second full-size buffer in write_decayfmt (header + payload streamed); text encode measured 7.9 → 3.9 ms (2.0x)
  • Smaller dependency tree — image default features trimmed (avif encode-only dead code, internal rayon); rav1e removed from lockfile. Decode format parity kept (exr retained)
  • Cargo workspace — members = ["python"] with default-members = ["."]; existing CLI CI/release workflows untouched
Benchmark Before After Improvement
Text corruption ×1 142 MiB/s 1,366 MiB/s 9.6× faster
Text corruption ×10 86 MiB/s 754 MiB/s 8.8× faster
Image corruption ×1 187 MiB/s 1,421 MiB/s 7.6× faster
Image corruption ×10 116 MiB/s 950 MiB/s 8.2× faster
Encode 16 MiB text 7.9 ms 3.9 ms 2× faster

Internal (no CLI behavior change)

  • encode::encode_bytes, decode_image, text_payload, write_decayfmt, open::decay_in_place now pub for embedding
  • New bench harness (benches/, no new dependencies, DECAY_BENCH_MB override) and large-payload statistical tests (8 MiB parallel path, seeded determinism, alpha/tail invariance)

Notes

  • CLI functionality, commands, error messages, and file format are unchanged — perf work and Python binding sit on top of the existing library
  • End-to-end encode is bounded by image decode + disk I/O; the large speedups above are the corruption step
  • PyPI package name is decayfmt-py (import stays decayfmt); releases tagged py-v* independently of CLI v* tags

@aravpanwar

aravpanwar commented Sep 3, 2026 •

Copy link
Copy Markdown
Owner

Awesome work. Went through the corruption rewrite and it's great: nothing's seeded in the real path, and the alpha and pixel-boundary handling held up across the parallel split.

CI's red on this thing: PyO3/maturin-action@v2 doesn't exist, so the python jobs die at "Set up job" before building. Switch both uses (build + publish) to @v1 and it should go green, then I'll merge.

@AAVision

AAVision commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@aravpanwar fixed, check the tests and manage how you publish it to PyPI

@aravpanwar
aravpanwar merged commit 10cfc08 into aravpanwar:main Sep 4, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants