๐๏ธ synced-memory
A production-ready Python class for seamless, multiprocessing-safe, persistent key-value storage using Redis or DragonflyDB as a backend. If the backend is unavailable, values are cached locally and queued for syncing when it comes back online. All values are serialized as JSON, and you interact with it using natural Python attribute access.
Purpose
The intention is to use this with agentic workflows deployed as microservices, allowing for multiple instances of the same pod to share their state.
โจ Features
- ๐ Multiprocessing-safe: All processes share the same state via Redis or DragonflyDB.
- ๐ง Pythonic API: Set and get attributes as if they were regular object properties.
- ๐ฐ๏ธ Persistence: Values survive process restarts and context blocks.
- ๐ฆ Resilient: If the backend is down, changes are queued and flushed when it returns.
- ๐งฉ Customizable: Prefixes and conversation IDs for namespacing.
- ๐งต Background sync: Queued changes are flushed automatically in the background.
Quick Example
from synced_memory.redis import Memory # Redis
from synced_memory.dragonflydb import Memory # DragonflyDB
mem = Memory()
mem.answer = 42
print(mem.answer) # 42
# Across processes or instances:
mem2 = Memory()
print(mem2.answer) # 42
mem.settings = {"theme": "dark", "volume": 0.75}
print(mem.settings) # {'theme': 'dark', 'volume': 0.75}
Getting Started
Check out the Installation Guide and Quickstart Tutorial to get up and running.
License
MIT