Metadata-Version: 2.1
Name: anonypyx
Version: 0.2.0
Summary: Anonymization library for python, fork of anonypy
Author-email: abyssexplorer <abyssexplorer2@gmail.com>, glassonion1 <glassonion999@gmail.com>
License: MIT License
        
        Copyright (c) 2021 Taisuke Fujita
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/abyssexplorer/anonypyx
Keywords: k-anonymity,l-diversity,t-closeness,anonymization,mondrian,microaggregation,mdav
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pandas>=1.1.0
Requires-Dist: numpy>=1.21.3
Requires-Dist: scikit-learn>=1.0.1
Requires-Dist: scipy>=1.11.3
Requires-Dist: category_encoders>=2.3.0
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"

# AnonyPyx

This is a fork of the python library [AnonyPy](https://pypi.org/project/anonypy/) providing data anonymization techniques. 
AnonyPyx adds further algorithms (see below) and introduces a declarative interface.
If you consider migrating from AnonyPy, keep in mind that AnonyPyx is not compatible with its original API.

## Features

- partion-based anonymization algorithm Mondrian [1] supporting
    - k-anonymity
    - l-diversity 
    - t-closeness
- microclustering based anonymization algorithm MDAV-Generic [2] supporting
    - k-anonymity
- interoperability with pandas data frames
- supports both continuous and categorical attributes 

## Install

```bash
pip install anonypyx
```


## Usage

Mondrian:

```python
import anonypyx
import pandas as pd

# Step 1: Prepare data as pandas data frame:

columns = ["age", "sex", "zip code", "diagnosis"]
data = [
    [50, "male", "02139", "stroke"],
    [33, "female", "10023", "flu"],
    [66, "intersex", "20001", "flu"],
    [28, "female", "33139", "diarrhea"],
    [92, "male", "94130", "cancer"],
    [19, "female", "96850", "diabetes"],
]

df = pd.DataFrame(data=data, columns=columns)

for column in ("sex", "zip code", "diagnosis"):
    df[column] = df[column].astype("category")

# Step 2: Prepare anonymizer

anonymizer = anonypyx.Anonymizer(df, k=3, l=2, algorithm="Mondrian", feature_columns=["age", "sex", "zip code"], sensitive_column="diagnosis")

# Step 3: Anonymize data (this might take a while for large data sets)

anonymized_records = anonymizer.anonymize()

# Print results:

anonymized_df = pd.DataFrame(anonymized_records)
print(anonymized_df)
```

Output: 

```bash
     age            sex           zip code diagnosis  count
0  19-33         female  10023,33139,96850  diabetes      1
1  19-33         female  10023,33139,96850  diarrhea      1
2  19-33         female  10023,33139,96850       flu      1
3  50-92  male,intersex  02139,20001,94130    cancer      1
4  50-92  male,intersex  02139,20001,94130       flu      1
5  50-92  male,intersex  02139,20001,94130    stroke      1
```

MDAV-generic

```python
# Step 2: Prepare anonymizer
anonymizer = anonypyx.Anonymizer(df, k=3, algorithm="MDAV-generic", feature_columns=["age", "sex", "zip code"], sensitive_column="diagnosis")
```

## Contributing

Clone the repository:

```bash
git clone TODO
```

Set a virtual python environment up and install dependencies:

```bash
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

Run tests:

```bash
pytest
```

## Changelog

### 0.2.0

- added the microaggregation algorithm MDAV-generic [2]
- added the Anonymizer class as the new API 
- removed Preserver class which was superseded by Anonymizer

## References

- [1]: LeFevre, K., DeWitt, D. J., & Ramakrishnan, R. (2006). Mondrian multidimensional K-anonymity. 22nd International Conference on Data Engineering (ICDE’06), 25–25. https://doi.org/10.1109/ICDE.2006.101
- [2]: Domingo-Ferrer, J., & Torra, V. (2005). Ordinal, continuous and heterogeneous k-anonymity through microaggregation. Data Mining and Knowledge Discovery, 11, 195–212.

