{"id":19499692,"url":"https://github.com/apsl/django-hattori","last_synced_at":"2025-04-25T22:34:21.614Z","repository":{"id":57420333,"uuid":"132881785","full_name":"APSL/django-hattori","owner":"APSL","description":"Command to anonymize sensitive data","archived":false,"fork":false,"pushed_at":"2019-09-17T11:36:51.000Z","size":33,"stargazers_count":18,"open_issues_count":5,"forks_count":6,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-14T04:08:05.599Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/APSL.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-10T09:55:44.000Z","updated_at":"2023-12-05T06:39:56.000Z","dependencies_parsed_at":"2022-09-15T02:42:30.008Z","dependency_job_id":null,"html_url":"https://github.com/APSL/django-hattori","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/APSL%2Fdjango-hattori","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/APSL%2Fdjango-hattori/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/APSL%2Fdjango-hattori/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/APSL%2Fdjango-hattori/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/APSL","download_url":"https://codeload.github.com/APSL/django-hattori/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224019605,"owners_count":17242177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T22:05:50.490Z","updated_at":"2024-11-10T22:05:51.442Z","avatar_url":"https://github.com/APSL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django-Hattori\n\n[![pypi](https://img.shields.io/pypi/v/django-hattori.svg)](https://pypi.python.org/pypi/django-hattori/)\n\n\nCommand to anonymize sensitive data. This app helps you anonymize data in a database used for development of a Django project.\n\nThis app is based on [Django-Database-Anonymizer](https://github.com/Blueshoe/Django-Database-Anonymizer), using [Faker](https://github.com/joke2k/faker) to anonymize the values.\n\n## Installation\n\nInstall using pip:\n\n```\npip install django-hattori\n```\n\nThen add ``'hattori'`` to your ``INSTALLED_APPS``.\n\n```\nINSTALLED_APPS = [\n    ...\n    'hattori',\n]\n```\n\n### Important\n\n***You should only run the anonymize process in PRE or development environments***. To avoid problems by default anonymization is disabled.\n\nTo enable you must add to settings ```ANONYMIZE_ENABLED=True```\n\n\n## Usage\n\nHow to execute command:\n\n    ./manage.py anonymize_db\n\nPossible arguments:\n\n* ```-a, --app```: Define a app you want to anonymize. All anonymizers in this app will be run. Eg. ```anonymize_db -a shop```\n* ```-m, --models```: List of models you want to anonymize. Eg. ```anonymize_db -m Customer,Product```\n* ```-b, --batch-size```: batch size used in the bulk_update of the instances. Depends on the DB machine, default use 500.\n\n\n## Writing anonymizers\n\nIn order to use the management command we need to define _**anonymizers**_.\n\n* Create a module _anonymizers.py_ in the given django-app\n* An _anonymizer_ is a simple class that inherits from ```BaseAnonymizer```\n* Each anonymizer class is going to represent **one** model\n* An anonymizer has the following members:\n    * ```model```: (required) The model class for this anonymizer\n    * ```attributes```: (required) List of tuples that determine which fields to replace. The first value of the tuple is the fieldname, the second value is the _**replacer**_\n    * ```get_query_set()```: (optional) Define your QuerySet\n* A _replacer_ is either of type _str_ or _callable_\n* A callable _replacer_ is a Faker instance or custom replacer.\n* All Faker methods are available. For more info read the official documentation [Faker!](http://faker.readthedocs.io/en/master/providers.html)\n\n\n#### Example\n```\nfrom hattori.base import BaseAnonymizer, faker\nfrom shop.models import Customer\n\nclass CustomerAnonymizer(BaseAnonymizer):\n    model = Customer\n\n    attributes = [\n        ('card_number', faker.credit_card_number),\n        ('first_name', faker.first_name),\n        ('last_name', faker.last_name),\n        ('phone', faker.phone_number),\n        ('email', faker.email),\n        ('city', faker.city),\n        ('comment', faker.text),\n        ('description', 'fix string'),\n        ('code', faker.pystr),\n    ]\n\n    def get_query_set(self):\n        return Customer.objects.filter(age__gt=18)\n```\n\n#### Extending the existing replacers with arguments\nUse lambdas to extend certain predefined replacers with arguments, like `min_chars` or `max_chars` on `faker.pystr`:\n\n```\n('code', lambda **kwargs: faker.pystr(min_chars=250, max_chars=250, **kwargs)),\n```\n\n**Important**: don't forget the ****kwargs**!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapsl%2Fdjango-hattori","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapsl%2Fdjango-hattori","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapsl%2Fdjango-hattori/lists"}