anonypyx


Nameanonypyx JSON
Version 0.2.3 PyPI version JSON
download
home_page
SummaryAnonymization library for python, fork of anonypy
upload_time2023-12-18 11:43:31
maintainer
docs_urlNone
authorquestforwisdom, glassonion1
requires_python>=3.9
licenseMIT 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.
keywords k-anonymity l-diversity t-closeness anonymization mondrian microaggregation mdav
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

**Disclaimer**: AnonyPyX does not shuffle the input data currently. In some applications, records can be re-identified based on the order in which they appear in the anonymized data set when shuffling is not used. 

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 https://github.com/questforwisdom/anonypyx.git
```

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

### 0.2.1

- minor bugfixes

## 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.


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "anonypyx",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "k-anonymity,l-diversity,t-closeness,anonymization,mondrian,microaggregation,mdav",
    "author": "questforwisdom, glassonion1",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/11/e7/f53ebfe1f86fcc54acf5f24e63da238bfab2626b62a943aa1ee1bd5e36cb/anonypyx-0.2.3.tar.gz",
    "platform": null,
    "description": "# AnonyPyx\n\nThis is a fork of the python library [AnonyPy](https://pypi.org/project/anonypy/) providing data anonymization techniques. \nAnonyPyx adds further algorithms (see below) and introduces a declarative interface.\nIf you consider migrating from AnonyPy, keep in mind that AnonyPyx is not compatible with its original API.\n\n## Features\n\n- partion-based anonymization algorithm Mondrian [1] supporting\n    - k-anonymity\n    - l-diversity \n    - t-closeness\n- microclustering based anonymization algorithm MDAV-Generic [2] supporting\n    - k-anonymity\n- interoperability with pandas data frames\n- supports both continuous and categorical attributes \n\n## Install\n\n```bash\npip install anonypyx\n```\n\n\n## Usage\n\n**Disclaimer**: AnonyPyX does not shuffle the input data currently. In some applications, records can be re-identified based on the order in which they appear in the anonymized data set when shuffling is not used. \n\nMondrian:\n\n```python\nimport anonypyx\nimport pandas as pd\n\n# Step 1: Prepare data as pandas data frame:\n\ncolumns = [\"age\", \"sex\", \"zip code\", \"diagnosis\"]\ndata = [\n    [50, \"male\", \"02139\", \"stroke\"],\n    [33, \"female\", \"10023\", \"flu\"],\n    [66, \"intersex\", \"20001\", \"flu\"],\n    [28, \"female\", \"33139\", \"diarrhea\"],\n    [92, \"male\", \"94130\", \"cancer\"],\n    [19, \"female\", \"96850\", \"diabetes\"],\n]\n\ndf = pd.DataFrame(data=data, columns=columns)\n\nfor column in (\"sex\", \"zip code\", \"diagnosis\"):\n    df[column] = df[column].astype(\"category\")\n\n# Step 2: Prepare anonymizer\n\nanonymizer = anonypyx.Anonymizer(df, k=3, l=2, algorithm=\"Mondrian\", feature_columns=[\"age\", \"sex\", \"zip code\"], sensitive_column=\"diagnosis\")\n\n# Step 3: Anonymize data (this might take a while for large data sets)\n\nanonymized_records = anonymizer.anonymize()\n\n# Print results:\n\nanonymized_df = pd.DataFrame(anonymized_records)\nprint(anonymized_df)\n```\n\nOutput: \n\n```bash\n     age            sex           zip code diagnosis  count\n0  19-33         female  10023,33139,96850  diabetes      1\n1  19-33         female  10023,33139,96850  diarrhea      1\n2  19-33         female  10023,33139,96850       flu      1\n3  50-92  male,intersex  02139,20001,94130    cancer      1\n4  50-92  male,intersex  02139,20001,94130       flu      1\n5  50-92  male,intersex  02139,20001,94130    stroke      1\n```\n\nMDAV-generic\n\n```python\n# Step 2: Prepare anonymizer\nanonymizer = anonypyx.Anonymizer(df, k=3, algorithm=\"MDAV-generic\", feature_columns=[\"age\", \"sex\", \"zip code\"], sensitive_column=\"diagnosis\")\n```\n\n## Contributing\n\nClone the repository:\n\n```bash\ngit clone https://github.com/questforwisdom/anonypyx.git\n```\n\nSet a virtual python environment up and install dependencies:\n\n```bash\npython -m venv venv\nsource venv/bin/activate\npip install -r requirements.txt\n```\n\nRun tests:\n\n```bash\npytest\n```\n\n## Changelog\n\n### 0.2.0\n\n- added the microaggregation algorithm MDAV-generic [2]\n- added the Anonymizer class as the new API \n- removed Preserver class which was superseded by Anonymizer\n\n### 0.2.1\n\n- minor bugfixes\n\n## References\n\n- [1]: LeFevre, K., DeWitt, D. J., & Ramakrishnan, R. (2006). Mondrian multidimensional K-anonymity. 22nd International Conference on Data Engineering (ICDE\u201906), 25\u201325. https://doi.org/10.1109/ICDE.2006.101\n- [2]: Domingo-Ferrer, J., & Torra, V. (2005). Ordinal, continuous and heterogeneous k-anonymity through microaggregation. Data Mining and Knowledge Discovery, 11, 195\u2013212.\n\n",
    "bugtrack_url": null,
    "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. ",
    "summary": "Anonymization library for python, fork of anonypy",
    "version": "0.2.3",
    "project_urls": {
        "Homepage": "https://github.com/questforwisdom/anonypyx"
    },
    "split_keywords": [
        "k-anonymity",
        "l-diversity",
        "t-closeness",
        "anonymization",
        "mondrian",
        "microaggregation",
        "mdav"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a26247e9d68f7666660ce1abc9dfd033321bf8b4a573aa9ac55278364b84f33f",
                "md5": "d48752786ec11ca15a6ca611c012a770",
                "sha256": "160b88d9a66c571272d2a865a9a5036a40f75b236faccbc97e6a419be1f7da77"
            },
            "downloads": -1,
            "filename": "anonypyx-0.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d48752786ec11ca15a6ca611c012a770",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 10843,
            "upload_time": "2023-12-18T11:43:30",
            "upload_time_iso_8601": "2023-12-18T11:43:30.062634Z",
            "url": "https://files.pythonhosted.org/packages/a2/62/47e9d68f7666660ce1abc9dfd033321bf8b4a573aa9ac55278364b84f33f/anonypyx-0.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "11e7f53ebfe1f86fcc54acf5f24e63da238bfab2626b62a943aa1ee1bd5e36cb",
                "md5": "89377c8ed8453a935d051ef9190aa30b",
                "sha256": "84736343edef7651630991bd23ea03ee2d3cc617a9193b79788e1c3ebf9c8fb6"
            },
            "downloads": -1,
            "filename": "anonypyx-0.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "89377c8ed8453a935d051ef9190aa30b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 14349,
            "upload_time": "2023-12-18T11:43:31",
            "upload_time_iso_8601": "2023-12-18T11:43:31.102732Z",
            "url": "https://files.pythonhosted.org/packages/11/e7/f53ebfe1f86fcc54acf5f24e63da238bfab2626b62a943aa1ee1bd5e36cb/anonypyx-0.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-18 11:43:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "questforwisdom",
    "github_project": "anonypyx",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "anonypyx"
}
        
Elapsed time: 1.04603s