Skip to main content

A safe and efficient Python serialization library

Project description

rPickle

A safe and efficient Python serialization library.

Features

  • 🔒 Safe - No arbitrary code execution, unlike pickle
  • Fast - Optimized binary format
  • 📦 Compact - Small serialized size
  • 🔄 Circular references - Handles self-referential structures
  • 🎨 Extensible - Custom type support via extensions

Requirements

  • Python 3.15+ (preview)
  • Python 3.10+ (full)

Installation

pip install rPickle

Quick Start

import rPickle

# Serialize
data = {'name': 'Alice', 'scores': [95, 87, 92]}
packed = rPickle.dumps(data)

# Deserialize
restored = rPickle.loads(packed)
print(restored)  # {'name': 'Alice', 'scores': [95, 87, 92]}

API

Core Function

Function Description
dumps(obj) Serialize object to bytes
loads(data) Deserialize from bytes
dump(obj, file) Serialize to file
load(file) Deserialize from file

Extensions

from datetime import datetime

data = {'created': datetime.now()}
packed = rPickle.dumps(data, extensions=rPickle.datetime_ex)
restored = rPickle.loads(packed, extensions=rPickle.datetime_ex)

Custom Extensions

Add support for your own types using the extensions parameter.

from datetime import datetime

# 1. Define dump function (type → bytes)
def dump_datetime(dt: datetime) -> bytes:
    return dt.timestamp().to_bytes(8, 'little')

# 2. Define load function (bytes → type)
def load_datetime(data: bytes) -> datetime:
    timestamp = int.from_bytes(data, 'little')
    return datetime.fromtimestamp(timestamp)

# 3. Register your extension
my_extensions = {
    datetime: (load_datetime, dump_datetime)  # (load, dump), don't forget the order
}

# 4. Use it
data = {'created': datetime.now()}
packed = rPickle.dumps(data, extensions=my_extensions)
restored = rPickle.loads(packed, extensions=my_extensions)

Built-in Extensions

rPickle includes some ready-to-use extensions

Supported Types

  • None, bool, int, float, complex, str
  • bytes, bytearray
  • list, tuple, set, frozenset
  • dict, frozendict (Python 3.15+)
  • range, slice
  • Ellipsis, NotImplemented
  • Custom types

License

MIT

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

rpickle-0.2.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

rpickle-0.2.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file rpickle-0.2.0.tar.gz.

File metadata

  • Download URL: rpickle-0.2.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for rpickle-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3ee7709681910145888da0199c4501c59cd76b3e667ebcca3acc87cbc706c48b
MD5 7d5257be22011eb42fb13dabb81ae98d
BLAKE2b-256 5c7d3b9b1d3ddbbfaca7ca3f5e8bdcff48459e15304412bf760e8eaa90bfb43a

See more details on using hashes here.

File details

Details for the file rpickle-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: rpickle-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for rpickle-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f119a6362bfd23bc848075c10246d677d1611b47c312a4ec3c3d3f1dc74b4bd
MD5 afd9979726ca8633ef5d7ce1ea153e03
BLAKE2b-256 00bba7c46ffdf6989671e83c6baec58e2cee0c3a32d40fb9af34691cf4f02716

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