SDKs

Python SDK

Connect Python apps to the recommended MemexAI service.

The Python SDK connects to the recommended containerized MemexAI service by default. Direct Postgres mode is still available for advanced deployments where your Python app intentionally owns database credentials.

Install

From the repository root:

python3 -m pip install -e "sdks/python[test]"

From sdks/python:

python3 -m pip install -e ".[test]"

Service usage

from memexai import MemexAI

memex = MemexAI(
    url="http://localhost:8080",
    api_key="dev-agent-key",
)

memory = memex.for_user("user_123", actor="assistant")
await memory.write_file(
    "user/profile.md",
    "# Profile\n\n- Prefers quiet neighborhoods.",
    reason="captured preference",
)

result = await memory.read_file("user/profile.md")
print(result["content"])

await memex.close()

Helpers

await memory.list_files(prefix="user/")
await memory.read_file("user/profile.md")
await memory.write_file("user/profile.md", "# Profile", reason="initial write")
await memory.patch_file(
    "user/profile.md",
    "append_lines",
    after_heading="# Profile",
    lines=["- Likes good tests"],
    reason="new preference",
)
await memory.search("quiet neighborhoods")
await memory.memorize("Remember that the user prefers quiet neighborhoods.")

Framework adapters

FrameworkPage
LangChainLangChain adapter
LlamaIndexLlamaIndex adapter
CrewAICrewAI adapter

Advanced: direct Postgres

Use create_memex only when your Python app should connect directly to Postgres.

from memexai import create_memex

memex = await create_memex({
    "databaseUrl": "postgresql://memexai:memexai@localhost:5433/memexai",
})

await memex.migrate()

memory = memex.for_user("user_123", actor="assistant")
result = await memory.search("quiet neighborhoods")

await memex.close()

On this page