lookalike 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lookalike-0.1.0/.github/workflows/ci.yml +64 -0
- lookalike-0.1.0/.github/workflows/release.yml +131 -0
- lookalike-0.1.0/.gitignore +8 -0
- lookalike-0.1.0/PKG-INFO +128 -0
- lookalike-0.1.0/README.md +116 -0
- lookalike-0.1.0/docs/cli.md +220 -0
- lookalike-0.1.0/docs/column-types.md +140 -0
- lookalike-0.1.0/docs/formats.md +64 -0
- lookalike-0.1.0/docs/getting-started.md +102 -0
- lookalike-0.1.0/docs/privacy.md +105 -0
- lookalike-0.1.0/docs/python-api.md +73 -0
- lookalike-0.1.0/docs/releasing.md +70 -0
- lookalike-0.1.0/docs/verification.md +121 -0
- lookalike-0.1.0/examples/customers.csv +7 -0
- lookalike-0.1.0/pyproject.toml +29 -0
- lookalike-0.1.0/scripts/smoke-test.sh +18 -0
- lookalike-0.1.0/src/lookalike/__init__.py +8 -0
- lookalike-0.1.0/src/lookalike/cli.py +338 -0
- lookalike-0.1.0/src/lookalike/config.py +173 -0
- lookalike-0.1.0/src/lookalike/core.py +499 -0
- lookalike-0.1.0/src/lookalike/detect.py +224 -0
- lookalike-0.1.0/src/lookalike/fake.py +223 -0
- lookalike-0.1.0/src/lookalike/io.py +168 -0
- lookalike-0.1.0/src/lookalike/regexgen.py +193 -0
- lookalike-0.1.0/src/lookalike/verify.py +252 -0
- lookalike-0.1.0/tests/test_lookalike.py +547 -0
- lookalike-0.1.0/uv.lock +333 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# CI: tests on every supported Python, plus a build of the wheel and sdist.
|
|
2
|
+
# Also called by release.yml, so a release runs exactly these checks on the tagged commit.
|
|
3
|
+
name: ci
|
|
4
|
+
|
|
5
|
+
on:
|
|
6
|
+
push:
|
|
7
|
+
branches: [main]
|
|
8
|
+
pull_request:
|
|
9
|
+
workflow_call:
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
permissions: {}
|
|
13
|
+
|
|
14
|
+
concurrency:
|
|
15
|
+
group: ci-${{ github.workflow_ref }}-${{ github.ref }}
|
|
16
|
+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
|
17
|
+
|
|
18
|
+
env:
|
|
19
|
+
UV_VERSION: "0.10.4"
|
|
20
|
+
|
|
21
|
+
jobs:
|
|
22
|
+
test:
|
|
23
|
+
name: Tests (Python ${{ matrix.python }})
|
|
24
|
+
runs-on: ubuntu-24.04
|
|
25
|
+
timeout-minutes: 15
|
|
26
|
+
permissions:
|
|
27
|
+
contents: read
|
|
28
|
+
strategy:
|
|
29
|
+
fail-fast: false
|
|
30
|
+
matrix:
|
|
31
|
+
python: ["3.10", "3.12", "3.13"]
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
34
|
+
with:
|
|
35
|
+
persist-credentials: false
|
|
36
|
+
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
|
37
|
+
with:
|
|
38
|
+
version: ${{ env.UV_VERSION }}
|
|
39
|
+
enable-cache: false
|
|
40
|
+
- name: Lockfile is current
|
|
41
|
+
run: uv lock --check
|
|
42
|
+
- name: Tests
|
|
43
|
+
env:
|
|
44
|
+
PYTHON: ${{ matrix.python }}
|
|
45
|
+
run: uv run --locked --python "$PYTHON" pytest -q
|
|
46
|
+
|
|
47
|
+
build:
|
|
48
|
+
name: Build and smoke-test the wheel
|
|
49
|
+
runs-on: ubuntu-24.04
|
|
50
|
+
timeout-minutes: 10
|
|
51
|
+
permissions:
|
|
52
|
+
contents: read
|
|
53
|
+
steps:
|
|
54
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
55
|
+
with:
|
|
56
|
+
persist-credentials: false
|
|
57
|
+
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
|
58
|
+
with:
|
|
59
|
+
version: ${{ env.UV_VERSION }}
|
|
60
|
+
enable-cache: false
|
|
61
|
+
- name: Build
|
|
62
|
+
run: uv build --out-dir dist
|
|
63
|
+
- name: Install the wheel on its own and run it
|
|
64
|
+
run: scripts/smoke-test.sh "$(ls dist/*.whl)"
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Release: push a tag vX.Y.Z (matching pyproject's version) on a commit in main.
|
|
2
|
+
# verify -> the full CI run on the tagged commit
|
|
3
|
+
# build -> wheel and sdist, built once, smoke-tested, with SHA-256 checksums
|
|
4
|
+
# pypi -> uploads those exact files to PyPI with Trusted Publishing (OIDC, no stored token)
|
|
5
|
+
# and PEP 740 attestations; only when the repo variable PYPI_PUBLISH is "true"
|
|
6
|
+
# publish -> GitHub release with the same files
|
|
7
|
+
# One-time setup and the release steps are in docs/releasing.md.
|
|
8
|
+
name: release
|
|
9
|
+
|
|
10
|
+
on:
|
|
11
|
+
push:
|
|
12
|
+
tags: ["v*"]
|
|
13
|
+
|
|
14
|
+
permissions: {}
|
|
15
|
+
|
|
16
|
+
concurrency:
|
|
17
|
+
group: release-${{ github.ref }}
|
|
18
|
+
cancel-in-progress: false
|
|
19
|
+
|
|
20
|
+
env:
|
|
21
|
+
UV_VERSION: "0.10.4"
|
|
22
|
+
|
|
23
|
+
jobs:
|
|
24
|
+
verify:
|
|
25
|
+
name: CI
|
|
26
|
+
uses: ./.github/workflows/ci.yml
|
|
27
|
+
permissions:
|
|
28
|
+
contents: read
|
|
29
|
+
|
|
30
|
+
build:
|
|
31
|
+
name: Build release artifacts
|
|
32
|
+
needs: verify
|
|
33
|
+
runs-on: ubuntu-24.04
|
|
34
|
+
timeout-minutes: 10
|
|
35
|
+
permissions:
|
|
36
|
+
contents: read
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
39
|
+
with:
|
|
40
|
+
fetch-depth: 0 # all branches, so origin/main is present for the on-main check
|
|
41
|
+
persist-credentials: false
|
|
42
|
+
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
|
|
43
|
+
with:
|
|
44
|
+
version: ${{ env.UV_VERSION }}
|
|
45
|
+
enable-cache: false
|
|
46
|
+
- name: Tag matches version and is on main
|
|
47
|
+
env:
|
|
48
|
+
TAG: ${{ github.ref_name }}
|
|
49
|
+
run: |
|
|
50
|
+
version=$(uv version --short)
|
|
51
|
+
if [[ "$TAG" != "v$version" ]]; then
|
|
52
|
+
echo "::error::tag $TAG does not match pyproject version $version"; exit 1
|
|
53
|
+
fi
|
|
54
|
+
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
|
|
55
|
+
echo "::error::tagged commit $GITHUB_SHA is not on main"; exit 1
|
|
56
|
+
fi
|
|
57
|
+
- name: Build (reproducible timestamps)
|
|
58
|
+
run: |
|
|
59
|
+
SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)
|
|
60
|
+
export SOURCE_DATE_EPOCH
|
|
61
|
+
uv build --out-dir dist
|
|
62
|
+
- name: Install the wheel on its own and run it
|
|
63
|
+
run: scripts/smoke-test.sh "$(ls dist/*.whl)"
|
|
64
|
+
- name: Checksums
|
|
65
|
+
run: cd dist && sha256sum -- * > SHA256SUMS && cat SHA256SUMS
|
|
66
|
+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
|
67
|
+
with:
|
|
68
|
+
name: dist
|
|
69
|
+
path: dist/
|
|
70
|
+
retention-days: 90
|
|
71
|
+
|
|
72
|
+
# PyPI never accepts a filename twice, even after deletion, so this runs only after CI and the
|
|
73
|
+
# build passed. It uploads exactly the files built above (checksum-verified), nothing rebuilt.
|
|
74
|
+
# The PyPI project trusts only this workflow file in the `pypi` environment, which is
|
|
75
|
+
# restricted to v* tags; see docs/releasing.md.
|
|
76
|
+
pypi:
|
|
77
|
+
name: Publish to PyPI
|
|
78
|
+
needs: build
|
|
79
|
+
if: ${{ vars.PYPI_PUBLISH == 'true' }}
|
|
80
|
+
runs-on: ubuntu-24.04
|
|
81
|
+
timeout-minutes: 15
|
|
82
|
+
environment:
|
|
83
|
+
name: pypi
|
|
84
|
+
url: https://pypi.org/project/lookalike/
|
|
85
|
+
permissions:
|
|
86
|
+
id-token: write # Trusted Publishing (OIDC) and the PEP 740 attestations
|
|
87
|
+
steps:
|
|
88
|
+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
89
|
+
with:
|
|
90
|
+
name: dist
|
|
91
|
+
path: dist
|
|
92
|
+
- name: Pick the built wheel and sdist
|
|
93
|
+
env:
|
|
94
|
+
TAG: ${{ github.ref_name }}
|
|
95
|
+
run: |
|
|
96
|
+
(cd dist && sha256sum -c SHA256SUMS)
|
|
97
|
+
version="${TAG#v}"
|
|
98
|
+
mkdir pypi-dist
|
|
99
|
+
cp -- "dist/lookalike-$version-py3-none-any.whl" "dist/lookalike-$version.tar.gz" pypi-dist/
|
|
100
|
+
ls -l pypi-dist
|
|
101
|
+
sha256sum pypi-dist/*
|
|
102
|
+
# Pinned by commit. That commit runs ghcr.io/pypa/gh-action-pypi-publish by tag, not digest
|
|
103
|
+
# (the same accepted risk as in capitaltg/icebergdx).
|
|
104
|
+
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
|
|
105
|
+
with:
|
|
106
|
+
packages-dir: pypi-dist/
|
|
107
|
+
attestations: true
|
|
108
|
+
print-hash: true
|
|
109
|
+
|
|
110
|
+
publish:
|
|
111
|
+
name: Publish GitHub release
|
|
112
|
+
needs: [build, pypi]
|
|
113
|
+
if: ${{ !cancelled() && needs.build.result == 'success' && needs.pypi.result != 'failure' }}
|
|
114
|
+
runs-on: ubuntu-24.04
|
|
115
|
+
timeout-minutes: 10
|
|
116
|
+
environment: release # restricted to v* tags
|
|
117
|
+
permissions:
|
|
118
|
+
contents: write
|
|
119
|
+
steps:
|
|
120
|
+
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
121
|
+
with:
|
|
122
|
+
name: dist
|
|
123
|
+
path: dist
|
|
124
|
+
- name: Create release
|
|
125
|
+
env:
|
|
126
|
+
GH_TOKEN: ${{ github.token }}
|
|
127
|
+
TAG: ${{ github.ref_name }}
|
|
128
|
+
run: |
|
|
129
|
+
cd dist && sha256sum -c SHA256SUMS
|
|
130
|
+
gh release create "$TAG" --repo "$GITHUB_REPOSITORY" --verify-tag --generate-notes \
|
|
131
|
+
--title "$TAG" -- *
|
lookalike-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: lookalike
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Anonymize structured data files with random fake values while preserving schema, types and uniqueness cardinality.
|
|
5
|
+
Project-URL: Repository, https://github.com/capitaltg/lookalike
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: faker>=20
|
|
8
|
+
Requires-Dist: tomli>=2; python_version < '3.11'
|
|
9
|
+
Provides-Extra: parquet
|
|
10
|
+
Requires-Dist: pyarrow>=14; extra == 'parquet'
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# lookalike
|
|
14
|
+
|
|
15
|
+
Turn a data file full of real people into one that looks the same but isn't.
|
|
16
|
+
|
|
17
|
+
`lookalike` replaces every value in a CSV, JSON, JSON Lines or Parquet file
|
|
18
|
+
with random fake data of the same type and shape. Each column keeps its number
|
|
19
|
+
of distinct values and how often each one occurs, so the copy behaves like the
|
|
20
|
+
original in tests, demos and analysis. Before the output is saved it is checked
|
|
21
|
+
against the input; if any original value survived, nothing is written.
|
|
22
|
+
|
|
23
|
+
## Example
|
|
24
|
+
|
|
25
|
+
Input (`examples/customers.csv`):
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
customer_id,full_name,email,phone,ssn,city,state,...
|
|
29
|
+
CU-1001,Maria Lopez,maria.lopez@acme.com,(703) 281-4410,514-22-9081,Reston,VA,...
|
|
30
|
+
CU-1002,James Carter,jcarter@gmail.com,(301) 774-2295,233-71-4406,Bethesda,MD,...
|
|
31
|
+
CU-1003,Priya Nair,priya.nair@acme.com,(571) 902-1184,601-35-7720,Reston,VA,...
|
|
32
|
+
CU-1001,Maria Lopez,maria.lopez@acme.com,(703) 281-4410,514-22-9081,Reston,VA,...
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Output:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
customer_id,full_name,email,phone,ssn,city,state,...
|
|
39
|
+
ZO-7893,Scott Kirby,hartdaniel298@ikuma.example,(249) 555-4032,000-62-2439,West Jasonborough,DC,...
|
|
40
|
+
WO-9217,April Bowman,ojones692@bajecoro.example,(899) 555-1023,000-32-8367,North Josephmouth,CO,...
|
|
41
|
+
DU-0967,Vincent Bates,matthew45420@ikuma.example,(940) 555-9546,000-60-1108,West Jasonborough,DC,...
|
|
42
|
+
ZO-7893,Scott Kirby,hartdaniel298@ikuma.example,(249) 555-4032,000-62-2439,West Jasonborough,DC,...
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Rows 1 and 4 were the same customer and still are. The two `acme.com`
|
|
46
|
+
addresses still share a domain. Nothing real is left.
|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
|
|
50
|
+
Requires Python 3.10 or newer.
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
pip install lookalike
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
For Parquet files, install with the extra:
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
pip install "lookalike[parquet]"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Use
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
lookalike inspect customers.csv # 1. see how each column will be treated
|
|
66
|
+
lookalike anonymize customers.csv safe.csv # 2. write the anonymized copy
|
|
67
|
+
lookalike verify customers.csv safe.csv # 3. optional: re-check later
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Common adjustments. `ssn`, `notes`, `order_total` and `col7` below stand for
|
|
71
|
+
column names in your own file; `inspect` lists them.
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
lookalike anonymize in.csv out.csv --drop ssn --drop notes # remove the ssn and notes columns
|
|
75
|
+
lookalike anonymize in.csv out.csv --keep order_total # leave the order_total column as is
|
|
76
|
+
lookalike anonymize in.csv out.csv --type col7=name # tell it the col7 column holds people's names
|
|
77
|
+
lookalike anonymize in.csv out.csv --type 'code=regex:[0-9]{2}-[A-Z]{5}' # fill the code column from your own pattern
|
|
78
|
+
lookalike anonymize in.csv out.csv --report report.json # save the check results
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`--type` takes `COLUMN=TYPE`. Every column is anonymized whatever its type;
|
|
82
|
+
the type only decides what the fakes look like. A column of names that
|
|
83
|
+
`inspect` shows as `text` would come out as `Kovar Tunib`; with
|
|
84
|
+
`--type col7=name` it comes out as `Scott Kirby`. For a format of your own,
|
|
85
|
+
use `regex:` followed by a regular expression: `[0-9]{2}-[A-Z]{5}` gives values
|
|
86
|
+
such as `66-QNIDO`. The full list of types is in
|
|
87
|
+
[Column types](docs/column-types.md).
|
|
88
|
+
|
|
89
|
+
To reuse the same options, save them under a name and pass `--profile`
|
|
90
|
+
(see [Profiles](docs/cli.md#profiles)):
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
lookalike profile save customers --drop ssn --type col7=name
|
|
94
|
+
lookalike anonymize in.csv out.csv --profile customers
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Exit code `0` means the output was written and passed every check.
|
|
98
|
+
|
|
99
|
+
## Before you share the output
|
|
100
|
+
|
|
101
|
+
`lookalike` removes the values, not the patterns. Someone looking at the
|
|
102
|
+
output can still see how many distinct values a column has, how often each
|
|
103
|
+
occurs, where the blanks are, and the rough range of numbers and dates. That
|
|
104
|
+
is the point of the tool, but it also means a person who already knows your
|
|
105
|
+
data could recognise rows by their pattern. Drop columns you do not need, and
|
|
106
|
+
read [what is and is not guaranteed](docs/privacy.md) before publishing
|
|
107
|
+
anything.
|
|
108
|
+
|
|
109
|
+
## Documentation
|
|
110
|
+
|
|
111
|
+
| Guide | What it covers |
|
|
112
|
+
|---|---|
|
|
113
|
+
| [Getting started](docs/getting-started.md) | A first run, step by step, and how to read the results |
|
|
114
|
+
| [Command reference](docs/cli.md) | Every command and option, selecting columns, exit codes |
|
|
115
|
+
| [Column types](docs/column-types.md) | How types are detected and what each fake looks like |
|
|
116
|
+
| [Privacy guarantees](docs/privacy.md) | What is protected, what stays visible, known limits |
|
|
117
|
+
| [Verification](docs/verification.md) | The checks that run and the fields of the report |
|
|
118
|
+
| [File formats](docs/formats.md) | CSV, JSON, JSON Lines and Parquet specifics |
|
|
119
|
+
| [Python API](docs/python-api.md) | Using `lookalike` from code |
|
|
120
|
+
|
|
121
|
+
## Development
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
uv sync
|
|
125
|
+
uv run pytest
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Pushing a `vX.Y.Z` tag publishes to PyPI; see [Releasing](docs/releasing.md).
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# lookalike
|
|
2
|
+
|
|
3
|
+
Turn a data file full of real people into one that looks the same but isn't.
|
|
4
|
+
|
|
5
|
+
`lookalike` replaces every value in a CSV, JSON, JSON Lines or Parquet file
|
|
6
|
+
with random fake data of the same type and shape. Each column keeps its number
|
|
7
|
+
of distinct values and how often each one occurs, so the copy behaves like the
|
|
8
|
+
original in tests, demos and analysis. Before the output is saved it is checked
|
|
9
|
+
against the input; if any original value survived, nothing is written.
|
|
10
|
+
|
|
11
|
+
## Example
|
|
12
|
+
|
|
13
|
+
Input (`examples/customers.csv`):
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
customer_id,full_name,email,phone,ssn,city,state,...
|
|
17
|
+
CU-1001,Maria Lopez,maria.lopez@acme.com,(703) 281-4410,514-22-9081,Reston,VA,...
|
|
18
|
+
CU-1002,James Carter,jcarter@gmail.com,(301) 774-2295,233-71-4406,Bethesda,MD,...
|
|
19
|
+
CU-1003,Priya Nair,priya.nair@acme.com,(571) 902-1184,601-35-7720,Reston,VA,...
|
|
20
|
+
CU-1001,Maria Lopez,maria.lopez@acme.com,(703) 281-4410,514-22-9081,Reston,VA,...
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Output:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
customer_id,full_name,email,phone,ssn,city,state,...
|
|
27
|
+
ZO-7893,Scott Kirby,hartdaniel298@ikuma.example,(249) 555-4032,000-62-2439,West Jasonborough,DC,...
|
|
28
|
+
WO-9217,April Bowman,ojones692@bajecoro.example,(899) 555-1023,000-32-8367,North Josephmouth,CO,...
|
|
29
|
+
DU-0967,Vincent Bates,matthew45420@ikuma.example,(940) 555-9546,000-60-1108,West Jasonborough,DC,...
|
|
30
|
+
ZO-7893,Scott Kirby,hartdaniel298@ikuma.example,(249) 555-4032,000-62-2439,West Jasonborough,DC,...
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Rows 1 and 4 were the same customer and still are. The two `acme.com`
|
|
34
|
+
addresses still share a domain. Nothing real is left.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
Requires Python 3.10 or newer.
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
pip install lookalike
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
For Parquet files, install with the extra:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
pip install "lookalike[parquet]"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Use
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
lookalike inspect customers.csv # 1. see how each column will be treated
|
|
54
|
+
lookalike anonymize customers.csv safe.csv # 2. write the anonymized copy
|
|
55
|
+
lookalike verify customers.csv safe.csv # 3. optional: re-check later
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Common adjustments. `ssn`, `notes`, `order_total` and `col7` below stand for
|
|
59
|
+
column names in your own file; `inspect` lists them.
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
lookalike anonymize in.csv out.csv --drop ssn --drop notes # remove the ssn and notes columns
|
|
63
|
+
lookalike anonymize in.csv out.csv --keep order_total # leave the order_total column as is
|
|
64
|
+
lookalike anonymize in.csv out.csv --type col7=name # tell it the col7 column holds people's names
|
|
65
|
+
lookalike anonymize in.csv out.csv --type 'code=regex:[0-9]{2}-[A-Z]{5}' # fill the code column from your own pattern
|
|
66
|
+
lookalike anonymize in.csv out.csv --report report.json # save the check results
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`--type` takes `COLUMN=TYPE`. Every column is anonymized whatever its type;
|
|
70
|
+
the type only decides what the fakes look like. A column of names that
|
|
71
|
+
`inspect` shows as `text` would come out as `Kovar Tunib`; with
|
|
72
|
+
`--type col7=name` it comes out as `Scott Kirby`. For a format of your own,
|
|
73
|
+
use `regex:` followed by a regular expression: `[0-9]{2}-[A-Z]{5}` gives values
|
|
74
|
+
such as `66-QNIDO`. The full list of types is in
|
|
75
|
+
[Column types](docs/column-types.md).
|
|
76
|
+
|
|
77
|
+
To reuse the same options, save them under a name and pass `--profile`
|
|
78
|
+
(see [Profiles](docs/cli.md#profiles)):
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
lookalike profile save customers --drop ssn --type col7=name
|
|
82
|
+
lookalike anonymize in.csv out.csv --profile customers
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Exit code `0` means the output was written and passed every check.
|
|
86
|
+
|
|
87
|
+
## Before you share the output
|
|
88
|
+
|
|
89
|
+
`lookalike` removes the values, not the patterns. Someone looking at the
|
|
90
|
+
output can still see how many distinct values a column has, how often each
|
|
91
|
+
occurs, where the blanks are, and the rough range of numbers and dates. That
|
|
92
|
+
is the point of the tool, but it also means a person who already knows your
|
|
93
|
+
data could recognise rows by their pattern. Drop columns you do not need, and
|
|
94
|
+
read [what is and is not guaranteed](docs/privacy.md) before publishing
|
|
95
|
+
anything.
|
|
96
|
+
|
|
97
|
+
## Documentation
|
|
98
|
+
|
|
99
|
+
| Guide | What it covers |
|
|
100
|
+
|---|---|
|
|
101
|
+
| [Getting started](docs/getting-started.md) | A first run, step by step, and how to read the results |
|
|
102
|
+
| [Command reference](docs/cli.md) | Every command and option, selecting columns, exit codes |
|
|
103
|
+
| [Column types](docs/column-types.md) | How types are detected and what each fake looks like |
|
|
104
|
+
| [Privacy guarantees](docs/privacy.md) | What is protected, what stays visible, known limits |
|
|
105
|
+
| [Verification](docs/verification.md) | The checks that run and the fields of the report |
|
|
106
|
+
| [File formats](docs/formats.md) | CSV, JSON, JSON Lines and Parquet specifics |
|
|
107
|
+
| [Python API](docs/python-api.md) | Using `lookalike` from code |
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
uv sync
|
|
113
|
+
uv run pytest
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Pushing a `vX.Y.Z` tag publishes to PyPI; see [Releasing](docs/releasing.md).
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Command reference
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
lookalike inspect INPUT [options]
|
|
5
|
+
lookalike anonymize INPUT OUTPUT [options]
|
|
6
|
+
lookalike verify ORIGINAL ANONYMIZED [options]
|
|
7
|
+
lookalike profile save NAME [options]
|
|
8
|
+
lookalike profile list
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
### `inspect`
|
|
14
|
+
|
|
15
|
+
Prints one line per column: detected type, date format if any, whether it
|
|
16
|
+
will be anonymized or kept, and how many non-null and distinct values it has.
|
|
17
|
+
No data values are printed. Use it to decide which options you need.
|
|
18
|
+
|
|
19
|
+
### `anonymize`
|
|
20
|
+
|
|
21
|
+
Writes an anonymized copy of `INPUT` to `OUTPUT`, in the same format. The
|
|
22
|
+
output is verified before it is given its final name; if verification fails,
|
|
23
|
+
no output file is written. `OUTPUT` must not be the input file.
|
|
24
|
+
|
|
25
|
+
### `verify`
|
|
26
|
+
|
|
27
|
+
Compares an anonymized file with its original and prints the same summary
|
|
28
|
+
`anonymize` does. Pass the same column and null options that were used to
|
|
29
|
+
create the file. See [Verification](verification.md).
|
|
30
|
+
|
|
31
|
+
### `profile save` and `profile list`
|
|
32
|
+
|
|
33
|
+
Save a set of options under a name, and show what is saved. See
|
|
34
|
+
[Profiles](#profiles).
|
|
35
|
+
|
|
36
|
+
## Options for all commands
|
|
37
|
+
|
|
38
|
+
| Option | Meaning |
|
|
39
|
+
|---|---|
|
|
40
|
+
| `--keep COLUMN` | Leave this column unchanged. Repeatable. Reported as a warning. |
|
|
41
|
+
| `--drop COLUMN` | Remove this column from the output. Repeatable. |
|
|
42
|
+
| `--type COLUMN=TYPE` | Use this type for this column instead of the detected one, e.g. `--type col7=name`. `TYPE` can also be `regex:PATTERN` to generate values from your own pattern. Repeatable. Types are listed in [Column types](column-types.md). |
|
|
43
|
+
| `--null-value TOKEN` | Treat this exact string as a blank and leave it as is. Repeatable; replaces the default list. |
|
|
44
|
+
| `--no-null-tokens` | Treat only empty cells as blanks. `NA`, `NULL` and similar are anonymized like any other value. |
|
|
45
|
+
| `--format FORMAT` | `csv`, `json`, `jsonl` or `parquet`, when the file extension is not enough. |
|
|
46
|
+
| `--delimiter CHAR` | CSV delimiter, when auto-detection picks the wrong one. |
|
|
47
|
+
| `--profile NAME` | Start from the options saved under `[NAME]` in the config file. See [Profiles](#profiles). |
|
|
48
|
+
| `--config FILE` | Read profiles from this file instead of the default one. |
|
|
49
|
+
|
|
50
|
+
By default these strings count as blanks: `NULL`, `null`, `None`, `N/A`,
|
|
51
|
+
`n/a`, `NA`, `NaN`, `nan`, `#N/A`. Empty and whitespace-only cells always do.
|
|
52
|
+
|
|
53
|
+
## Options for `anonymize`
|
|
54
|
+
|
|
55
|
+
| Option | Meaning |
|
|
56
|
+
|---|---|
|
|
57
|
+
| `--report FILE` | Save the verification results as JSON. Contains column names, your options and counts; no cell values. |
|
|
58
|
+
| `--shuffle-rows` | Write the rows in random order. Use this when the original order itself gives something away (for example, sorted by surname). |
|
|
59
|
+
| `--preserve-order` | Numeric and date columns keep their sort order: the smallest original becomes the smallest fake, and so on. Reveals rank; off by default. |
|
|
60
|
+
| `--locale LOCALE` | Language/region for fake names and addresses, e.g. `en_GB`, `de_DE`. Default `en_US`. |
|
|
61
|
+
| `--seed N` | Produce the same output every run. For tests only; without it the operating system's secure random source is used. |
|
|
62
|
+
|
|
63
|
+
## Options for `verify`
|
|
64
|
+
|
|
65
|
+
| Option | Meaning |
|
|
66
|
+
|---|---|
|
|
67
|
+
| `--unordered` | The output was written with `--shuffle-rows`. Only per-column totals can be compared in this mode. |
|
|
68
|
+
| `--report FILE` | Save the results as JSON. |
|
|
69
|
+
|
|
70
|
+
## Profiles
|
|
71
|
+
|
|
72
|
+
A profile is a named set of options kept in a config file, so you do not have
|
|
73
|
+
to retype the same `--type`, `--drop` and `--keep` flags for files you
|
|
74
|
+
anonymize regularly. It stores option values only (column names, types,
|
|
75
|
+
flags), never data.
|
|
76
|
+
|
|
77
|
+
Save one from the flags you would otherwise pass:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
lookalike profile save customers --drop ssn --keep quantity \
|
|
81
|
+
--type col7=name --type 'employee_no=regex:EMP\d{6}'
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Then use it:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
lookalike inspect in.csv --profile customers
|
|
88
|
+
lookalike anonymize in.csv out.csv --profile customers
|
|
89
|
+
lookalike verify in.csv out.csv --profile customers
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`lookalike profile list` prints the config file in use and its profiles:
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
[customers]
|
|
96
|
+
keep = ["quantity"]
|
|
97
|
+
drop = ["ssn"]
|
|
98
|
+
|
|
99
|
+
[customers.types]
|
|
100
|
+
col7 = "name"
|
|
101
|
+
employee_no = 'regex:EMP\d{6}'
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The file is [TOML](https://toml.io) and you can write or edit it by hand.
|
|
105
|
+
Each `[NAME]` section is one profile. `profile save` only adds new profiles;
|
|
106
|
+
to change or remove one, edit the file.
|
|
107
|
+
|
|
108
|
+
| Setting | Same as | Value |
|
|
109
|
+
|---|---|---|
|
|
110
|
+
| `keep` | `--keep` | list of columns |
|
|
111
|
+
| `drop` | `--drop` | list of columns |
|
|
112
|
+
| `[NAME.types]` | `--type` | one `COLUMN = "TYPE"` line per column |
|
|
113
|
+
| `null_values` | `--null-value` | list of strings |
|
|
114
|
+
| `no_null_tokens` | `--no-null-tokens` | `true` or `false` |
|
|
115
|
+
| `format` | `--format` | string |
|
|
116
|
+
| `delimiter` | `--delimiter` | string |
|
|
117
|
+
| `locale` | `--locale` | string |
|
|
118
|
+
| `preserve_order` | `--preserve-order` | `true` or `false` |
|
|
119
|
+
| `shuffle_rows` | `--shuffle-rows` | `true` or `false` |
|
|
120
|
+
|
|
121
|
+
Notes on writing the file by hand:
|
|
122
|
+
|
|
123
|
+
- Put a column name in quotes if it has anything other than letters, digits,
|
|
124
|
+
`-` and `_` in it: `"orders[].ref" = "uuid"`.
|
|
125
|
+
- Write regex patterns in single quotes, so backslashes are taken as they
|
|
126
|
+
are: `'regex:EMP\d{6}'`.
|
|
127
|
+
- `--seed` and `--report` cannot be saved.
|
|
128
|
+
|
|
129
|
+
**Where the file lives.** The first of these is used; files are not combined:
|
|
130
|
+
|
|
131
|
+
1. the file given with `--config FILE`
|
|
132
|
+
2. the file named by the `LOOKALIKE_CONFIG` environment variable
|
|
133
|
+
3. `lookalike.toml` in the current directory
|
|
134
|
+
4. `~/.config/lookalike/config.toml` (or under `$XDG_CONFIG_HOME`)
|
|
135
|
+
|
|
136
|
+
`profile save` writes to the same file, creating number 4 if none exists. A
|
|
137
|
+
`lookalike.toml` next to your data can be committed with a project so everyone
|
|
138
|
+
uses the same options.
|
|
139
|
+
|
|
140
|
+
**Adding flags to a profile.** Flags on the command line go on top of the
|
|
141
|
+
profile:
|
|
142
|
+
|
|
143
|
+
- `--keep`, `--drop` and `--type` are added to the profile's. If a `--type`
|
|
144
|
+
on the command line and one in the profile cover the same column, the
|
|
145
|
+
command line wins, even when the profile's uses a wildcard.
|
|
146
|
+
- `--format`, `--delimiter` and `--locale` replace the profile's value.
|
|
147
|
+
- `--null-value` or `--no-null-tokens` replaces whatever the profile says
|
|
148
|
+
about nulls.
|
|
149
|
+
- A switch the profile turns on (`shuffle_rows`, `preserve_order`) cannot be
|
|
150
|
+
turned off from the command line; edit the profile or leave `--profile` out.
|
|
151
|
+
|
|
152
|
+
A profile with `shuffle_rows = true` makes `verify --profile` compare as
|
|
153
|
+
`--unordered`. Settings that do not apply to a command are ignored (for
|
|
154
|
+
example `locale` in `inspect`).
|
|
155
|
+
|
|
156
|
+
## Selecting columns
|
|
157
|
+
|
|
158
|
+
`COLUMN` in `--keep`, `--drop` and `--type` is:
|
|
159
|
+
|
|
160
|
+
- for CSV and Parquet, the column header: `--drop ssn`
|
|
161
|
+
- for JSON, the path to the field, with `.` between levels and `[]` after a
|
|
162
|
+
list: `--drop contact.email`, `--keep tags[]`, `--type orders[].ref=uuid`
|
|
163
|
+
|
|
164
|
+
Two shortcuts:
|
|
165
|
+
|
|
166
|
+
- A path also selects everything under it: `--drop contact` removes
|
|
167
|
+
`contact.email`, `contact.phones[]` and so on.
|
|
168
|
+
- `*` and `?` work as wildcards: `--drop "*_internal"`.
|
|
169
|
+
|
|
170
|
+
Run `inspect` to see the exact names. If a CSV has two columns with the same
|
|
171
|
+
header, the second is called `name#2`; a blank header is called `column_N`.
|
|
172
|
+
|
|
173
|
+
## Exit codes
|
|
174
|
+
|
|
175
|
+
| Code | Meaning |
|
|
176
|
+
|---|---|
|
|
177
|
+
| `0` | Success. For `anonymize`, the output was written and verified. |
|
|
178
|
+
| `1` | Could not run: unreadable file, unknown format, bad option value. |
|
|
179
|
+
| `2` | Verification failed (no output written), or the command line was invalid. |
|
|
180
|
+
|
|
181
|
+
## Recipes
|
|
182
|
+
|
|
183
|
+
Drop what you do not need, keep a non-sensitive measure:
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
lookalike anonymize orders.csv out.csv --drop notes --drop ssn --keep quantity
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
A column called `col7` holds people's names, but its header gives no clue, so
|
|
190
|
+
`inspect` shows it as `text`. Tell `lookalike` what it is (`COLUMN=TYPE`):
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
lookalike anonymize in.csv out.csv --type col7=name
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Employee numbers should look like `EMP` plus six digits, whatever they looked
|
|
197
|
+
like before (see [Your own pattern](column-types.md#your-own-pattern-regex)):
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
lookalike anonymize in.csv out.csv --type 'employee_no=regex:EMP\d{6}'
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
`NA` is a real country code in this file, not a blank:
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
lookalike anonymize in.csv out.csv --no-null-tokens
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Hide the row order and check the result later:
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
lookalike anonymize in.jsonl out.jsonl --shuffle-rows
|
|
213
|
+
lookalike verify in.jsonl out.jsonl --unordered
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Semicolon-separated file with a `.txt` extension:
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
lookalike anonymize export.txt out.txt --format csv --delimiter ";"
|
|
220
|
+
```
|