Skip to main content

Pydantic models with Redis as the backend

Project description

Rapyer Logo

Rapyer

Redis Atomic Pydantic Engine Reactor

An async Redis ORM that provides atomic operations for complex data models

Python 3.10+ License: MIT Redis

📚 Full Documentation | Installation | Examples | API Reference


What is Rapyer?

Rapyer (Redis Atomic Pydantic Engine Reactor) is a modern async Redis ORM that enables atomic operations on complex data models. Built with Pydantic v2, it provides type-safe Redis interactions while maintaining data consistency and preventing race conditions.

Key Features

🚀 Atomic Operations - Built-in atomic updates for complex Redis data structures
Async/Await - Full asyncio support for high-performance applications
🔒 Type Safety - Complete type validation using Pydantic v2
🌐 Universal Types - Native optimization for primitives, automatic serialization for complex types
🔄 Race Condition Safe - Lock context managers and pipeline operations
📦 Redis JSON - Efficient storage using Redis JSON with support for nested structures

Installation

pip install rapyer

Requirements:

  • Python 3.10+
  • Redis server with JSON module
  • Pydantic v2

Quick Start

import asyncio
from rapyer.base import AtomicRedisModel
from typing import List, Dict

class User(AtomicRedisModel):
    name: str
    age: int
    tags: List[str] = []
    metadata: Dict[str, str] = {}

async def main():
    # Create and save a user
    user = User(name="John", age=30)
    await user.save()

    # Atomic operations that prevent race conditions
    await user.tags.aappend("python")
    await user.tags.aextend(["redis", "pydantic"])
    await user.metadata.aupdate(role="developer", level="senior")

    # Load user from Redis
    loaded_user = await User.get(user.key)
    print(f"User: {loaded_user.name}, Tags: {loaded_user.tags}")

    # Atomic operations with locks for complex updates
    async with user.lock("update_profile") as locked_user:
        locked_user.age += 1
        await locked_user.tags.aappend("experienced")
        # Changes saved atomically when context exits

if __name__ == "__main__":
    asyncio.run(main())

Core Concepts

Atomic Operations

Rapyer ensures data consistency with built-in atomic operations:

# These operations are atomic and race-condition safe
await user.tags.aappend("python")           # Add to list
await user.metadata.aupdate(role="dev")     # Update dict
await user.score.set(100)                   # Set value

Lock Context Manager

For complex multi-field updates:

async with user.lock("transaction") as locked_user:
    locked_user.balance -= 50
    locked_user.transaction_count += 1
    # All changes saved atomically

Pipeline Operations

Batch multiple operations for performance:

async with user.pipeline() as pipelined_user:
    await pipelined_user.tags.aappend("redis")
    await pipelined_user.metadata.aupdate(level="senior")
    # Executed as single atomic transaction

Type Support

Rapyer supports all Python types with automatic serialization:

  • Native types (str, int, List, Dict) - Optimized Redis operations
  • Complex types (dataclass, Enum, Union) - Automatic pickle serialization
  • Nested models - Full Redis functionality preserved
from dataclasses import dataclass
from enum import Enum

@dataclass
class Config:
    debug: bool = False

class User(AtomicRedisModel):
    name: str = "default"
    scores: List[int] = []
    config: Config = Config()  # Auto-serialized
    
# All types work identically
user = User()
await user.config.set(Config(debug=True))  # Automatic serialization
await user.scores.aappend(95)               # Native Redis operation

Why Rapyer?

Race Condition Prevention

Traditional Redis operations can lead to data inconsistency in concurrent environments. Rapyer solves this with atomic operations and lock management.

Developer Experience

  • Type Safety: Full Pydantic v2 validation
  • Async/Await: Native asyncio support
  • Intuitive API: Pythonic Redis operations

Performance

  • Pipeline Operations: Batch multiple operations
  • Native Type Optimization: Efficient Redis storage
  • Connection Pooling: Built-in Redis connection management

Learn More


Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rapyer-0.0.3.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rapyer-0.0.3-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file rapyer-0.0.3.tar.gz.

File metadata

  • Download URL: rapyer-0.0.3.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rapyer-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c1c8dbb9e3fcecf44e4588cfb209f0c9f81f76ddf9d24ae5d40789d3a3aeb3ca
MD5 4f01b15a27c597f37a8a26d8810862c0
BLAKE2b-256 a4e740334ec83cbcc994aa755589bb13cc05de176ccaf0a41b85feaa9cf9912a

See more details on using hashes here.

File details

Details for the file rapyer-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: rapyer-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rapyer-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5ec99d1dd6f69486572b500db808aaacce3a803ba6f9a8982fc1163a60c59030
MD5 c0ab1b6e606197d7424f987a35c50077
BLAKE2b-256 24ee05ff21d7d15ddcef6cdb79a89c338a902478da60208f54fd42e03cbc31f1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page