entirius-django-crypt
A Django helper for symmetric encryption in Entirius, the open-source modular ecommerce platform: Fernet encrypt and decrypt with one key from settings.
It wraps cryptography.fernet in a small Crypt class and ships management commands for the same operations.
What it does
- Encrypts and decrypts strings with Fernet, using the key in
settings.CRYPT_SALTor one passed toCrypt(salt=...). - Generates a Fernet-compatible key with
Crypt.generate_salt(). - Passes
Nonethrough unchanged, so nullable fields need no guard. - Ships the management commands
generate_salt,encryptanddecrypt. - Ships
CryptedTextField, a modelTextFieldencrypted at rest: call sites read and write plaintext. - Produces non-deterministic ciphertext: the same plaintext encrypts to a different value each time, so use a separate deterministic hash (for example HMAC-SHA256) for unique or lookup columns.
Installation
uv add entirius-django-crypt
pip install entirius-django-crypt
INSTALLED_APPS = [
...
"django_crypt",
]
CRYPT_SALT = "<output of generate_salt>"
python manage.py generate_salt # print a fresh key
python manage.py encrypt "plain text" # encrypt a string
python manage.py decrypt "<ciphertext>" # decrypt a string
Required setting: CRYPT_SALT; reference in
https://github.com/entirius/entirius-django-crypt/blob/develop/AGENTS.md (section Settings).
Quick start
from django_crypt import Crypt
crypt = Crypt() # uses settings.CRYPT_SALT
encrypted = crypt.encrypt("secret value")
assert crypt.decrypt(encrypted) == "secret value"
salt = Crypt.generate_salt() # a fresh key for first-time setup
An encrypted model field:
from django.db import models
from django_crypt.fields import CryptedTextField
class PaymentProviderConfig(models.Model):
client_secret = CryptedTextField(default="")
db_index,uniqueandprimary_keyraiseValueErrorat declaration: ciphertext differs on every save, so the column can't be indexed, filtered or searched.- A value that no longer decrypts (key rotated, row corrupted) raises
django_crypt.fields.DecryptionErroron load. The error and the log line name model and field, never the ciphertext or the plaintext. The field never reads such a row as"": the nextsave()would write""over the ciphertext and the secret would be gone. Loading that row fails, its admin change page included, until you either restore theCRYPT_SALTit was written with, or blank it on purpose withPaymentProviderConfig.objects.filter(pk=...).update(client_secret="")(update()never reads the old value). A missing or malformedCRYPT_SALTraisesValueError. - The local
EncryptedTextFieldin entirius-django-communicator and entirius-django-contact-forms still reads an undecryptable value as"". Moving them ontoCryptedTextFieldis a follow-up. dumpdatawrites the decrypted plaintext;loaddataencrypts on save. Don't commit fixtures with real secrets.
Requirements
- Python 3.11 or newer, Django 4.0 or newer.
cryptography42.0 or newer.- No database tables and no other Entirius packages.
Documentation
- Entirius documentation: https://docs.entirius.com/
- Releases: https://github.com/entirius/entirius-django-crypt/releases
- Fernet specification: https://cryptography.io/en/latest/fernet/
Part of Entirius
This module installs into the Entirius backend service (Volkanos) as a standalone helper with no database tables.
- Backend service: https://github.com/entirius/entirius-service-volkanos
- Docker harness: https://github.com/entirius/entirius-zeno
- Sibling modules: https://github.com/entirius/entirius-django-utils
Development
make install # sync dependencies (uv)
make check # lint + format check (ruff)
make test # test suite (pytest + pytest-django)
Development and agent instructions: https://github.com/entirius/entirius-django-crypt/blob/develop/AGENTS.md
License
Mozilla Public License 2.0 (MPL-2.0) — see https://github.com/entirius/entirius-django-crypt/blob/develop/LICENSE.
Metadata
Release files for entirius-django-crypt 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| entirius_django_crypt-2.1.0.tar.gz | 45.4 kB | Without provenance | Details for entirius_django_crypt-2.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| entirius_django_crypt-2.1.0-py3-none-any.whl | Python 3 | none | any | Details for entirius_django_crypt-2.1.0-py3-none-any.whl |
Total release size: 59.4 kB
Release files / entirius_django_crypt-2.1.0.tar.gz
| Download URL | entirius_django_crypt-2.1.0.tar.gz |
|---|---|
| Size | 45.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
673c97c4639825a5fc3e2b31bc10328e5cf436278d22d70dfd156244bf7ead1f
|
|
BLAKE2b-256 checksum How to use checksums |
e5b78ce0a3b5ab806871b176c82572ff98f6d6dd3a0a2dfe3f782d8881b9be46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / entirius_django_crypt-2.1.0-py3-none-any.whl
| Download URL | entirius_django_crypt-2.1.0-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be645afe6638820627998fddf287971924fec63d8bd273731eccc4d9a875e745
|
|
BLAKE2b-256 checksum How to use checksums |
24802b04881a36e7fc2003759112fefc89dd0aa92541fd218b6951bbe850815e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for entirius-django-crypt 2.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.