Skip to main content

Encrypted python object serialization

Project description

CryptPickle

Encrypted python object serialization

python python Downloads Issues Test

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.

Migration from v0.x

Breaking change: CryptPickle 1.0 changes the encryption format from AES-ZIP (pyzipper) to AES-256-GCM with PBKDF2 (cryptography). Files created with versions prior to 1.0 are not readable with this version.

To migrate existing data: decrypt with CryptPickle 0.9, then re-encrypt with CryptPickle 1.0.

Install

pip install cryptpickle

Examples

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(df1,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)

Install and try it (Linux)

  1. Clone this repository and enter in the directory:
git clone https://github.com/privtools/CryptPickle.git
cd CryptPickle
  1. Create a vitual environment:
python3 -m venv .venv
  1. Activate the virtual environment:
source .venv/bin/activate
  1. Install the package:
pip install -r requirements.txt
  1. Run sample1:
python sample1.py
  1. Run sample2:
python sample2.py

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

cryptpickle-1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

cryptpickle-1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file cryptpickle-1.0.tar.gz.

File metadata

  • Download URL: cryptpickle-1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for cryptpickle-1.0.tar.gz
Algorithm Hash digest
SHA256 cd7f215a7cf6640b9525deca6e6499828801390bbfa5850acf7d42bfa111c65a
MD5 5c86cffd219ab83d66891628bb8ff522
BLAKE2b-256 cf2fbb7cc3fed261a993d888d9550b2f83cfccc58674a3aedb4a84f20b70e85b

See more details on using hashes here.

File details

Details for the file cryptpickle-1.0-py3-none-any.whl.

File metadata

  • Download URL: cryptpickle-1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for cryptpickle-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3205dfd651e90d475865109c127624efbc530fb8afcb77500a145d32ddba07f1
MD5 7d208717747a4f6d6b964697ed26e90a
BLAKE2b-256 bb93478f655caf7326b5f90ce12b43b71b5b72e65d1e441457d23d5a259d9c95

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