Skip to main content

Simple Djanngo module to anonymize production data for safe usage on none production environments

Project description

django-anonymous

CI codecov License: GPL v3 PyPI version

Simple Django module to anonymize production data for safe usage on non-production environments.

Installation

pip install django-anonymous

Usage

In your app create a file anon.py:

from django_anonymous import Anonymizer, Faker, register
from .model import YourModel


@register(YourModel)
class YourModelAnonymizer(Anonymizer):
    
    # You can give any callable, Faker is a small wrapper around the `faker` library. 
    email = Faker("email", unique=True)
    
    # You can also use any static value
    first_name = "Anon"

Run the anonymizer

python manage.py anonymize

Custom QuerySet

You can set a custom QuerySet to filter out some objects

from django_anonymous import Anonymizer, Faker, register
from .model import YourModel


@register(YourModel)
class YourModelAnonymizer(Anonymizer):
    email = Faker("email", unique=True)

    def get_queryset(self):
        return super().get_queryset().filter(is_staff=True)

Faker seed

Default it will use the object id as seed, to generate the same data for every run. You can disable this by overriding the get_object_seed and return falsy value.

from django_anonymous import Anonymizer, Faker, register
from .model import YourModel


@register(YourModel)
class YourModelAnonymizer(Anonymizer):
    email = Faker("email", unique=True)

    def get_object_seed(self, obj):
        return None

Settings for Anonymizer

Per Anonymizer you can set the select chunk size and update batch size.

from django_anonymous import Anonymizer, Faker, register
from .model import YourModel


@register(YourModel)
class YourModelAnonymizer(Anonymizer):
    SELECT_CHUNK_SIZE = 100
    UPDATE_BATCH_SIZE = 25
    
    email = Faker("email", unique=True)

Inspired by

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-anonymous-0.3.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_anonymous-0.3.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file django-anonymous-0.3.0.tar.gz.

File metadata

  • Download URL: django-anonymous-0.3.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for django-anonymous-0.3.0.tar.gz
Algorithm Hash digest
SHA256 167e8fd0d4d9a0b45bfdeeabce1a9cfb44924fed3a0ffcfabcf181ed6ec48001
MD5 71a6fd7ef9c49b1645c8ae03b304c17d
BLAKE2b-256 dc4ea0ce4d7ae8de289db984a33dbf73d293cf810c105057e27f82ee7234bea8

See more details on using hashes here.

File details

Details for the file django_anonymous-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_anonymous-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e479724c368f3f70fe25aa2ccc19fa170b88855e18d1d20a30fab150f23097d3
MD5 6fba77002a2c7c80a4c87c117bc46715
BLAKE2b-256 2753b4f01a865847b456a19f364f4b7aceeae84d2058d89d8a51f5577fd938c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page