Skip to main content

Django Mask Postgres Data

Adds a management command to your Django project which allows you to create a (sort of) pg_dump of your data with sensitive data masked.

Installation

Install with pip:

pip install django-maskpostgresdata

And add maskpostgresdata to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'maskpostgresdata',
    ...
]

Usage

By default, django-maskpostgresdata will replace the password column for each row in the Django User model with "password". Just run manage.py dump_masked_data and you'll get a pg_dump with the password field changed to "password" for all users.

There are 2 ways to customise the behaviour of django-maskpostgresdata.

To override individual fields of a model with a given value, add a dictionary called MASKER_FIELDS to your settings using the following format:

MASKER_FIELDS = {
    "{ APP_NAME }": {"{ MODEL_NAME }": {"{ FIELD_NAME }": { VALUE },}},
}

Alternatively, you can define exactly how the data is updated by subclassing BasePostgresDataMaskingCommand in a management command of your own. For example:

from django.contrib.auth.hashers import make_password

from maskpostgresdata import BasePostgresDataMaskingCommand


class Command(BasePostgresDataMaskingCommand):

    def update_auth_user(self, queryset):
        queryset.update(password=make_password("a_different_password"))

Just create a method called update_{ db_table_name } taking a queryset as the parameter. You can then perform update operations on this queryset. { db_table_name } is of the format {app_label}_{model_name} by default, but could technically be different.

You can then run manage.py dump_masked_data and it will dump your data to stdout.

Metadata

Release files for django-maskpostgresdata 0.2.1

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-maskpostgresdata 0.2.1
File Size Uploaded
django-maskpostgresdata-0.2.1.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-maskpostgresdata 0.2.1
File Interpreter ABI Platform
django_maskpostgresdata-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.3 kB

Release files / django-maskpostgresdata-0.2.1.tar.gz

Download URL django-maskpostgresdata-0.2.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4fe15dd217207ac9991164aeb74a5d24404b4834df46c253f98f6aee6a864633
BLAKE2b-256 checksum
How to use checksums
a4a209e758549cbbfa460e7b32512f43f663ceb2f2c88aa83ce0ab76b6728155
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.11

Release files / django_maskpostgresdata-0.2.1-py3-none-any.whl

Download URL django_maskpostgresdata-0.2.1-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e12cbd3b8062bac37759af6d99c10c18ca171deb0b7635736ebc944f10fb3e5
BLAKE2b-256 checksum
How to use checksums
12607ef240200c15d7fc6e96f3638af3f32962136624ba30611dfee0311b4564
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2

2 release files

0.1.16

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

1 release file

0.1.9

2 release files

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

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