Skip to main content

The Anonymize library provides functionality to anonymize sensitive data in different formats, such as strings, lists, and dictionaries. This library is useful for developers who need to ensure data privacy in their applications.

Project description

anonymize-data

Documentation Status

The anonymize-data library provides functionality to anonymize sensitive data in different formats, such as strings, lists, and dictionaries. This library is useful for developers who need to ensure data privacy in their applications.

Quickstart

Installation

pip

pip install anonymize-data

uv

uv add anonymize-data

Anonymize strings

To anonymize strings in your project you can use the MaskStr class.

Example:

from anonymizer_data import MaskStr
string = MaskStr("Hello Word")
string.anonymize()
print(string)  # result: *******ord

You can control how much percent the string will be anonymized relative to its length via the size_anonymization parameter. You can pass a value from 0 to 1.
You can also pass a negative value to reverse the anonymization.

Example:

from anonymizer_data import MaskStr
string = MaskStr("Hello Word", size_anonymization=0.5)
string.anonymize()
print(string)  # result: ***** Word
MaskStr("Hello Word", size_anonymization=0.5).anonymize()  # result: Hello*****

Anonymize lists

List anonymization is done by the MaskList class.

Example:

from anonymizer_data import MaskList
list_data = MaskList(['1234435', '98765432', '24295294', 'Jhon Doe'])
list_data.anonymize()
print(list_data)  # result: ['****435', '*****432', '*****294', '*****Doe']

Anonymize dict

Dictionary's anonymization is done by the MaskList class.

Example:

from anonymizer_data import MaskDict
dict_data = MaskDict(
    {
        "username": "JhonDoe",
        "password": "123Change",
        "roles": ['Admin', 'developer'],
        "contact": {
            "number": "+55 (99) 99999-9999"
        }
    }
)
dict_data.anonymize()
print(dict_data)  # result: {'username': '****Doe', 'password': '******nge', 'roles': ['***in', '******per'], 'contact': {'number': '*************9-9999'}}

Note: Dictionary anonymization brings with it other advantages such as: choosing which keys in the dictionary should be anonymized; enabling exclusive anonymization based on the key. For example, jhondue@example.com would become ******e@example.com.

cli

You can anonymize strings from the command line. For this you need to have uv installed.

Exemple:

uv run anonymize "Hello Word"
*******ord
uv run anonymmize --help
Usage: anonymize [OPTIONS] VALUE [TYPE_MASK] [SIZE_ANONYMIZATION]                                                                                            

 cli anonymization string                                                                                                                                     

╭─ Arguments ───────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ *    value                   TEXT                  The string you want to anonymize [default: None] [required]    │
│      type_mask               [TYPE_MASK]           The type mask to use [default: string]                         │
│      size_anonymization      [SIZE_ANONYMIZATION]  The size anonymization factor [default: 0.7]                   │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --install-completion          Install completion for the current shell.                                           │
│ --show-completion             Show completion for the current shell, to copy it or customize the installation.    │
│ --help                        Show this message and exit.                                                         │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

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

anonymizer_data-0.1.1.tar.gz (211.9 kB view details)

Uploaded Source

Built Distribution

anonymizer_data-0.1.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file anonymizer_data-0.1.1.tar.gz.

File metadata

  • Download URL: anonymizer_data-0.1.1.tar.gz
  • Upload date:
  • Size: 211.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for anonymizer_data-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8dc548ef81096e5ffd0898e309f5c2fdad0e72ae7c0907a170c0331d9e591dec
MD5 4dca1e93dd8d8a0c46f093268c083712
BLAKE2b-256 c2164f5441632cf4ccf5f9d77bf7d4b459b2586d314b669494d947bfd5a3fc21

See more details on using hashes here.

File details

Details for the file anonymizer_data-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for anonymizer_data-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a421df23f54d6977cfd38d90fd3dbbbb0f08f70be6400107726c3a82a210f825
MD5 6414f5fdb00f35576a8bb3dab3b7623c
BLAKE2b-256 ac61db63d26350de056af6cef09b8c40b90540dfadd3612dbdc1d5344facfac0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page