Skip to main content
image

PyPI version PyPI Downloads Python Versions LinkedIn Portal ORCID License

WRedis 🚀

Production-Grade, High-Availability Python Client Suite for Redis with Dual Sync/Async APIs, Transparent Claim-Check RAM Offloading, and Enterprise Forensic Auditing.


📑 Table of Contents


🏛️ Architectural Overview

+========================================================================================+
|                                    WREDIS ECOSYSTEM                                    |
+========================================================================================+
|                                                                                        |
|   🔌 UNIFIED CLIENT INTERFACE (Dual Sync / Async APIs)                                 |
|   +--------------------------------------------------------------------------------+   |
|   |  • Auto-Reconnection & Connection Pooling with intelligent backoff            |   |
|   |  • Dual Sync / Asynchronous (`asyncio` / `await`) runtime parity               |   |
|   |  • Forensic Audit Trail (`forensic=True` appends pre/post mutation snapshots)  |   |
|   |  • Type-Safety: 100% strict PEP-484 type annotations and runtime validation    |   |
|   +--------------------------------------------------------------------------------+   |
|                                          |                                             |
|                                          v                                             |
|   🗂️ 13 SPECIALIZED DATA STRUCTURE MANAGERS                                            |
|   +--------------------------------------------------------------------------------+   |
|   |  • KeyValue: Ephemeral RAM offload, raw byte DMA, auto-JSON serialization       |   |
|   |  • Cache Decorators: `@cache` / `@async_cache` with hit/miss telemetry & TTL   |   |
|   |  • Streams & Queues: Consumer groups, ACK management, Gzip payload compression  |   |
|   |  • Pub/Sub: Thread-safe listener registries and topic routing                  |   |
|   |  • Sets / SortedSets: Leaderboards, rank queries, and set algebra operations   |   |
|   |  • Geo / Bitmaps / HyperLogLog: Spatial radii, bitfields, probabilistic stats  |   |
|   |  • Pipelines & Transactions: Batch pipelining and atomic MULTI/EXEC locks      |   |
|   +--------------------------------------------------------------------------------+   |
|                                          |                                             |
|                                          v                                             |
|   🛡️ HIGH AVAILABILITY & INFRASTRUCTURE TOPOLOGIES                                    |
|   +--------------------------------------------------------------------------------+   |
|   |  • Standalone Redis: Single-node high-throughput cache & Claim-Check RAM       |   |
|   |  • Redis Sentinel: Automatic master failover & replica topology sync           |   |
|   |  • Redis Cluster: Transparent 16,384 hash slot partitioning and sharding       |   |
|   +--------------------------------------------------------------------------------+   |
+========================================================================================+

🌟 Why WRedis?

Direct usage of low-level redis-py requires substantial boilerplate for production applications: manual connection teardown, connection pool exhaustion debugging, type casting, JSON parsing/serializing, manual retry backoff, and ad-hoc clustering configs.

WRedis delivers an enterprise-grade developer experience:

  • 🚀 Zero Boilerplate: Specialized manager classes for each Redis capability with intuitive CRUD semantics.
  • ⚡ Claim-Check RAM Offload Engine: Native setex and get_bytes optimized for ultra-high-throughput multimedia offloading in event-driven systems (e.g., wkafka).
  • 🔍 Forensic Auditing: Built-in mutation audit trail stream (forensic=True) recording before-and-after snapshots with zero performance penalty.
  • 🎯 Dual Sync & Async APIs: Seamlessly switch between synchronous workers and high-concurrency asyncio services.
  • 🛡️ Enterprise Resilience: Native Sentinel failover detection and Redis Cluster sharding out of the box.
  • 📦 Production Ready: 100% test coverage with fakeredis and live integration test suites.

📦 Installation

# Standard installation from PyPI
pip install wredis

# Using poetry
poetry add wredis

🛠️ Key Technologies and Libraries

WRedis is engineered on top of modern, battle-tested Python and Redis database standards:

  • Python (3.9 - 3.14): Modern typed runtime with PEP-561 compliance (py.typed).
  • redis-py (redis>=5.0.0): High-performance core Redis client supporting Standalone, Sentinel, Cluster, and AsyncIO.
  • Loguru: Structured, thread-safe asynchronous logging and operational telemetry.
  • Fakeredis: Deterministic in-memory Redis mocking for hermetic unit testing without external daemon dependencies.
  • Pytest & Pytest-Cov: Automated unit, integration, and high-availability test suites (>95% coverage).

🚀 Quick Start

Cache Decorator with Metrics & TTL

from wredis.cache import RedisCacheManager

