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. Default it will not anonymize a field that has no value.
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
Metadata
Release files for django-anonymous 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-anonymous-0.4.0.tar.gz | 17.2 kB | Without provenance | Details for django-anonymous-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_anonymous-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for django_anonymous-0.4.0-py3-none-any.whl |
Total release size: 35.2 kB
Release files / django-anonymous-0.4.0.tar.gz
| Download URL | django-anonymous-0.4.0.tar.gz |
|---|---|
| Size | 17.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bc652560497be7f429ba1930b8a4afd1f4686c7f0d0d96b56e8f4d186ea48bdb
|
|
BLAKE2b-256 checksum How to use checksums |
77d38b3ebd295cdd40464cd13749acfa96de6b1776da63c95491e3fd0490f542
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Release files / django_anonymous-0.4.0-py3-none-any.whl
| Download URL | django_anonymous-0.4.0-py3-none-any.whl |
|---|---|
| Size | 18.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0a3b330d8a0e5b5b483b67b1758283f6119276c9689657c92e20a28810c80c65
|
|
BLAKE2b-256 checksum How to use checksums |
7f4551253872cfe0823861cc7cbbdbe159374c9ca566f4f7cd898dbbe5d95e27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Security for django-anonymous 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.