CryptPickle allows you to easily encrypt python objects into a file and decrypt, regardless of their content. It may be any python object, including for example a Pandas DataFrame.
pip install cryptpickle
Usage example 1 (Encrypt and Decrypt a dict with some sensible data):
import cryptpickle
# Create a dictionary with some data
# It could be any other python object. ie: a Pandas Dataframe
ej1 = { 'name1': 'John Doe',
'name2': 'Lisa Doe'}
# Print the data
print(ej1)
# Serialice the data in an encrypted file with a password (file.crypt)
cryptpickle.obj_to_encrypted(ej1,password="SecretPassword",path='./file.crypt')
# Load the serialiced data in other python object. Password is needed to unencrypt the data
ej2 =cryptpickle.obj_from_encrypted(password="SecretPassword",path='./file.crypt')
# Print the data
print(ej2)
Usage example 2 (Encrypt and Decrypt a Pandas DataFrame with some sensible data):
import cryptpickle
import pandas as pd
# Create a dictionary with some data
df1 = pd.DataFrame({'A': [1, 2, 3],
'B': ['one', 'one', 'four']})
# Print the data
print(df1)
# Serialice the data in an encrypted file (path) with a password (password)
cryptpickle.obj_to_encrypted(df11,password="SecretPassword",path='./pd_data.crypt')
# Load the serialiced data in other Pandas DataFrame.
df2 =cryptpickle.obj_from_encrypted(password="SecretPassword",path='./pd_data.crypt')
# Print the data
print(df2)
- Clone this repository and enter in the directory:
git clone https://github.com/privtools/CryptPickle.git
cd CryptPickle
- Create a vitual environment:
python3 -m venv .venv
- Activate the virtual environment:
source .venv/bin/activate
- Install the package:
pip install -r requirements.txt
- Run sample1:
python sample1.py
- Run sample2:
python sample2.py