A tool for encryption and decryption of numpy arrays and pandas dataframes. Port of `cryptpandas`.
Project description
About
This project is a port of Luca Mingarelli's cryptpandas package and allows users to easily encrypt and decrypt numpy arrays in addition to pandas dataframes.
Installation
You can install cryptnumpy with pip:
pip install cryptnumpy
NumPy example
You can encrypt and decrypt a single numpy array as follows:
import numpy as np
import cryptnumpy as crp
my_array = np.arange(10)
crp.to_encrypted(my_array, password='APassWord', path='file.crypt')
decrypted_array = crp.read_encrypted('file.crypt', password='APassWord')
print(np.all(my_array == decrypted_array))
A dictionary of numpy arrays works just the same:
import numpy as np
import cryptnumpy as crp
my_array_dict = dict(
arry1=np.array(['foo', 'bar', 'baz']),
arry2=np.array(['qux', 'quux'])
)
crp.to_encrypted(my_array_dict, password='APassWord', path='file.crypt')
decrypted_dict = crp.read_encrypted('file.crypt', password='APassWord')
for name, original_array in my_array_dict.items():
decrypted_array = decrypted_dict[name]
print(np.all(original_array == decrypted_array))
Pandas example
For convenience, cryptnumpy maintains the original functionality of Luca Mingarelli's cryptpandas package.
Specifically, you can encrypt and decrypt a pandas dataframe as follows:
import pandas as pd
import cryptnumpy as crp
my_df = pd.DataFrame(
{'A': [1, 2, 3],
'B': ['foo', 'bar', 'baz']
}
)
crp.to_encrypted(my_df, password='somePassword', path='file.crypt')
decrpyted_df = crp.read_encrypted(
'file.crypt',
password='somePassword',
use_pandas=True
)
print(decrpyted_df.equals(my_df))
By default, the read_encrypted function will assume that your encrypted data is a numpy array.
To load an encrypted dataframe instead, you need to set use_pandas=True (see above).
If you are only looking to encrypt and decrypt dataframes, and do not need support for
numpy arrays, you should install the original cryptpandas package. cryptnumpy will not offer
you any additional functionalities in that case.
Requirements
pandasnumpycryptography >= 41.0.4pyarrow >= 14.0.1
Licence
Project details
Release history Release notifications | RSS feed
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 cryptnumpy-0.1.tar.gz.
File metadata
- Download URL: cryptnumpy-0.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec846776f8e3acc1022042bd92fcced55b219854687068e095d1fcdee32f2d0f
|
|
| MD5 |
da8b2da4e949103115ec7e102cbbe8c5
|
|
| BLAKE2b-256 |
d3e8e9ac6485e355567378310d539eb57a6b95ca45b328b8349bc2366b11aefd
|
File details
Details for the file cryptnumpy-0.1-py3-none-any.whl.
File metadata
- Download URL: cryptnumpy-0.1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21651b539d865c9a01a31a175365d8471a439c23785206bb05f9ea7840c30488
|
|
| MD5 |
2ec6192098f4bd9824d60ea91d7770b2
|
|
| BLAKE2b-256 |
092ceefffca52f57dc505171d4806b719c6c22a6d9fcc1a76ae3cf3d238c3a56
|