Skip to main content

CI

PZip

PZip is an encrypted file format (with optional compression), a command-line tool, and a Python file-like interface.

PZip Documentation

Installation

PZip is available on PyPI:

pip install pzip

Command Line Usage

For a full list of options, run pzip -h. Basic usage is summarized below:

pzip --key keyfile sensitive_data.csv
pzip --key keyfile sensitive_data.csv.pz

Piping and outputting to stdout is also supported:

tar cf - somedir | pzip -z --key keyfile -o somedir.pz
pzip --key keyfile -c somedir.pz | tar xf -

PZip will generate an encryption key automatically, if you want:

pzip -a sensitive_data.csv
encrypting with password: HgHs4OIm4zGXkch6lTBIqg

pzip -p HgHs4OIm4zGXkch6lTBIqg sensitive_data.csv.pz

Python Usage

import os, pzip

key = pzip.Key(os.urandom(32))

with pzip.open("myfile.pz", "wb", key=key) as f:
    f.write(b"sensitive data")

with pzip.open("myfile.pz", "rb", key=key) as f:
    print(f.read())

To encrypt using a password instead of a random key (and thus use PBKDF2 instead of HKDF for key derivation):

with pzip.open("myfile.pz", "wb", key=pzip.Password("secret")) as f:
    f.write(b"hello world")

By default, PZip will append the total plaintext length to the end of the file, both as a final integrity check, and a way for applications to quickly get the original file size. However, you can disable this by passing append_length=False when opening a file/stream for writing:

with pzip.open(output_stream, "wb", key=secret, append_length=False) as f:
    f.write(plaintext)

Encryption

See the Encryption docs for more information.

File Format

See the File Format docs for more information.

FAQ

Why does this exist?

Nothing PZip does couldn't be done by chaining together existing tools - compressing with gzip, deriving a key and encrypting with openssl, generating a MAC (if not using GCM), etc. But at that point, you're probably writing a script to automate the process, tacking on bits of data here and there (or writing multiple files). PZip simply wraps that in a nice package and documents a file format. Plus having a Python interface you can pretty much treat as a file is super nice.

Why not store filename?

Storing the original filename has a number of security implications, both technical and otherwise. At a technical level, PZip would need to ensure safe filename handling across all platforms with regards to path delimiters, encodings, etc. Additionally, PZip was designed for a system where user-generated file attachments may contain sensitive information in the filenames themselves. In reality, having a stored filename is of minimal use anyway, since the default behavior is to append and remove a .pz suffix when encrypting/decrypting. If a .pz file was renamed, you would have a conflict that would likely be resolved by using the actual filename (not the stored filename) anyway. With all of that said, PZip does specify a FILENAME tag for applications that wish to store it.

Release files for pzip 1.2.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 pzip 1.2.0
File Size Uploaded
pzip-1.2.0.tar.gz 77.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pzip 1.2.0
File Interpreter ABI Platform
pzip-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 91.2 kB

Release files / pzip-1.2.0.tar.gz

Download URL pzip-1.2.0.tar.gz
Size 77.3 kB
Tags Source
SHA-256 checksum
How to use checksums
33f57ba505e0cff6eda659926aec5545779896f0bc5c3bac1563b3d0cb59a6f8
BLAKE2b-256 checksum
How to use checksums
6105a8bc82bb7cca6944e2fbe66607b55e7c350d9606874ec716e7b7928a6ed1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.0

Release files / pzip-1.2.0-py3-none-any.whl

Download URL pzip-1.2.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b17c35da3d305d4ca40f26545f9f172264d058971547e554ac6fd53aad89eab8
BLAKE2b-256 checksum
How to use checksums
8a7ce6645ad5837acef7093750f5eef27c68daf88fb3f260ea2907199a7e62a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.0

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.9.9

2 release files

0.9.8

1 release file

0.9.7

1 release file

0.9.6

1 release file

0.9.5

1 release file

0.9.4

1 release file

0.9.3

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9.0

1 release file

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