Skip to main content

Declarative transformation tool for JSON, CSV, and filenames with stable mappings - ideal for anonymization and data manipulation

Project description

Structured Data Transformer

Anonymize sensitive fields in JSON, CSV, and filenames — with stable mappings for reversible anonymization.


Installation

pip install .

Or for development:

pip install -e '.[dev]'

Usage (CLI)

sdt --config CONFIG --base-dir BASE_DIR

Usage help:

sdt -h

Output:

usage: sdt [-h] --config CONFIG --base-dir BASE_DIR [--cache-in CACHE_IN] [--cache-out CACHE_OUT] [--reverse-cache]

Apply structured data transforms in place.

options:
  -h, --help            show this help message and exit
  --config CONFIG, -c CONFIG
                        Path to the JSON config file to load.
  --base-dir BASE_DIR, -d BASE_DIR
                        Base directory containing the data to transform in place.
  --cache-in CACHE_IN, -ci CACHE_IN
                        Optional path to input JSON cache file for stable anonymizer.
  --cache-out CACHE_OUT, -co CACHE_OUT
                        Optional path to output JSON cache file for stable anonymizer.
  --reverse-cache, -r   Reverse keys and values in the input cache (for decoding instead of encoding).

Examples

There is examples folder containing simple input, output, config and key.json.

Anonymize:

sdt --config examples/simple/config.json --base-dir examples/simple/input

Anonymize using existing key:

sdt -c examples/simple/config.json -d examples/simple/input -ci examples/simple/key.json

Reverse:

sdt -c examples/simple/config.json -d examples/simple/output -r -ci examples/simple/key.json

What it does

  • Anonymizes fields in JSON, CSV, and filenames with pattern rules.
  • Handles Bitcoin transactions, addresses, company names, emails, etc.
  • Keeps empty values unchanged.
  • Maintains a stable mapping so each value is always replaced the same way.
  • Saves the key for reuse so data can be deanonymized with --reverse-cache.

Customization

Custom transforms

You can add your own transform function. It doesn't necessarily need to anonymize, it can transform the field to any kind of form. Transform function expected input and output is Optional[str | int | float | bool] (Json primitives). Only str can happen for csv/path adapters.

To register the transform function, use register_transform(func: callable, name: str)

Example custom transform can be uppercase:

from typing import Optional
from structured_data_transformer.transforms import register_transform
from structured_data_transformer.types import JSONPrimitive


def uppercase(value: Optional[JSONPrimitive]) -> Optional[JSONPrimitive]:
    if value:
        return str(value).upper()
    return value


register_transform(uppercase, "uppercase")

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

structured_data_transformer-0.2.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

structured_data_transformer-0.2.1-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file structured_data_transformer-0.2.1.tar.gz.

File metadata

File hashes

Hashes for structured_data_transformer-0.2.1.tar.gz
Algorithm Hash digest
SHA256 db1c9bf82fd4469092732f71ba75c8960cfd1addc292d8970090e5bd0d173c75
MD5 59ee0b4193c7e10a70e432ed4c3d8b3e
BLAKE2b-256 9333069a571a79b71894a02c25961554c191c3557f31b2423623db4df152140c

See more details on using hashes here.

File details

Details for the file structured_data_transformer-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for structured_data_transformer-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d9efe9952a816eed12da0b74326bbe60c1c06bda2b23440f1f1f05302758977
MD5 cece64e4e6db212fdfb989598832ba32
BLAKE2b-256 1ef61beaf3b9422d3096c878502483b076f136af2b0aa1808eaa4a752bf2ba49

See more details on using hashes here.

Supported by

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