https://github.com/fourdigits/django-anonymous
Simple Django module to anonymize production data for safe usage on none production environments
https://github.com/fourdigits/django-anonymous
Last synced: 10 months ago
JSON representation
Simple Django module to anonymize production data for safe usage on none production environments
- Host: GitHub
- URL: https://github.com/fourdigits/django-anonymous
- Owner: fourdigits
- License: gpl-3.0
- Created: 2022-03-04T08:59:15.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-06-06T10:56:56.000Z (about 3 years ago)
- Last Synced: 2025-03-27T18:50:22.428Z (about 1 year ago)
- Language: Python
- Homepage:
- Size: 48.8 KB
- Stars: 9
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# django-anonymous
[](https://github.com/krukas/django-anonymous/actions/workflows/main.yml)
[](https://codecov.io/gh/krukas/django-anonymous)
[](https://www.gnu.org/licenses/gpl-3.0)
[](https://badge.fury.io/py/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`:
```python
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
```python
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.
```python
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.
Default it will not anonymize a field that has no value.
```python
from django_anonymous import Anonymizer, Faker, register
from .model import YourModel
@register(YourModel)
class YourModelAnonymizer(Anonymizer):
SELECT_CHUNK_SIZE = 100
UPDATE_BATCH_SIZE = 25
ANONYMIZE_EMPTY_FIELD = False
email = Faker("email", unique=True)
```
## Inspired by
- https://github.com/Tesorio/django-anon
- https://github.com/FactoryBoy/factory_boy