Pydantic Models for Redis
Typed Redis provides strongly typed, Pydantic-based models for Redis with built-in validation and serialization.
It offers an async, ORM-like API for creating, retrieving, updating, and deleting data stored in Redis.
Installation
Install with pip
pip install typed_redis
Features
- Add a schema to Redis models with validation and serialization
- Async support
- ORM-like syntax
Example
from typing import Annotated
from typed_redis import Store, RedisPrimaryKey
from redis.asyncio import Redis
redis = Redis(...)
class User(Store(redis), model_name="user"):
"""User model."""
id: Annotated[int, RedisPrimaryKey]
name: str
user = User(id=1, name="Charlie")
await user.create() # Store user object in Redis
# Later:
user = await User.get(1) # Look up by primary key value
print(user.name) # "Charlie"
Documentation
Create Store
The Store function takes in your Redis instance and returns back a base class with the ORM operations.
Create a Store:
store.py
from redis.asyncio import Redis
from typed_redis import Store as _Store
redis = Redis(...)
Store = _Store(redis)
Create Model
Using your Store object created earlier, inherit from it and set a model_name class argument to prefix your Redis keys for this model.
Annotate one field as the primary key using RedisPrimaryKey. This field value will be used as the value for the Redis key.
Note: The Redis key is derived using the model name and field value.
user.py
from typed_redis import RedisPrimaryKey
from .store import Store
class User(Store, model_name="user"):
"""User model."""
id: Annotated[int, RedisPrimaryKey]
name: str
Use Your Model
Now you can use your model:
from .user import User
# Get existing user by primary key value
user = await User.get(1)
# Create new user (idempotent)
new_user = User(id=2, name="Bob")
await new_user() # Same as calling await user.create(...)
# Update user:
await new_user.update(name="Bob Smith")
Supported Operations
| Operation | Method | Example | Notes |
|---|---|---|---|
| Create | await instance.create(**kwargs) or await instance(**kwargs) |
await user.create(ex=60) or await user(ex=60) |
Serializes with model_dump_json() and stores in Redis. Optional kwargs are passed to Redis. |
| Update | await instance.update(**changes) |
await user.update(name="Charlie Brown") |
Validates via Pydantic then persists to Redis. |
| Get | await Model.get(primary_key) |
user = await User.get(1) |
Key is derived as <model_name>:<pk>. Parses JSON using model_validate_json(...) and returns the model if it exists; otherwise, None is returned. |
| Delete | await instance.delete() |
await user.delete() |
Removes the model from Redis. No further operations are allowed after this is called. |
Notes
- Annotate exactly one field with
RedisPrimaryKey. - Bind a Redis client via
Store(redis_client)and inherit from it; otherwise, operations raise aRuntimeError. - Set the model name using the
model_nameclass argument, e.g.,class User(Store, model_name="user"):. This determines the Redis key prefix.
Metadata
Release files for typed-redis 0.0.12
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 | |
|---|---|---|---|---|
| typed_redis-0.0.12.tar.gz | 4.8 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| typed_redis-0.0.12-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.9 kB
Release files / typed_redis-0.0.12.tar.gz
| Download URL | typed_redis-0.0.12.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d60ca258f072ae8a1dcd8b4e2e5220b4b655d66b45af0bc05639c122f727370
|
|
BLAKE2b-256 checksum How to use checksums |
2d8b7ca50162a0017dc41a67e73f253266802b6e6fa74a60c738a9ec6d58877d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2025.
Transparency logRelease files / typed_redis-0.0.12-py3-none-any.whl
| Download URL | typed_redis-0.0.12-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9782d35ff3d42e7cc3566dc9549582a7a18b4f57d618b74ce124ef7464470204
|
|
BLAKE2b-256 checksum How to use checksums |
c7409a770a93f4f27c692ead7bdbceb3055c50ac53363a4903d445737fa96007
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2025.
Transparency logSecurity for typed-redis 0.0.12
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for typed_redis-0.0.12.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 10, 2025.
Transparency logA 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.