cache = RedisCacheManager(host="localhost", port=6379)

@cache(ttl=60)
def fetch_user_profile(user_id: str) -> dict:
    # Heavy database query or remote API call
    return {"id": user_id, "name": "Alice", "role": "admin"}

# First call executes function; subsequent calls within 60s return cached RAM result instantly
profile = fetch_user_profile("user-42")

🔍 Enterprise Forensic Audit Trail

WRedis provides an automated, stream-based audit trail (_forensic_audit_log) for monitoring data mutations across sensitive key-spaces.

  • Disabled by default: Enable by setting forensic=True when instantiating any manager:
    from wredis.hash import RedisHashManager
    
    hm = RedisHashManager(host="localhost", forensic=True)
    hm.create_hash("accounts", "acc:100", {"balance": 5000})
    
  • Stream-Based Immutable Ledger: Records the action (create, update, delete), target key, pre-state, post-state, and high-precision UTC timestamp.
  • Zero Overhead: Fully isolated logging stream that does not block primary database commands.

🧩 Supported Data Structures & Managers

1. Key-Value & Ephemeral Binary Storage

Direct ephemeral RAM storage for raw binary streams, strings, and auto-serialized dictionaries.

from wredis.keyvalue import RedisKeyValueManager

kv = RedisKeyValueManager(host="localhost", port=6379)

# 1. Store raw binary bytes with 5-second TTL (ideal for high-throughput multimedia offload & claim-check)
kv.setex("frame:camera_1", ttl=5, value=raw_bytes)

# 2. Retrieve raw bytes directly without string encoding overhead
payload = kv.get_bytes("frame:camera_1")

# 3. Store and retrieve structured dictionaries (auto-serialized to JSON)
kv.set("metadata:101", {"status": "active", "tags": ["cv", "edge"]})
meta = kv.get("metadata:101")  # Returns dict directly

2. Cache Decorators (@cache / @async_cache)

High-performance memoization with configurable TTL and key hashing:

# Synchronous function caching
@cache("product_cache", ttl=300)
def get_product(product_id: int) -> dict:
    return {"id": product_id, "price": 49.99}

# Asynchronous coroutine caching
@async_cache("async_orders", ttl=120)
async def get_order_async(order_id: str) -> dict:
    return await db.orders.find_one({"_id": order_id})

3. Hashes

Manage structured object maps with field-level mutations:

from wredis.hash import RedisHashManager

hm = RedisHashManager(host="localhost")
hm.create_hash("users", "user:1", {"name": "Alice", "age": 30}, ttl=3600)

user = hm.read_hash("users", "user:1")
hm.update_hash("users", "user:1", {"age": 31})
hm.delete_hash_field("users", "user:1")

4. Queues with Gzip Compression

Reliable FIFO worker queues with optional compression for heavy task payloads:

from wredis.queue import RedisQueueManager

# Producer
qm = RedisQueueManager(host="localhost", compress=True)
qm.publish("heavy_tasks", {"action": "render_video", "clip_id": 992}, ttl=60)

# Consumer / Worker
@qm.on_message("heavy_tasks")
def task_worker(task):
    print(f"Processing task: {task['action']}")

qm.start()

5. Pub/Sub Engine

Thread-safe topic broadcasting and event subscriptions:

from wredis.pubsub import RedisPubSubManager

pbm = RedisPubSubManager(host="localhost")

# Subscribe listener
@pbm.on_message("system.alerts")
def on_alert(msg):
    print(f"Alert received: {msg}")

# Publish message
pbm.publish_message("system.alerts", {"level": "CRITICAL", "node": "gpu-01"})

6. Streams & Consumer Groups

Production event streaming with consumer group checkpointing and message acks:

from wredis.streams import RedisStreamManager

sm = RedisStreamManager(host="localhost")

# Publish event
sm.add_to_stream("order_events", {"order_id": "ORD-55", "total": 99.0})

# Consumer group subscriber
@sm.on_message("order_events", group_name="billing_workers", consumer_name="worker_a")
def handle_event(event):
    print(f"Processing order event: {event}")

sm.wait()

7. Bitmaps

Compact bitfields for daily active user tracking and boolean flag registries:

from wredis.bitmap import RedisBitmapManager

bm = RedisBitmapManager(host="localhost")
bm.set_bit("dau:2026-11-16", offset=402, value=1)

is_active = bm.get_bit("dau:2026-11-16", 402)  # 1
total_active = bm.count_bits("dau:2026-11-16")

8. Sets & Sorted Sets

Unordered unique sets and scored leaderboards:

from wredis.sortedset import RedisSortedSetManager

