Skip to main content

UUnonymous

This description can be found on GitHub here

UUnonymous facilitates the replacement of keywords or regex-patterns within a file tree or zipped archive. It recursively traverses the tree, opens supported files and substitutes any found pattern or keyword with a replacement. Besides contents, UUnonymous will substitue keywords/patterns in file/folder-paths as well.

The result will be either a copied or replaced version of the original file-tree with all substitutions made.

As of now, UUnonymous supports text-based files, like .txt, .html, .json and .csv. UTF-8 encoding is assumed. Besides text files, UUnonymous is also able to handle (nested) zip archives. These archives will be unpacked in a temp folder, processed and zipped again.

Installation

$ pip install UUnonymous

Usage

Import the Anomymize class in your code and create an anonymization object like this:

from uunonymous import Anonymize

# refer to csv files in which keywords and substitutions are paired
anonymize_csv = Anonymize('/Users/casper/Desktop/keys.csv')

# using a dictionary instead of a csv file:
my_dict = {
    'A1234': 'aaaa',
    'B9876': 'bbbb',
}
anonymize_dict = Anonymize(my_dict)

# specifying a zip-format to zip unpacked archives after processing (.zip is default)
anonymize_zip = Anonymize('/Users/casper/Desktop/keys.csv', zip_format='gztar')

When using a csv-file, UUnonymous will assume your file contains two columns: the left column contains the keywords which need to be replaced, the right column contains their substitutions. Column headers are mandatory, but don't have to follow a specific format.

When using a dictionary only (absence of the pattern argument), the keys will be replaced by their values.

Performance might be enhanced when your keywords can be generalized into regular expressions. Anynomize_UU will search these patterns and replace them instead of matching the entire dictionary/csv-file against file contents or file/folder-paths. Example:

anonymize_regex = Anonymize(my_dict, pattern=r'[A-B]\d{4}')

By default is case sensitive by default. The regular expressions that take care of the replacements can be modified by using the flag parameter. It takes one or more variables which can be found here. Multiple variables are combined by a bitwise OR (the | operator). Example for a case-insensitive substitution:

anonymize_regex = Anonymize(my_dict, flags=re.IGNORECASE)

By using the use_word_boundaries argument (defaults to False), the algorithm ignores substring matches. If 'ted' is a key in your dictionary, without use_word_boundaries the algorithm will replace the 'ted' part in f.i. 'created_at'. You can overcome this problem by setting use_word_boundaries to True. It will put the \b-anchor around your regex pattern or dictionary keys. The beauty of the boundary anchors is that '@' is considered a boundary as well, and thus names in email addresses can be replaced. Example:

anonymize_regex = Anonymize(my_dict, use_word_boundaries=True)

Windows usage

There is an issue with creating zip archives. Make sure you run UUnonymous as administrator.

Inplace replacements vs. replacements in a copy

UUnonymous is able to create a copy of the processed file-tree or replace it. The substitute method takes a mandatory source-path argument (path to a file, folder or zip-archive, either a string or a Path object) and an optional target-path argument (again, a string or Path object). The target needs to refer to a folder. The target-folder will be created if it doesn't exist.

When the target argument is provided, UUnonymous will create a processed copy of the source into the target-folder. If the source is a single file, and the file path does not contain elements that will be replaced, and the target-folder is identical to the source folder, than the processed result will get a 'copy' extension to prevent overwriting.

When the target argument is omitted, the source will be overwritten by a processed version of it:

# process the datadownload.zip file, replace all patterns and write
# a copy to the 'bucket' folder.
anonymize_regex.substitute(
    '/Users/casper/Desktop/datadownload.zip', 
    '/Users/casper/Desktop/bucket'
)

# process the 'download' folder and replace the original by its processed 
# version
anonymize_regex.substitute('/Users/casper/Desktop/download')

# process a single file, and replace it
anonymize_regex.substitute('/Users/casper/Desktop/my_file.json')

Todo

Testing ;)

Release files for UUnonymous 0.0.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 UUnonymous 0.0.1
File Size Uploaded
UUnonymous-0.0.1.tar.gz 5.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for UUnonymous 0.0.1
File Interpreter ABI Platform
UUnonymous-0.0.1-py3.7.egg Legacy Egg format - - Details
UUnonymous-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.7 kB

Release files / UUnonymous-0.0.1.tar.gz

Download URL UUnonymous-0.0.1.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
17a2c247b8cbcd266aa4876416e5733a0c8c1fc5bb681679e4df4ee44d15e2b5
BLAKE2b-256 checksum
How to use checksums
15b0c0d8211602974d1c7b44b86804665ce24978894a8651f297d3d233b53157
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release files / UUnonymous-0.0.1-py3.7.egg

Download URL UUnonymous-0.0.1-py3.7.egg
Size 9.7 kB
Tags Egg
SHA-256 checksum
How to use checksums
ebf566cba3cd0d414644661754f6b098cdf0663856bb7267d4a967540b017de7
BLAKE2b-256 checksum
How to use checksums
92bbdb8f9771dd575afd61605689677ef3b0a58d98209333a0af1b0f698317c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release files / UUnonymous-0.0.1-py3-none-any.whl

Download URL UUnonymous-0.0.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d17923eaca9d623ab1ed96672721e4c6d44845c66e4327e4fa59240e74d6014
BLAKE2b-256 checksum
How to use checksums
639526b4918ab68fc6f88ca0eb51bf7e8df541e6047f2b76f49f77f88e8f9046
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release history Release notifications | RSS feed

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

This release

0.0.1 This release

3 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