{"id":8946,"library":"django-cryptography-django5","title":"django-cryptography-django5","description":"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.","status":"active","version":"2.2","language":"python","source_language":"en","source_url":"https://github.com/chrisclark/django-cryptography","tags":["django","encryption","security","cryptography","fields"],"install":[{"cmd":"pip install django-cryptography-django5","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core framework integration; supports Django 3.2, 4.1, 4.2, 5.0.","package":"Django","optional":false},{"reason":"Backend cryptographic operations; requires version 2.0 or higher.","package":"cryptography","optional":false},{"reason":"Runtime environment; requires Python 3.8 or higher.","package":"Python","optional":false}],"imports":[{"wrong":"from django_cryptography import encrypt","symbol":"encrypt","correct":"from django_cryptography import encrypt"},{"symbol":"VERSION","correct":"from django_cryptography import VERSION"},{"symbol":"get_version","correct":"from django_cryptography import get_version"}],"quickstart":{"code":"import os\nfrom django.db import models\nfrom django_cryptography.fields import encrypt\n\n# Ensure your Django settings.py has a strong SECRET_KEY and optionally ENCRYPTION_KEY\n# For example, in settings.py:\n# SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'your-very-long-and-random-secret-key-here')\n# ENCRYPTION_KEY = os.environ.get('DJANGO_ENCRYPTION_KEY', SECRET_KEY) # Falls back to SECRET_KEY if not set\n\nclass SecureData(models.Model):\n    name = models.CharField(max_length=100)\n    # Encrypt the sensitive_info field\n    sensitive_info = encrypt(models.TextField())\n\n    def __str__(self):\n        return self.name\n\n# Example usage (after running migrations):\n# from myapp.models import SecureData\n# data_entry = SecureData.objects.create(name='User A', sensitive_info='This is very secret data.')\n# print(data_entry.sensitive_info) # Automatically decrypted when accessed via Django ORM","lang":"python","description":"Define a model with `encrypt` wrapped around the desired field. Ensure `SECRET_KEY` (and optionally `ENCRYPTION_KEY`) is configured in your Django settings."},"warnings":[{"fix":"Use `django-cryptography-django5` (version 1.2 or higher) for Django 5.x compatibility.","message":"The 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.","severity":"breaking","affected_versions":"Original `django-cryptography` with Django 5.x"},{"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.","message":"Using `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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Monitor project updates and releases for any changes in development status or significant API shifts. Factor this status into project risk assessments.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'2.2':67 '5':60 'access':50 'activ':56 'automat':48 'bug':76 'compat':61 'cryptographi':3,12,16,30,81 'current':64 'data':23,40 'decrypt':47 'django':2,11,15,25,52,59,72,78 'django-cryptographi':10 'django-cryptography-django5':1,14 'django5':4,17 'driven':70 'easili':21 'encrypt':22,37,79 'ensur':41 'field':35,82 'field-level':34 'fix':77 'fork':6 'level':36 'librari':13,31,54 'maintain':57 'model':26 'offer':33 'origin':9 'primit':19 'provid':18 'python':29 'releas':69 'secur':45,80 'sensit':39 'store':44 'updat':74 'version':66,73 'wrap':27","created_at":"2026-04-16T18:47:40.101060+00:00","updated_at":"2026-04-16T18:47:40.101060+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nImportError: cannot import name 'encrypt' from 'django_cryptography' (/tmp/tmpmvgyqu1v/venv/lib/python3.12/site-packages/django_cryptography/__init__.py)"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.2","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/georgemarshall/django-cryptography","docs":"https://django-cryptography.readthedocs.io","changelog":null,"pypi":"https://pypi.org/project/django-cryptography-django5/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["auth-security","web-framework","database","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}