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.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)
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- Custom types
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.3.0.tar.gz
(10.4 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.3.0.tar.gz.
File metadata
- Download URL: rpickle-0.3.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c6f686b9f0a556360e0616c79f27601e02de858077197daa07d5712375d14b0
|
|
| MD5 |
9a420fb807b3c6192d14655cb5789c2e
|
|
| BLAKE2b-256 |
1210257e5b8e9084fb7b5071ccd06e6cb469339bc8280500d8ec8bda16facfdd
|
File details
Details for the file rpickle-0.3.0-py3-none-any.whl.
File metadata
- Download URL: rpickle-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.1 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 |
5f797be90cd6e7860cba912c66396ef5356799bfd6b3646f4d50480b171b633d
|
|
| MD5 |
8ae01f3997b4b5a051802cc75d313cb5
|
|
| BLAKE2b-256 |
449607d82582d8178b8956142db225e424b77af34e27bca7cabd38748a88982b
|