{"id":27697,"library":"django-pgcrypto-fields","title":"django-pgcrypto-fields","description":"Provides encrypted model fields for Django using pgcrypto (PostgreSQL extension). Automatically encrypts/decrypts data via pgcrypto functions. Latest version 2.6.0 supports Django 2.2–3.1 and Python ≥3.6. Monthly or quarterly releases.","status":"active","version":"2.6.0","language":"python","source_language":"en","source_url":"https://github.com/incuna/django-pgcrypto-fields","tags":["django","pgcrypto","encryption","postgresql","fields"],"install":[{"cmd":"pip install django-pgcrypto-fields","lang":"bash","label":"Standard install"}],"dependencies":[{"reason":"Required: Django ORM integration","package":"Django","optional":false},{"reason":"Required for PostgreSQL connection","package":"psycopg2","optional":false}],"imports":[{"note":"Standard import for text fields encrypted with symmetric key.","symbol":"TextPGPSymmetricKeyField","correct":"from pgcrypto.fields import TextPGPSymmetricKeyField"},{"note":"Import for email field encrypted with public key.","symbol":"EmailPGPPublicKeyField","correct":"from pgcrypto.fields import EmailPGPPublicKeyField"},{"note":"PGPManager removed in v2.4.0 – auto-decryption is now automatic.","wrong":"from pgcrypto.managers import PGPManager","symbol":"PGPManager","correct":null},{"note":"PGPAdmin removed in v2.4.0 – no manual admin registration needed.","wrong":"from pgcrypto.admin import PGPAdmin","symbol":"PGPAdmin","correct":null}],"quickstart":{"code":"import os\nfrom django.db import models\nfrom pgcrypto.fields import TextPGPSymmetricKeyField\n\nclass MyModel(models.Model):\n    name = models.CharField(max_length=100)\n    secret = TextPGPSymmetricKeyField()\n\n# Usage\n# Ensure PGCRYPTO_KEY environment variable is set (e.g., export PGCRYPTO_KEY='mysecretkey')\n# Then create and query normally; encryption/decryption is automatic.\nobj = MyModel.objects.create(name='test', secret='sensitive data')\nprint(obj.secret)  # Outputs 'sensitive data' (decrypted)","lang":"python","description":"Define an encrypted field. Auto-encrypts on save, auto-decrypts on read."},"warnings":[{"fix":"Use regular Django managers and admins, or no manager at all.","message":"PGPManager and PGPAdmin were removed in v2.4.0. Auto-decryption is now automatic; remove any references to these classes.","severity":"breaking","affected_versions":">=2.4.0"},{"fix":"Remove imports from pgcrypto.aggregates.","message":"Aggregates module removed in v2.4.0. Use standard Django aggregates instead.","severity":"breaking","affected_versions":">=2.4.0"},{"fix":"Ensure PGCRYPTO_KEY is set in your environment or Django settings.","message":"Encryption keys are read from environment variables PGCRYPTO_KEY (symmetric) or public/private key paths for public key fields. Not setting these will cause errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Upgrade Python to 3.6+.","message":"Python 3.5 support dropped in v2.6.0. Use Python >=3.6.","severity":"deprecated","affected_versions":"2.6.0+"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Set PGCRYPTO_KEY environment variable (e.g., export PGCRYPTO_KEY='your-key' in shell, or set in Django settings with os.environ).","cause":"The symmetric key required by pgcrypto fields is missing.","error":"django.core.exceptions.ImproperlyConfigured: 'PGCRYPTO_KEY' environment variable is not set."},{"fix":"Use standard Django aggregates (.count(), .sum(), etc.). Remove any imports from pgcrypto.aggregates.","cause":"Trying to import pgcrypto.aggregates which was removed in v2.4.0.","error":"AttributeError: module 'pgcrypto' has no attribute 'aggregates'"},{"fix":"Remove PGPManager from model managers; use default Django manager or a custom manager.","cause":"PGPManager removed in v2.4.0.","error":"ImportError: cannot import name 'PGPManager' from 'pgcrypto.managers'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}