ssm = RedisSortedSetManager(host="localhost")
ssm.add_to_sorted_set("leaderboard", 1500, "player_alpha")
ssm.add_to_sorted_set("leaderboard", 2300, "player_beta")

# Retrieve top 10 players
top_players = ssm.get_sorted_set_reverse("leaderboard", start=0, end=9, with_scores=True)

9. Geospatial Indices

Coordinate storage and radius-based geographic queries:

from wredis.geo import RedisGeoManager

gm = RedisGeoManager(host="localhost")
gm.add_location("charging_stations", "Station A", 40.785091, -73.968285)
gm.add_location("charging_stations", "Station B", 40.758896, -73.985130)

distance_km = gm.distance("charging_stations", "Station A", "Station B", unit="km")

10. HyperLogLog Cardinality

Probabilistic distinct count tracking with negligible memory footprint:

from wredis.hyperloglog import RedisHyperLogLogManager

hll = RedisHyperLogLogManager(host="localhost")
hll.add("unique_visitors", "ip_1", "ip_2", "ip_3")
unique_count = hll.count("unique_visitors")

11. Pipelines & Atomic Transactions

Batch command execution and atomic MULTI/EXEC operations:

from wredis.pipeline import RedisPipelineManager

pm = RedisPipelineManager(host="localhost")
results = pm.mget_pipeline("key1", "key2", "key3")

🛡️ High Availability (Sentinel & Cluster)

Redis Sentinel

Automatic master failover orchestration with Sentinel service discovery:

from wredis.ha.sentinel import RedisSentinelManager

sm = RedisSentinelManager(
    sentinel_hosts=[("sentinel-node-1", 26379), ("sentinel-node-2", 26379)],
    service_name="mymaster",
    password="<your_password>",
    db=0
)

Redis Cluster

Automatic client-side sharding across 16,384 hash slots:

from wredis.ha.cluster import RedisClusterManager

cm = RedisClusterManager(
    startup_nodes=[{"host": "cluster-node-1", "port": 6379}, {"host": "cluster-node-2", "port": 6379}],
    password="<your_password>",
)

⚙️ Connection & Configuration Reference

All WRedis managers accept standard unified connection arguments:

Parameter Type Default Description
host str "localhost" Redis server hostname or IP address.
port int 6379 Redis server TCP port.
db int 0 Target Redis database index (0-15).
password Optional[str] None Authentication password.
verbose bool True Structured Loguru diagnostic telemetry.
decode_responses bool False Decode binary responses to UTF-8 strings automatically.
forensic bool False Enable automatic stream-based mutation auditing (_forensic_audit_log).

Queue-specific parameters:

Parameter Type Default Description
poll_interval float 1.0 Seconds to wait between consumer poll intervals.
max_retries int 3 Maximum retry attempts upon task failure.
compress bool False Automatically compress queue payloads using Gzip.

🧪 Unit Testing & Quality Assurance

WRedis enforces rigorous quality assurance with comprehensive mocked and live integration test suites:

# 1. Run unit test suite with in-memory fakeredis
pytest tests/unit/ -v

# 2. Run test coverage verification
pytest --cov=wredis tests/unit/

👤 Author & Official Affiliation


📜 License

Distributed under the MIT License. Free for commercial, enterprise, and research applications.

Metadata

Release files for wredis 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wredis 1.1.1
File Size Uploaded Provenance Actions
wredis-1.1.1.tar.gz 2.2 MB Without provenance Details for wredis-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wredis 1.1.1
File Interpreter ABI Platform Actions
wredis-1.1.1-py3-none-any.whl Python 3 none any Details for wredis-1.1.1-py3-none-any.whl

Total release size: 2.2 MB

Release files / wredis-1.1.1.tar.gz

Download URL wredis-1.1.1.tar.gz
Size 2.2 MB
Tags Source
SHA-256 checksum
How to use checksums
492a867a2bd29857453a8b08adc6c58b7435f5357fa2b67a3540a6d35048f033
BLAKE2b-256 checksum
How to use checksums
72080fd304b9a4dd85207333aa4597feb99aea1d9af4ea9fc0bf52ae01b3ec7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / wredis-1.1.1-py3-none-any.whl

Download URL wredis-1.1.1-py3-none-any.whl
Size 73.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47854e695a987982f0685fc6488f3ffe9f08d6b93dc58c81c10a5f6f41f26f2f
BLAKE2b-256 checksum
How to use checksums
31024cdadad7102d734067d9ad999772d3c2b09170c7b8788e61932f69f301c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for wredis 1.1.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page