Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

deterministic_zip

A tool to generate consistent zip files.

This tool was specifically built to prevent zip file changes from triggering AWS Lambda function updates when running terraform apply. Before this change, every re-build of the zipfile would result in a different zip even if its contents had not changed.

Requirements

This tool currently only runs on python3.7 in order to use deflate compression level 9.

Installation

pip install deterministic_zip

Creating a deterministic_zip

Run the following, and verify that your zip produces the same sha256 hash:

echo "The first file." > first
echo "The second file." > second
deterministic_zip archive.zip first second
sha256sum archive.zip

If you have \n line endings the result should be:

3afbd7c9b42bd5539ffd5c40499d3d1825157ed83791dce8d7ff2694189d28d6

If you have \r\n line endings (Windows) the result should be:

40e16270d62f15e7a192e88b1b301fa6540c86e7e897036b56be513341d376ed

How does it work?

Great question! There are three tricks to building a deterministic zip.

  1. Files must be added to the zip in the same order. Directory iteration order may vary across machines, resulting in different zips. deterministic_zip sorts all files before adding them to the zip archive.

  2. Files in the zip must have consistent timestamps. If I share a directory to another machine, the timestamps of individual files may differ, depsite identical content. To achieve timestamp consistency, deterministic_zip sets the timestamp of all added files to 2019-01-01 00:00:00. Please note that this does not affect the timestamp of the source files.

  3. Files in the zip must have consistent permissions. File permissions look like -rw-r--r-- for a file that is readable by all users, and only writable by the user who owns the file. Similarly executable files might have permissions that look like: -rwxr-xr-x or -rwx------. deterministic_zip sets the permission of all files to either -r--r--r--, or -r-xr-xr-x. The latter is only used of the user running deterministic_zip has execute access on the file.

Metadata

Release files for deterministic-zip 0.1

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

Source distribution (sdist)

Source distribution for deterministic-zip 0.1
File Size Uploaded
deterministic_zip-0.1.tar.gz 3.9 kB Details

Built distribution (wheel)

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

Total release size: 8.3 kB

Release files / deterministic_zip-0.1.tar.gz

Download URL deterministic_zip-0.1.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d0095bafb65a7272ea9742c35d9fd3305dc5f1011b0f37addcf3fb95e7606100
BLAKE2b-256 checksum
How to use checksums
045a297b8b79061e9ac3b1c23cc238c78c89bca8b07379864d37ef172fa182de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

Release files / deterministic_zip-0.1-py3-none-any.whl

Download URL deterministic_zip-0.1-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a16dc9fdfd130849e09adb5bc9c3e9ec8f3de109d405de04cb670cf73bb7c84a
BLAKE2b-256 checksum
How to use checksums
7a297e6db311798cf302d28312673c8d0e79e4bfa3d1be7cc46b94a45589d564
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files

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