Skip to main content

CI

django-pgcrypto

A set of utility functions for dealing with ASCII Armor (http://www.ietf.org/rfc/rfc2440.txt) and padding, and a collection of Django field classes that utilize these functions in a way that is compatible with pgcrypto functions.

Installation

pip install django-pgcrypto

Quickstart

There are several encrypted versions of Django fields that you can use (mostly) as you would use a normal Django field:

from django.db import models
import pgcrypto

class Employee (models.Model):
    name = models.CharField(max_length=100)
    ssn = pgcrypto.EncryptedTextField()
    pay_rate = pgcrypto.EncryptedDecimalField()
    date_hired = pgcrypto.EncryptedDateField(key="datekey", auto_now_add=True)

If not specified when creating the field (as in ssn and pay_rate above), fields are encrypted according to the following settings:

  • PGCRYPTO_DEFAULT_CIPHER (only aes is currently supported) - The default algorithm to use when encrypting fields.
  • PGCRYPTO_DEFAULT_KEY (default: settings.SECRET_KEY) - The default key to use for encryption.

You must also make sure the pgcrypto extension is installed in your database. Django makes this easy with a CryptoExtension migration.

Querying

It is possible to filter on encrypted fields as you would normal fields via exact, gt, gte, lt, lte, contains, icontains, startswith, istartswith, endswith, and iendswith lookups. For example, querying the model above is possible like so:

Employee.objects.filter(date_hired__gt="1981-01-01", salary__lt=60000)

Caveats

This library encrypts and encodes data in a way that works with pgcrypto's raw encryption functions. All the warnings there about using direct keys and the lack of integrity checking apply here.

This library also predates Django's BinaryField, which is why the fields are essentially TextFields that store armored encrypted data. This may or may not be ideal for your application, and a hypothetical future version might include a switch to store binary data.

Metadata

Release files for django-pgcrypto 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-pgcrypto 3.1.0
File Size Uploaded
django_pgcrypto-3.1.0.tar.gz 7.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-pgcrypto 3.1.0
File Interpreter ABI Platform
django_pgcrypto-3.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / django_pgcrypto-3.1.0.tar.gz

Download URL django_pgcrypto-3.1.0.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
87956b3e8b7e9976dd90cf650e970fdea0aa3d09b3dabd825ccccf058124cd00
BLAKE2b-256 checksum
How to use checksums
5af09a2e36348a163ef40b6b9b70774d41064f10bcc0af408ef9810ec913b886
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","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 / django_pgcrypto-3.1.0-py3-none-any.whl

Download URL django_pgcrypto-3.1.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
20969fb96ab984bb4c9d841cfb872ccae336064b66db4c223a21291088e5e3a4
BLAKE2b-256 checksum
How to use checksums
90119646f36f131a9151c4657de3f161164d89b202e39f8f42713fab6882baa3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","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 history Release notifications | RSS feed

This release

3.1.0 This release

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.0

1 release file

1.4.0

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page