Skip to main content

zip-deterministic

Build the same archive twice, get the same bytes.

from zip_deterministic import zip_bytes

assert zip_bytes({"a.txt": b"hello"}) == zip_bytes({"a.txt": b"hello"})

A zip or tar file stores the modification time, permission bits and member order of everything it contains, so two builds of the same tree normally differ. That breaks cache keys, signatures, reproducible builds and "did this artifact really change?" comparisons. This package pins all of it:

value default why
modification time 1980-01-01 00:00:00 for zip, 0 for tar the earliest zip can store, and the reproducible-builds convention for tar
permissions 0o644 no umask, no author's home directory leaking into the artifact
member order sorted by name the order of a dict or a directory listing must not matter
gzip header no timestamp, no file name gzip writes the current time and the name of the file it compressed

Zero dependencies, Python 3.9+.

Install

pip install zip-deterministic

Use

from zip_deterministic import zip_bytes, tar_bytes, write_zip, write_tar

data = zip_bytes(
    {"README.md": b"# hello\n", "src/app.py": b"print('hi')\n"},
    compression=__import__("zipfile").ZIP_DEFLATED,
    level=6,
)

tar = tar_bytes({"README.md": b"# hello\n"})  # .tar.gz, gzip header cleared
plain = tar_bytes({"README.md": b"# hello\n"}, gz=False)  # bare .tar

write_zip("release.zip", {"a.txt": b"a"})  # returns the size in bytes
write_tar("release.tar.gz", {"a.txt": b"a"})

Executables keep their bit when you ask for it:

zip_bytes({"bin/run.sh": b"#!/bin/sh\n"}, mode=0o755)

Members are checked before anything is written. Absolute paths, .. traversal, duplicate names and non-bytes content raise instead of producing an archive that extracts outside the target directory.

What it does not do

  • It does not walk a directory for you: pass the members, so the caller decides what goes in and in what encoding.
  • Symbols, hard links and directories are not modelled; only regular file members.
  • Deflate output still depends on the zlib version. Same interpreter and zlib, same bytes; across zlib versions the compressed stream may differ, which is why the reproducible-builds project recommends ZIP_STORED when that matters.

Development

python -m venv .venv
.venv/bin/pip install -e ".[test]"
.venv/bin/pytest

License

MIT.

Metadata

Release files for zip-deterministic 0.1.0

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

Source distribution (sdist)

Source distribution for zip-deterministic 0.1.0
File Size Uploaded Provenance Actions
zip_deterministic-0.1.0.tar.gz 6.5 kB Without provenance Details for zip_deterministic-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for zip-deterministic 0.1.0
File Interpreter ABI Platform Actions
zip_deterministic-0.1.0-py3-none-any.whl Python 3 none any Details for zip_deterministic-0.1.0-py3-none-any.whl

Total release size: 11.8 kB

Release files / zip_deterministic-0.1.0.tar.gz

Download URL zip_deterministic-0.1.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e06292d82183c1c32eb81132b8155f9e8d011bab8d6a17b5e09e6d0d2acf7b54
BLAKE2b-256 checksum
How to use checksums
675c98c5319f6d1a93f7e8470811112c823e502b5182cd8f5cceba9f33e55e23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / zip_deterministic-0.1.0-py3-none-any.whl

Download URL zip_deterministic-0.1.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16ebd1100a2e90d1525e1d7a703f7cdec52b480a0cec3e2f0ccf29aea6f1c5b5
BLAKE2b-256 checksum
How to use checksums
f59645a0e8e8c8f52db6b5b600aaefd411e2d04c7c824ce5b9d1da69de3356e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for zip-deterministic 0.1.0

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.

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