Skip to content

๐Ÿ—„๏ธ synced-memory

Tests & Lint PyPI Downloads Monthly Downloads License

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