redis-json-serializer
Fast and secure JSON serializer for Redis caching with Pydantic and dataclass support.
Features
- 🚀 Fast: Built on top of
orjsonfor maximum performance - 🔒 Secure: Whitelist-based model registration prevents arbitrary code execution
- 📦 Type-safe: Full support for Pydantic models and dataclasses
- 🔧 Extensible: Plugin-based architecture for custom types
- 🎯 Simple: Clean API with minimal boilerplate
Installation
From PyPI (when published)
pip install redis-json-serializer
From source (development)
# Clone repository
git clone git@github.com:seligoroff/redis-json-serializer.git
cd redis-json-serializer
# Install in development mode
pip install -e ".[dev,all]"
# Or using requirements files
pip install -r requirements-dev.txt
With optional dependencies
# With Pydantic support
pip install redis-json-serializer[pydantic]
# With MongoDB ObjectId support
pip install redis-json-serializer[mongodb]
# With aiocache integration
pip install redis-json-serializer[aiocache]
# All optional dependencies
pip install redis-json-serializer[all]
Quick Start
Basic Usage
from redis_json_serializer import JsonSerializer
serializer = JsonSerializer()
# Serialize
data = {"name": "John", "age": 30, "tags": {"python", "redis"}}
packed = serializer.pack(data)
json_bytes = serializer.dumps(data)
# Deserialize
unpacked = serializer.unpack(serializer.loads(json_bytes))
With Pydantic Models
from redis_json_serializer import JsonSerializer, register_model
from pydantic import BaseModel
@register_model("user.v1") # Stable alias for versioning
class User(BaseModel):
id: str
name: str
email: str
serializer = JsonSerializer()
user = User(id="123", name="Alice", email="alice@example.com")
packed = serializer.pack(user)
unpacked = serializer.unpack(packed) # Returns User instance
With aiocache
from aiocache import cached
from aiocache.serializers import JsonSerializer
from redis_json_serializer import JsonSerializer as RedisJsonSerializer
# Configure aiocache to use our serializer
from aiocache import caches
caches.set_config({
"default": {
"cache": "aiocache.RedisCache",
"serializer": {
"class": "redis_json_serializer.aiocache.AiocacheJsonSerializer",
},
}
})
@cached(ttl=3600)
async def get_user(user_id: str) -> User:
# Your logic here
return User(id=user_id, name="Alice", email="alice@example.com")
Architecture
The library uses a dispatch-table approach for O(1) type lookup instead of chain-of-responsibility pattern, providing better performance and simpler code.
Supported Types
- Native JSON:
str,int,float,bool,None - Dates:
datetime.datetime,datetime.date - Collections:
set,list,tuple,dict - Pydantic models: With registration via
@register_model() - Dataclasses: With registration via
@register_model() - Custom types:
Decimal,ObjectId(MongoDB)
Versioning
The library supports format versioning through namespaces:
serializer = JsonSerializer(namespace="cache:v2:")
This allows safe migration between format versions without clearing the entire Redis cache.
License
MIT
Contributing
Contributions are welcome! Please read our contributing guidelines first.
Metadata
Release files for redis-json-serializer 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| redis_json_serializer-0.1.0.tar.gz | 74.2 kB | Without provenance | Details for redis_json_serializer-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| redis_json_serializer-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for redis_json_serializer-0.1.0-py3-none-any.whl |
Total release size: 88.2 kB
Release files / redis_json_serializer-0.1.0.tar.gz
| Download URL | redis_json_serializer-0.1.0.tar.gz |
|---|---|
| Size | 74.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
142d941c516cb11cf67c04a9673b36f4f6e60256f0b8d356584970fa51513c3d
|
|
BLAKE2b-256 checksum How to use checksums |
403f244ea3d0fadb1bd744d57d8dc570f183ca292d5eb82b2e9f56b79dee4ccf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Release files / redis_json_serializer-0.1.0-py3-none-any.whl
| Download URL | redis_json_serializer-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f142ec791d0444717012196da179429b5555550e1d83ebfbbce34f19204953c0
|
|
BLAKE2b-256 checksum How to use checksums |
47f83c6fedc25d4847d1053d4496b6c857d6cfc3a361f1d0eeb75c6c7a16a8b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.2
|
Security for redis-json-serializer 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.