Skip to main content

Package for signing and verifying pickle files

Project description

pylotte

Secure Pickle Serialization with RSA Signatures

pylotte is a lightweight Python utility that allows you to securely serialize Python objects with RSA digital signatures. It ensures the integrity and authenticity of your data by cryptographically signing serialized files and verifying them before loading.


✨ Features

  • 🔐 Sign serialized files using an RSA private key
  • ✅ Verify signatures with the corresponding public key
  • 🛡️ Prevents tampering and ensures data authenticity
  • 📦 Simple and minimal interface
  • 🔄 Pluggable serializer: use pickle, dill, cloudpickle, or any dump/load API

📦 Installation

Install directly from PyPI:

# Basic installation with pickle support
pip install pylotte

# With dill support for advanced serialization
pip install pylotte[dill]

🛠 Usage

Basic Usage with Pickle

from pylotte.signed_pickle import SignedPickle

# Initialize with RSA key paths
signer = SignedPickle(public_key_path="public.pem", private_key_path="private.pem")

# Data to serialize
data = {"user": "alice", "role": "admin"}

# Securely dump and sign the pickle file
signer.dump_and_sign(data, "data.pkl", "data.sig")

# Load and verify the signed pickle file
loader = SignedPickle(public_key_path="public.pem")
data_loaded = loader.safe_load("data.pkl", "data.sig")

Advanced Usage with a Custom Serializer

from pylotte.signed_pickle import SignedPickle
import cloudpickle  # or dill, or any module with dump/load

signer = SignedPickle(
    public_key_path="public.pem",
    private_key_path="private.pem",
    serializer=cloudpickle,
)

data = {
    "name": "bob",
    "process": lambda x: x * 2,
    "nested": {"func": lambda y: y + 1},
}

signer.dump_and_sign(data, "data.pkl", "data.sig")

loader = SignedPickle(public_key_path="public.pem", serializer=cloudpickle)
data_loaded = loader.safe_load("data.pkl", "data.sig")

result = data_loaded["process"](5)  # Returns 10

Using a Custom Serializer (e.g., cloudpickle)

from pylotte.signed_pickle import SignedPickle
import cloudpickle

# Pass any object that provides dump/load
signer = SignedPickle(
    public_key_path="public.pem",
    private_key_path="private.pem",
    serializer=cloudpickle,
)

data = {"callable": lambda x: x + 3}
signer.dump_and_sign(data, "data.pkl", "data.sig")

loader = SignedPickle(public_key_path="public.pem", serializer=cloudpickle)
loaded = loader.safe_load("data.pkl", "data.sig")

🔐 How It Works

  • dump_and_sign():

    • Serializes your data using the provided serializer (defaults to pickle) and saves it to a file.
    • Signs the file contents using an RSA private key.
    • Stores the signature in a separate .sig file.
  • safe_load():

    • Reads the serialized file and its signature.
    • Verifies the signature using the RSA public key.
    • If valid, loads and returns the original data.

🔧 Requirements


📄 License

This project is licensed under the MIT License.


🌐 Links


👤 Author

Developed by Alpamayo Solutions

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

pylotte-0.3.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

pylotte-0.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file pylotte-0.3.tar.gz.

File metadata

  • Download URL: pylotte-0.3.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for pylotte-0.3.tar.gz
Algorithm Hash digest
SHA256 f123fdd23cd7df0845a1df43e6a92357d3d070c08d619b69651b532f18f8beb1
MD5 bd03ee1f3497333ac133ba5e5ca7676a
BLAKE2b-256 3b2d1de404f980c9089a804cd075ffac16a39c1a68ea0f1d8f3a16a788d637c2

See more details on using hashes here.

File details

Details for the file pylotte-0.3-py3-none-any.whl.

File metadata

  • Download URL: pylotte-0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for pylotte-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5884bf2b9846eb87e646ae35233587e32c1cc8513a90d54702f427469e2392fa
MD5 a176893bb69dbaf41f21f94a51eb3f9b
BLAKE2b-256 628049ceb6b362fecab0027e160040d6e551504f5ceab6191a19cc85bae3ad8d

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