Library to anonymize JSON objects by creating placeholders for keys and values, while generating a reversible mapping to restore afterwards
Project description
Prompt-Horizon
Prompt-Horizon is a Python library that enables developers to anonymize JSON objects by creating placeholders for keys and values, while generating a reversible mapping to restore the original JSON data. The purpose of this library is to facilitate data sharing while preserving privacy and allowing for the de-anonymization of the data when required.
Note: I had the idea for this library when I was trying to find a way to obfuscate data objects such as JSON to include them as contextual information in prompts (hence the name).
Prompt-Horizon is not designed to specifically identify and anonymize PII (personally identifiable information) or other sensitive data within the JSON objects.
Installation
pip install prompt-horizon
Usage
Anonymize JSON
from prompt_horizon import anonymize
input_json = {
"name": "John",
"age": 30,
"city": "New York",
"favorites": ["pizza", "basketball"]
}
#This line will return the anonymized JSON object and the mapping object.
anonymized_json, map_object = anonymize(input_json)
Original JSON:
{
"name": "John",
"age": 30,
"city": "New York",
"favorites": ["pizza", "basketball"]
}
Anonymized JSON:
{
"a1": "a2",
"a3": "a4",
"a5": "a6",
"a7": ["a8", "a9"]
}
input and output file handling is supported
from prompt_horizon import anonymize_from_file
#This line will read the JSON data from "input.json", anonymize it, and save the anonymized JSON to "anonymized.json".
anonymized_json, map_object = anonymize_from_file("input.json", output_file_path="anonymized.json")
De-anonymize JSON
from prompt_horizon import de_anonymize
#This line will return the de-anonymized JSON object, which should be the same as the original input JSON.
deanonymized_json = de_anonymize(anonymized_json, map_object=map_object)
input and output files are supported
from prompt_horizon import de_anonymize_from_file
#This will read the anonymized JSON data from "anonymized.json", the mapping object from "map_file.json", de-anonymize the JSON data, and save the de-anonymized JSON to "deanonymized.json".
deanonymized_json = de_anonymize_from_file("anonymized.json", map_file_path="map_file.json", output_file_path="deanonymized.json")
Saving and loading the map
You can also save the generated mapping object to a file and load it later for de-anonymization.
from prompt_horizon import save_map, load_map
# Save the map object to a file
save_map(map_object, "map_file.json")
# Load the map object from a file
loaded_map_object = load_map("map_file.json")
Then, use the loaded map object to de-anonymize the JSON data:
deanonymized_json = de_anonymize(anonymized_json, map_object=loaded_map_object)
License
This project is licensed under the MIT License.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prompt-horizon-0.1.1.tar.gz.
File metadata
- Download URL: prompt-horizon-0.1.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
13e94bf12f652a52517b6363886c6aac67f47696961301e40c3a30b4b8ed871b
|
|
| MD5 |
cda2ea3db70c0bb263f4b3b0fa721a1f
|
|
| BLAKE2b-256 |
79851089454766b7969e0cc5fc14cc177bf6044aeb92aeb93abc032c3b486b7b
|
File details
Details for the file prompt_horizon-0.1.1-py3-none-any.whl.
File metadata
- Download URL: prompt_horizon-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
340626278d84b9f6243851a465439e2768471618ed2ebeb158fa60e050eb2395
|
|
| MD5 |
30206dc6e9e93f14b4842c0dbe53c335
|
|
| BLAKE2b-256 |
304b5109a99b6c2366b380a33f5c82178486d83480e2ab704b585df844599966
|