{"id":15440518,"url":"https://github.com/glassonion1/anonypy","last_synced_at":"2025-04-13T01:21:28.222Z","repository":{"id":50464380,"uuid":"417773255","full_name":"glassonion1/anonypy","owner":"glassonion1","description":"Anonymization library for python. Protect the privacy of individuals.","archived":false,"fork":false,"pushed_at":"2024-09-21T00:19:26.000Z","size":1372,"stargazers_count":27,"open_issues_count":3,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T05:50:00.532Z","etag":null,"topics":["k-anonymity","l-diversity","mondrian","pandas","python","python3","t-closeness"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/glassonion1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-16T09:01:02.000Z","updated_at":"2025-03-09T04:17:29.000Z","dependencies_parsed_at":"2024-10-31T16:01:54.408Z","dependency_job_id":"d44c8f62-b2f4-448c-bb47-4fc93d7b4bcc","html_url":"https://github.com/glassonion1/anonypy","commit_stats":{"total_commits":21,"total_committers":4,"mean_commits":5.25,"dds":"0.47619047619047616","last_synced_commit":"2a172285958e7697dc42fd4fde6cfd89cf104e6d"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassonion1%2Fanonypy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassonion1%2Fanonypy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassonion1%2Fanonypy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/glassonion1%2Fanonypy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/glassonion1","download_url":"https://codeload.github.com/glassonion1/anonypy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248651181,"owners_count":21139771,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["k-anonymity","l-diversity","mondrian","pandas","python","python3","t-closeness"],"created_at":"2024-10-01T19:13:55.950Z","updated_at":"2025-04-13T01:21:28.161Z","avatar_url":"https://github.com/glassonion1.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AnonyPy\nAnonymization library for python.\nAnonyPy provides following privacy preserving techniques for the anonymization.\n- K Anonymity\n- L Diversity\n- T Closeness\n\n## The Anonymization method\n- Anonymization method aims at making the individual record be indistinguishable among a group record by using techniques of generalization and suppression.\n- Turning a dataset into a k-anonymous (and possibly l-diverse or t-close) dataset is a complex problem, and finding the optimal partition into k-anonymous groups is an NP-hard problem.\n- AnonyPy uses \"Mondrian\" algorithm to partition the original data into smaller and smaller groups\n- The algorithm assumes that we have converted all attributes into numerical or categorical values and that we are able to measure the “span” of a given attribute Xi.\n\n## Install\n```\n$ pip install anonypy\n```\n\n## Usage\n```python\nimport anonypy\nimport pandas as pd\n\ndata = [\n    [6, \"1\", \"test1\", \"x\", 20],\n    [6, \"1\", \"test1\", \"x\", 30],\n    [8, \"2\", \"test2\", \"x\", 50],\n    [8, \"2\", \"test3\", \"w\", 45],\n    [8, \"1\", \"test2\", \"y\", 35],\n    [4, \"2\", \"test3\", \"y\", 20],\n    [4, \"1\", \"test3\", \"y\", 20],\n    [2, \"1\", \"test3\", \"z\", 22],\n    [2, \"2\", \"test3\", \"y\", 32],\n]\n\ncolumns = [\"col1\", \"col2\", \"col3\", \"col4\", \"col5\"]\ncategorical = set((\"col2\", \"col3\", \"col4\"))\n\ndf = pd.DataFrame(data=data, columns=columns)\n\nfor name in categorical:\n  df[name] = df[name].astype(\"category\")\n\nfeature_columns = [\"col1\", \"col2\", \"col3\"]\nsensitive_column = \"col4\"\n\np = anonypy.Preserver(df, feature_columns, sensitive_column)\nrows = p.anonymize_k_anonymity(k=2)\n\ndfn = pd.DataFrame(rows)\nprint(dfn)\n```\n\nOriginal data\n```bash\n   col1 col2   col3 col4  col5\n0     6    1  test1    x    20\n1     6    1  test1    x    30\n2     8    2  test2    x    50\n3     8    2  test3    w    45\n4     8    1  test2    y    35\n5     4    2  test3    y    20\n6     4    1  test3    y    20\n7     2    1  test3    z    22\n8     2    2  test3    y    32\n```\n\nThe created anonymized data is below(Guarantee 2-anonymity).\n```bash\n  col1 col2         col3 col4  count\n0  2-4    2        test3    y      2\n1  2-4    1        test3    y      1\n2  2-4    1        test3    z      1\n3  6-8    1  test1,test2    x      2\n4  6-8    1  test1,test2    y      1\n5    8    2  test3,test2    w      1\n6    8    2  test3,test2    x      1\n```\n\n## Publish PyPI\n```\n$ python -m pip install hatchling wheel twine\n$ python -m build --wheel .\n$ python -m twine upload dist/*\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglassonion1%2Fanonypy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglassonion1%2Fanonypy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglassonion1%2Fanonypy/lists"}