Registry / auth-security / django-cryptography-django5

django-cryptography-django5

JSON →
library2.2pypypiunverified

A fork of the original `django-cryptography` library, `django-cryptography-django5` provides primitives for easily encrypting data in Django models, wrapping the Python `cryptography` library. It offers field-level encryption for sensitive data, ensuring it's stored securely and decrypted automatically when accessed through Django. The library is actively maintained for Django 5 compatibility and is currently at version 2.2, with releases driven by Django version updates and bug fixes.

pip install django-cryptography-django5
INSTALL
IMPORT
SIG · DJANGO-CRYPTOGRAPH
D
django-cryptography-django5
auth-securitypythonv2.2
Install
4.3s avg
Import
—
Disk
82MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.915 runs
installs and imports cleanly · install 0.0s · import 0.000s · 83MB
glibc
py 3.10–3.915 runs
installs and imports cleanly · install 4.3s · import 0.000s · 83MB
82MB installed
● package 82MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

encrypt
✓ from django_cryptography import encrypt
✗ from django_cryptography import encrypt
VERSION
✓ from django_cryptography import VERSION
get_version
✓ from django_cryptography import get_version

Define a model with `encrypt` wrapped around the desired field. Ensure `SECRET_KEY` (and optionally `ENCRYPTION_KEY`) is configured in your Django settings.

import os from django.db import models from django_cryptography.fields import encrypt # Ensure your Django settings.py has a strong SECRET_KEY and optionally ENCRYPTION_KEY # For example, in settings.py: # SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'your-very-long-and-random-secret-key-here') # ENCRYPTION_KEY = os.environ.get('DJANGO_ENCRYPTION_KEY', SECRET_KEY) # Falls back to SECRET_KEY if not set class SecureData(models.Model): name = models.CharField(max_length=100) # Encrypt the sensitive_info field sensitive_info = encrypt(models.TextField()) def __str__(self): return self.name # Example usage (after running migrations): # from myapp.models import SecureData # data_entry = SecureData.objects.create(name='User A', sensitive_info='This is very secret data.') # print(data_entry.sensitive_info) # Automatically decrypted when accessed via Django ORM
Debug
Known issues
breakingThe original `django-cryptography` library used `django.utils.baseconv`, which was removed in Django 5.x. Attempting to use the un-forked version with Django 5.x will result in import errors or deprecation warnings.
fix
Use `django-cryptography-django5` (version 1.2 or higher) for Django 5.x compatibility.
affects: Original `django-cryptography` with Django 5.x
gotchaUsing `unique=True` on an encrypted model field (`encrypt(models.SomeField(unique=True))`) can lead to `FieldError: Unsupported lookup 'exact'` or cause the uniqueness constraint to be ignored by the database. Encryption changes the stored value, making true database-level uniqueness difficult to enforce on the ciphertext.
fix
Avoid using `unique=True` directly on encrypted fields. If uniqueness is a strict requirement, implement it at the application layer (e.g., in `clean()` methods of models or forms) or consider if the field genuinely needs to be both encrypted and unique at the database level.
affects: All versions
gotchaThe security of encrypted data critically depends on Django's `SECRET_KEY`. This key must be strong, unique to each deployment, and kept absolutely secret. Exposing it in version control or using a default/weak key compromises all encrypted data.
fix
Generate a long, random `SECRET_KEY` for production and manage it securely using environment variables, a secrets manager, or similar methods. Do not commit it to source control.
affects: All versions
gotchaThe project's PyPI metadata indicates a 'Development Status :: 2 - Pre-Alpha'. While actively maintained, users should be aware of this classification, suggesting it may still be undergoing significant development or refinement.
fix
Monitor project updates and releases for any changes in development status or significant API shifts. Factor this status into project risk assessments.
affects: All versions
Upgrade
Version history
2.2latest on PyPI · released Jun 4, 2024
Audit
Dependencies
DjangorequiredCore framework integration; supports Django 3.2, 4.1, 4.2, 5.0.
cryptographyrequiredBackend cryptographic operations; requires version 2.0 or higher.
PythonrequiredRuntime environment; requires Python 3.8 or higher.
Agent activity
36 hits · last 30 days
node
34
OpenAI (training)
1
Resources