# django-anonymous
[![CI](https://github.com/krukas/django-anonymous/actions/workflows/main.yml/badge.svg)](https://github.com/krukas/django-anonymous/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/krukas/django-anonymous/branch/master/graph/badge.svg?token=BPQQ1RVKDJ)](https://codecov.io/gh/krukas/django-anonymous)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![PyPI version](https://badge.fury.io/py/django-anonymous.svg)](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
Raw data
{
"_id": null,
"home_page": "https://github.com/fourdigits/django-anonymous",
"name": "django-anonymous",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "Django,anonymous,anonymize",
"author": "Maikel Martens",
"author_email": "maikel@fourdigits.nl",
"download_url": "https://files.pythonhosted.org/packages/77/d3/8b3ebd295cdd40464cd13749acfa96de6b1776da63c95491e3fd0490f542/django-anonymous-0.4.0.tar.gz",
"platform": "any",
"description": "# django-anonymous \n\n[![CI](https://github.com/krukas/django-anonymous/actions/workflows/main.yml/badge.svg)](https://github.com/krukas/django-anonymous/actions/workflows/main.yml)\n[![codecov](https://codecov.io/gh/krukas/django-anonymous/branch/master/graph/badge.svg?token=BPQQ1RVKDJ)](https://codecov.io/gh/krukas/django-anonymous)\n[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n[![PyPI version](https://badge.fury.io/py/django-anonymous.svg)](https://badge.fury.io/py/django-anonymous)\n\n\nSimple Django module to anonymize production data for safe usage on non-production environments.\n\n## Installation\n\n pip install django-anonymous\n\n## Usage\n\nIn your app create a file `anon.py`:\n\n```python\nfrom django_anonymous import Anonymizer, Faker, register\nfrom .model import YourModel\n\n\n@register(YourModel)\nclass YourModelAnonymizer(Anonymizer):\n \n # You can give any callable, Faker is a small wrapper around the `faker` library. \n email = Faker(\"email\", unique=True)\n \n # You can also use any static value\n first_name = \"Anon\"\n```\n\nRun the anonymizer\n\n python manage.py anonymize\n\n## Custom QuerySet\n\nYou can set a custom QuerySet to filter out some objects\n\n```python\nfrom django_anonymous import Anonymizer, Faker, register\nfrom .model import YourModel\n\n\n@register(YourModel)\nclass YourModelAnonymizer(Anonymizer):\n email = Faker(\"email\", unique=True)\n\n def get_queryset(self):\n return super().get_queryset().filter(is_staff=True)\n```\n\n## Faker seed\n\nDefault it will use the object id as seed, to generate the same data for every run.\nYou can disable this by overriding the `get_object_seed` and return falsy value.\n\n```python\nfrom django_anonymous import Anonymizer, Faker, register\nfrom .model import YourModel\n\n\n@register(YourModel)\nclass YourModelAnonymizer(Anonymizer):\n email = Faker(\"email\", unique=True)\n\n def get_object_seed(self, obj):\n return None\n```\n\n## Settings for Anonymizer\n\nPer Anonymizer you can set the select chunk size and update batch size.\nDefault it will not anonymize a field that has no value.\n\n```python\nfrom django_anonymous import Anonymizer, Faker, register\nfrom .model import YourModel\n\n\n@register(YourModel)\nclass YourModelAnonymizer(Anonymizer):\n SELECT_CHUNK_SIZE = 100\n UPDATE_BATCH_SIZE = 25\n ANONYMIZE_EMPTY_FIELD = False\n \n email = Faker(\"email\", unique=True)\n```\n\n## Inspired by\n\n- https://github.com/Tesorio/django-anon\n- https://github.com/FactoryBoy/factory_boy\n\n\n",
"bugtrack_url": null,
"license": "GPL3",
"summary": "Simple Djanngo module to anonymize production data for safe usage on none production environments",
"version": "0.4.0",
"project_urls": {
"Download": "https://github.com/fourdigits/django-anonymous/releases/tag/0.4.0",
"Homepage": "https://github.com/fourdigits/django-anonymous"
},
"split_keywords": [
"django",
"anonymous",
"anonymize"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7f4551253872cfe0823861cc7cbbdbe159374c9ca566f4f7cd898dbbe5d95e27",
"md5": "4f27574604ba0fcecd27f2ee58eedae2",
"sha256": "0a3b330d8a0e5b5b483b67b1758283f6119276c9689657c92e20a28810c80c65"
},
"downloads": -1,
"filename": "django_anonymous-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4f27574604ba0fcecd27f2ee58eedae2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 17955,
"upload_time": "2023-06-06T10:57:40",
"upload_time_iso_8601": "2023-06-06T10:57:40.767916Z",
"url": "https://files.pythonhosted.org/packages/7f/45/51253872cfe0823861cc7cbbdbe159374c9ca566f4f7cd898dbbe5d95e27/django_anonymous-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "77d38b3ebd295cdd40464cd13749acfa96de6b1776da63c95491e3fd0490f542",
"md5": "c421f76b0a242fee8362e585263a33f2",
"sha256": "bc652560497be7f429ba1930b8a4afd1f4686c7f0d0d96b56e8f4d186ea48bdb"
},
"downloads": -1,
"filename": "django-anonymous-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "c421f76b0a242fee8362e585263a33f2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 17218,
"upload_time": "2023-06-06T10:57:43",
"upload_time_iso_8601": "2023-06-06T10:57:43.955470Z",
"url": "https://files.pythonhosted.org/packages/77/d3/8b3ebd295cdd40464cd13749acfa96de6b1776da63c95491e3fd0490f542/django-anonymous-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-06 10:57:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "fourdigits",
"github_project": "django-anonymous",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "django-anonymous"
}