Skip to main content

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.                                                         │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Release files for anonymizer-data 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anonymizer-data 0.1.1
File Size Uploaded
anonymizer_data-0.1.1.tar.gz 211.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for anonymizer-data 0.1.1
File Interpreter ABI Platform
anonymizer_data-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 223.4 kB

Release files / anonymizer_data-0.1.1.tar.gz

Download URL anonymizer_data-0.1.1.tar.gz
Size 211.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8dc548ef81096e5ffd0898e309f5c2fdad0e72ae7c0907a170c0331d9e591dec
BLAKE2b-256 checksum
How to use checksums
c2164f5441632cf4ccf5f9d77bf7d4b459b2586d314b669494d947bfd5a3fc21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / anonymizer_data-0.1.1-py3-none-any.whl

Download URL anonymizer_data-0.1.1-py3-none-any.whl
Size 11.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a421df23f54d6977cfd38d90fd3dbbbb0f08f70be6400107726c3a82a210f825
BLAKE2b-256 checksum
How to use checksums
ac61db63d26350de056af6cef09b8c40b90540dfadd3612dbdc1d5344facfac0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page