Skip to main content

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

  • pandas
  • numpy
  • cryptography >= 41.0.4
  • pyarrow >= 14.0.1

Licence

MIT

Metadata

Release files for CryptNumPy 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for CryptNumPy 0.1
File Size Uploaded
cryptnumpy-0.1.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for CryptNumPy 0.1
File Interpreter ABI Platform
cryptnumpy-0.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.6 kB

Release files / cryptnumpy-0.1.tar.gz

Download URL cryptnumpy-0.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ec846776f8e3acc1022042bd92fcced55b219854687068e095d1fcdee32f2d0f
BLAKE2b-256 checksum
How to use checksums
d3e8e9ac6485e355567378310d539eb57a6b95ca45b328b8349bc2366b11aefd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / cryptnumpy-0.1-py3-none-any.whl

Download URL cryptnumpy-0.1-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
21651b539d865c9a01a31a175365d8471a439c23785206bb05f9ea7840c30488
BLAKE2b-256 checksum
How to use checksums
092ceefffca52f57dc505171d4806b719c6c22a6d9fcc1a76ae3cf3d238c3a56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page