Skip to main content

Python SDK for OpenZync — open-source agent memory platform with persistent, queryable, graph-based memory for AI agents

Project description

OpenZync Python SDK

PyPI Python License

Python SDK for OpenZync — the open-source agent memory platform with persistent, queryable, graph-based memory for AI agents.

Installation

pip install openzync

Requires Python 3.11+.

Quick Start

from openzync import OpenZync

client = OpenZync(api_key="oz_live_your_api_key_here")

# Create a user
user = client.users.create(external_id="alice")
print(f"User: {user.name} ({user.id})")

# Ingest conversation messages
resp = client.memory.ingest(
    messages=[
        {"role": "user", "content": "Hi, I am Alice from Acme Corp."},
        {"role": "assistant", "content": "Hello Alice! How can I help you today?"},
    ],
)
print(f"Ingested {resp.episode_count} episodes")

# Search across memory
results = client.graph.search("Alice Acme Corp", types="episodes,facts")
for r in results:
    print(f"  - {r['content']}")

Client API

Sync (default)

from openzync import OpenZync

client = OpenZync(api_key="...")

# ── Memory ──
client.memory.ingest(messages=[...])
client.memory.get_context(query="...")
client.memory.delete()

# ── Facts ──
client.facts.add(facts=[...])

# ── Graph ──
for node in client.graph.nodes():
    print(node.name)
detail = client.graph.node_detail(node_id)
client.graph.delete_node(node_id)
for edge in client.graph.edges(subject_id):
    print(edge.type)
comms = client.graph.communities()
results = client.graph.search("query")

# ── Users ──
user = client.users.create(external_id="bob")
user = client.users.get(user_id)
user = client.users.update(user_id, name="New Name")
client.users.delete(user_id)
for user in client.users.list_iter():
    print(user["name"])

# ── Sessions ──
session = client.sessions.create(external_id="s1")
msgs = client.sessions.messages(session_id)
client.sessions.delete(session_id)

Async

import asyncio
from openzync import AsyncOpenZync

async def main():
    async with AsyncOpenZync(api_key="...") as client:
        resp = await client.memory.ingest(messages=[...])

asyncio.run(main())

Error Handling

from openzync import OpenZync
from openzync._errors import NotFoundError, RateLimitError

client = OpenZync(api_key="...")

try:
    user = client.users.get("non-existent-id")
except NotFoundError:
    print("User not found")
except RateLimitError:
    print("Rate limited — slow down")

Pagination

List endpoints return an iterator that auto-fetches subsequent pages:

# Iterate over all users (auto-paginated)
for user in client.users.list_iter():
    print(user["name"])

LangChain Integration

LangChain developers can use OpenZync as a drop-in memory provider, graph retriever, and tool set.

pip install "openzync[langchain]"

Chat Message History

Persist conversation history to OpenZync:

from openzync import OpenZync
from openzync.integrations.langchain import OZChatMessageHistory
from langchain_core.messages import HumanMessage

client = OpenZync(api_key="...")
history = OZChatMessageHistory(
    session_id="session-1",
    user_id="user-abc",
    client=client,  # accepts both sync and async clients
)

history.add_message(HumanMessage(content="Hello!"))
print(history.messages)

Memory

Use OZMemory as a standard LangChain BaseMemory inside chains:

from openzync import OpenZync
from openzync.integrations.langchain import OZMemory
from langchain_core.messages import HumanMessage, AIMessage

client = OpenZync(api_key="...")
memory = OZMemory(
    session_id="session-1",
    user_id="user-abc",
    client=client,
    return_messages=True,   # False returns string
    memory_key="history",   # key in memory_variables
)

memory.save_context({"input": "Hi"}, {"output": "Hello!"})
context = memory.load_memory_variables({})
# context["history"] — list of BaseMessage or str depending on return_messages

Graph Retriever

Use OZGraphRetriever as a LangChain retriever for RAG pipelines:

from openzync.integrations.langchain import OZGraphRetriever

retriever = OZGraphRetriever(
    user_id="user-abc",
    client=client,
    k=5,                    # max results
    types="episodes,facts", # filter by node type
    score_threshold=0.7,    # minimum relevance score
)

docs = retriever.invoke("What does Alice know about Acme Corp?")
for doc in docs:
    print(doc.page_content, doc.metadata)

Tool plugins

Expose OpenZync graph search and fact management as LangChain tools:

from openzync.integrations.langchain.tools.graph import GraphSearchTool
from openzync.integrations.langchain.tools.facts import AddFactsTool

tools = [
    GraphSearchTool(client=client),
    AddFactsTool(client=client),
]

# Use with LangGraph / ReAct agents
# agent = create_react_agent(model, tools)

Development

# Install with dev dependencies
pip install "openzync[dev]"

# Install everything (dev + langchain)
pip install "openzync[dev,langchain]"

# Run tests
pytest

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

openzync-1.0.0b2.tar.gz (23.9 kB view details)

Uploaded Source

Built Distribution

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

openzync-1.0.0b2-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file openzync-1.0.0b2.tar.gz.

File metadata

  • Download URL: openzync-1.0.0b2.tar.gz
  • Upload date:
  • Size: 23.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openzync-1.0.0b2.tar.gz
Algorithm Hash digest
SHA256 5bfe1b21dac8e095dff46086627348d22e2e4769e1eb9e8700f4e6e39251aa4e
MD5 bb4dc46edc95c08ac4a5ca5a61e4970a
BLAKE2b-256 50e4eb5bc553695649d52996cda12d86528d7b6e57877a25e8a79cab6e402ddf

See more details on using hashes here.

File details

Details for the file openzync-1.0.0b2-py3-none-any.whl.

File metadata

  • Download URL: openzync-1.0.0b2-py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openzync-1.0.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 569803517259e126c954aefef8cc8625ebe6ca8140a60732d293a11bae0f0978
MD5 b42aa1740317c0bf8886fc357e450d11
BLAKE2b-256 5ae2732daa44ea6d84b9e05066fd2dc024de2fe10dede4fea6b8f921e649d6c9

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