Skip to main content

Storage backend for Django that encrypts/compresses with PZip.

Project description

django-pzip-storage

A FileSystemStorage subclass for Django that encrypts/compresses with PZip.

Installation

pip install django-pzip-storage

Usage

The simplest way to use PZipStorage is by setting your DEFAULT_FILE_STORAGE to pzip_storage.PZipStorage. By default, PZipStorage will use your SECRET_KEY setting as the encryption key.

IMPORTANT: Encrypting with SECRET_KEY means you must keep SECRET_KEY a secret, and if you lose or reset it without first rotating the keys of all stored files, they will be lost forever.

PZipStorage may be used with existing unencrypted files, as a drop-in replacement for FileSystemStorage. If it determines the requested file is not a PZip file, it will delegate to FileSystemStorage after emitting a needs_encryption signal (see below).

You may also use PZipStorage as a custom storage backend anywhere Django allows it; see Managing Files in the Django documentation for more information.

Settings

  • PZIP_STORAGE_EXTENSION - the extension to append to any file saved with PZipStorage. Defaults to .pz.
  • PZIP_STORAGE_NOCOMPRESS - a set of file extensions (with leading period) which should not be compressed when saving. See PZipStorage.DEFAULT_NOCOMPRESS for the default list.
  • PZIP_STORAGE_KEYS - an iterable (or callable returning an iterable) of keys to use. The first key on the list will be used for encrypting files. Defaults to PZipStorage.default_keys, which yields SECRET_KEY.

These settings may be overridden on a per-storage basis by instantiating PZipStorage manually with extension or nocompress keyword arguments.

Signals

PZipStorage emits a number of signals when opening files in various circumstances:

  • pzip_storage.needs_rotation - sent when a file was decrypted using an old key, i.e. not the first key in the provided list.
  • pzip_storage.needs_encryption - sent when an unencrypted file was opened.
  • pzip_storage.bad_keys - sent when an encrypted file was opened, but no keys in the list could decrypt it.

You may listen for these signals to do things like gradual encryption, key rotation, or logging.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_pzip_storage-1.2.1.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

django_pzip_storage-1.2.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file django_pzip_storage-1.2.1.tar.gz.

File metadata

File hashes

Hashes for django_pzip_storage-1.2.1.tar.gz
Algorithm Hash digest
SHA256 4cc790ce0084c078a3e06afca1d7008c7e1bbd4483c56e9bc37a4b853a84fb05
MD5 7a0924b6a73684238d4e76bc7acfbad7
BLAKE2b-256 d2dd810e89bc7f7e9add8ba2fbc2a27f5b150147c19990ad5db979790bac0da5

See more details on using hashes here.

File details

Details for the file django_pzip_storage-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_pzip_storage-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 450ccc5cbee2abacaad0b7caad90683127384f2318da492523fc24f32758fbbd
MD5 ba1de700ac43c5f668479486999af1ff
BLAKE2b-256 8491f3532ee7541ba8aee80f6f1b5761a7be8f44ebb43f3ed91c4979068570ef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page