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

🔒 Safety

rPickle is safe in the sense that it does not execute arbitrary code during deserialization.

Unlike pickle (which can call arbitrary functions during loads()), rPickle only reconstructs data structures.
It does not use __reduce__(), no implicit imports, and no function calls.

rPickle.loads(data) does not execute any code — it only restores data.
pickle.loads(data) may execute arbitrary code defined in __reduce__.

However, safety is not absolute:

  • If you use custom extensions (Extension), you are responsible for the code you provide — the library author is not liable.
  • rPickle does not encrypt data or prevent tampering. If you need integrity or confidentiality, take additional measures.

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.ext.datetime_ext)
restored = rPickle.loads(packed, extensions=rPickle.ext.datetime_ext)

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 = rPickle.ext.Extension(typ=datetime, load_func=load_datetime, dump_func=dump_datetime)

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

Supported Types

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

Built-in Extensions

rPickle comes with ready-to-use extensions for common types: see the list below.

Name Type
datetime_ext datetime.datetime
Decimal_ext decimal.Decimal
UUID_ext uuid.UUID
Fraction_ext fractions.Fraction

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.4.0.tar.gz (13.0 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.4.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for rpickle-0.4.0.tar.gz
Algorithm Hash digest
SHA256 e50a4fdce9d0ecb4e11cdeb62bd7ecc4c5851aa29306ac87247db8312d8ae519
MD5 74e2ea4bdca297bec4db1b4470d420b2
BLAKE2b-256 ad76ddf068f08c6d12ee4d268a290616191882b33e8cf752e5056e48438da508

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rpickle-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 74ff6201d82d7752f627d2a0015ddf51bf91033d0b680c377d92dfc70484e0b8
MD5 2159449e082547eb0fc53552b86e27dd
BLAKE2b-256 493f311209bf9fe521aeb0c6dcb4d7d76e42a5186cbecf99b78981e174d810c3

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