pip install datasafe
git clone --depth 1 https://github.com/StephenRicher/datasafe.git
cd datasafe/
docker build -t datasafe .
docker run datasafe --help
datasafe encrypt data.csv > data.encrypted
datasafe decrypt data.encrypted > data.decrypted.csv
datasafe
can be imported as a python module to encrypt and decrypt files.
If a Pandas DataFrame is provided to datasafe.encrypt
then it will be encrypted in .parquet
format.
Following decryption, an in-memory buffer is returned which should be passed to pd.read_parquet
to recover the dataframe and datatypes.
import pandas as pd
from datasafe import encrypt, decrypt
df = pd.DataFrame({
'A': [1, 2, 3],
'B': ['dog', 'cat', 'bat']
})
encrypt(df, 'df-encrypted.pq')
df = pd.read_parquet(decrypt('df-encrypted.pq'))
The command line functionality can also be achieved within Python.
In addition the datasafe.decrypt
function returns an in-memory buffer which can be read directly.
import pandas as pd
from datasafe import encrypt, decrypt
with open('data.encrypted', 'wb') as fh:
fh.write(encrypt('data.csv'))
with open('data.decrypted.csv', 'w') as fh:
fh.write(decrypt('data.encrypted').getvalue())
df = pd.read_csv(decrypt('data.encrypted'))
Distributed under the MIT License. See LICENSE for more information.
If you have any other questions please contact the author Stephen Richer at [email protected]