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,strbytes,bytearraylist,tuple,set,frozensetdict,frozendict(Python 3.15+)range,sliceEllipsis,NotImplemented- Circular references
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
rpickle-0.1.0.tar.gz
(9.6 kB
view details)
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.1.0.tar.gz.
File metadata
- Download URL: rpickle-0.1.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcd538502f6202c1d64596b573e50d7697a0c01cc097ae1e5dac86e66833bedd
|
|
| MD5 |
4b9ec1f9fe5f550cc34e1ae9bbb96f9e
|
|
| BLAKE2b-256 |
a760780c4b6acd36b72e78faba89699086895455ca515a071ae8e13d1335171c
|
File details
Details for the file rpickle-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rpickle-0.1.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e680750dcd988d0fb6fdb175e5e9b37b2014fef53bd1efe04b607bfb076b883
|
|
| MD5 |
8d699e7b58fd5991c0da28a31b21dd47
|
|
| BLAKE2b-256 |
ab06304f4a6117b454e962942b7fac982a72fa426f17fd9bda60fcfbbb38c156
|