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)
}

# 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
  • Circular references

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.1.1.tar.gz (9.6 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.1.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for rpickle-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f498a33ca8df0506dcd130a8fa88c1ac27ba8927b4ce2fb40fa092b475419e3b
MD5 c2bb751e0580c302b3c8654ea45a661a
BLAKE2b-256 98a785ceee609aeeae6d79f6250010b0c9198520f40293408f40acedd2f58221

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rpickle-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 134d6e7c2815ab043a75879a7e5f718a9ed0a99f436bf7766945f15ea869f01d
MD5 d03ee06aafc0395c8c42e621b24334c5
BLAKE2b-256 3a63552c55b46f77a7d89a35151897d946c91941c9fa688512dfb37c71951693

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