Skip to main content

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+. Published on PyPI.

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?"},
    ],
    session_id="session-1",
)
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=[...], session_id="session-1")  # always sent as multipart/form-data, even text-only
client.memory.get_context(query="...")
client.memory.delete(confirm="<project-id>")

# ── Facts ──
client.facts.add(facts=[...], session_id="session-1")

# ── 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=[...], session_id="session-1")

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

# Clone and install with dev dependencies
git clone https://github.com/openzync/openzync-sdk-python.git
cd openzync-sdk-python
pip install "openzync[dev]"

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

# Run tests
pytest

License

Apache 2.0 — see LICENSE.

Metadata

Release files for openzync 1.0.0

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

Source distribution (sdist)

Source distribution for openzync 1.0.0
File Size Uploaded Provenance Actions
openzync-1.0.0.tar.gz 43.6 kB Without provenance Details for openzync-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 108.4 kB

Release files / openzync-1.0.0.tar.gz

Download URL openzync-1.0.0.tar.gz
Size 43.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2b491d910cde334996f4b30ca6501a3dddfbfd4f2dd57f9b0da231e9a0fb3965
BLAKE2b-256 checksum
How to use checksums
a9432e55476db18c6d1efc25f093d0aee8f4b59365a958855ba53a904521fac0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / openzync-1.0.0-py3-none-any.whl

Download URL openzync-1.0.0-py3-none-any.whl
Size 64.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1649ea45b4f19e7ad11de28e41a51431233706cc26e4a78876949714d8b898a1
BLAKE2b-256 checksum
How to use checksums
903ce0b563a13d7618f00a43ab1a9bec6498b08361700b4150d310c0c5ff64ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for openzync 1.0.0

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