Simple Djanngo module to anonymize production data for safe usage on none production environments
Project description
django-anonymous
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.1.tar.gz
(16.9 kB
view hashes)
Built Distribution
Close
Hashes for django_anonymous-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d10757e5975b3c8139bfca6828a65d2277272cfa3d5cac90c38d31b3335a3fa |
|
MD5 | 2dcaad25c429535124d985972551bd45 |
|
BLAKE2b-256 | 57d39e3d40740f1b61115d32792e2ec279d3790b615d960628a3bbdc01975c20 |