Skip to main content

Convenience functions for symetrically encrypting/decrypting huggingface Datasets

Project description

Installation

pip install encrypted-datasets

Usage

Raw string key

from datasets import load_dataset
from encrypted_datasets import encrypt_dataset, decrypt_dataset

huggingface_api_token = 'API_TOKEN'
downloaded_dataset = load_dataset('organization/dataset_repo', token=huggingface_api_token)
key = 'Your Symetric encryption key'

decrypted_dataset = decrypt_dataset(downloaded_dataset, key)

# Make modifications to decrypted_dataset...

re_encrypted_dataset = encrypt_dataset(decrypted_dataset, key)

re_encrypted_dataset.push_to_hub('organization/dataset_repo',token=huggingface_api_token)

AWS Key management service key

In this method, you use an AWS KMS key to encrypt data keys that are stored in huggingface with the data.

Create new encryped dataset and upload it to huggingface hub

from encrypted_datasets import EncryptedDataset, KMSCypher
import boto3

kms_client = boto3.client('kms')
kms_key_id = '<KMS_KEY_ID>'

cypher = KMSCypher(
    key_id=kms_key_id,
    client=client
)

dataset = Dataset.from_pandas(...)

encrypted_dataset = EncryptedDataset.encrypt(dataset, cypher)

encrypted_dataset.push_to_hub('organization/repo_id', token='<ACCESS_TOKEN>')

Load encrypted dataset, modify it, and reupload

from encrypted_datasets import EncryptedDataset, KMSCypher
import boto3

kms_client = boto3.client('kms')
kms_key_id = '<KMS_KEY_ID>'
hf_token= '<HF_TOKEN>'

cypher = KMSCypher(
    key_id=kms_key_id,
    client=client
)

encrypted_dataset = EncryptedDataset.load('organization/repo_id', token=hf_token)

dataset = encrypted_dataset.decrypt(cypher)

# Make modifications to dataset...


new_encrypted_dataset = EncryptedDataset.encrypt(dataset, cypher)

new_encrypted_dataset.push_to_hub('organization/repo_id', token=hf_token)

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

encrypted_datasets-1.0.12.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

encrypted_datasets-1.0.12-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file encrypted_datasets-1.0.12.tar.gz.

File metadata

  • Download URL: encrypted_datasets-1.0.12.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/24.3.0

File hashes

Hashes for encrypted_datasets-1.0.12.tar.gz
Algorithm Hash digest
SHA256 ea9c8e0631e4cd422b9d2f1691944c7b3a0beffab386d5355d2eba38414f8c8a
MD5 4d1dc414b1bf71f6631d85ef2e90d2ff
BLAKE2b-256 cb4eec34bdce6924630d1311222086530dc24b62035b49c0ac98259ae7eb033e

See more details on using hashes here.

File details

Details for the file encrypted_datasets-1.0.12-py3-none-any.whl.

File metadata

File hashes

Hashes for encrypted_datasets-1.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 fad463525aeb6436888bbc0596fb4787ed41a3335ff1b542c41af2138653e5d7
MD5 bf5ba6d793b968b211379b0355129d30
BLAKE2b-256 babe4dac30c1c46706606982ec0f234c33361de8397acb0e2499d70ac4d7c96c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page