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.11+ (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,strbytes,bytearraylist,tuple,set,frozensetdict,frozendict(Python 3.15+)range,sliceEllipsis,NotImplementedsentinel(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 |
Path_ext |
pathlib.Path |
defaultdict_ext |
collections.defaultdict |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rpickle-0.5.0.tar.gz.
File metadata
- Download URL: rpickle-0.5.0.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efe811d9ee0cc5b8d3995d5a9b0171e67ce1ba74cfc3e776c45f41f1c5805521
|
|
| MD5 |
c7a240de4d622c8e853a3451c9a4c190
|
|
| BLAKE2b-256 |
878d9cdb0d4652c677e38eb5d0be2f9c01e682b79ae89ec3268c073188f53bdb
|
File details
Details for the file rpickle-0.5.0-py3-none-any.whl.
File metadata
- Download URL: rpickle-0.5.0-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9dda93f3a7f0d51a129d172e603e917d7737d16cdca8199ff0a03f62b96fe2c
|
|
| MD5 |
9bf3fc15ae67e5cbfa0c58cf4d734d57
|
|
| BLAKE2b-256 |
c578a482c5b588814356c2d0d2eb1ae9cd94247eb3b750ccc52b0279c5ab9106
|