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 Djanngo 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)

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.2.0.tar.gz (18.6 kB view hashes)

Uploaded Source

Built Distribution

django_anonymous-0.2.0-py3-none-any.whl (17.5 kB view hashes)

Uploaded Python 3

Supported by

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