Skip to main content

semurg

The Python client for Semurg: memory for AI agents (a knowledge graph and vector search in one engine) that runs on your own hardware. Zero dependencies: it uses only the standard library.

Quick start (needs Docker)

python3 -m venv .venv && . .venv/bin/activate   # Ubuntu 24.04 and Homebrew Python refuse a system-wide pip install
pip install semurg
import semurg

mem = semurg.open()   # starts a local Semurg node with Docker, or reuses the one already running
mem.remember(scope="demo", content="Ada Lovelace works at Acme on the analytics team.")
print(mem.recall(scope="demo", subject="Ada Lovelace"))          # what is stored about one entity, with its source
print(mem.context(scope="demo", query="Where does Ada work?"))  # passages and facts for a question

The first open() downloads the Semurg image; later ones reuse the running node. The node listens on 127.0.0.1 only, keeps its data in a Docker volume (semurg-default-data) and the client reads its API token for you. mem.stop() stops the node and keeps the data; semurg.remove() deletes the node and its data. semurg.open("work") runs a second, separate node.

From a shell, python -m semurg up starts the node and prints export SEMURG_URL=... and export SEMURG_API_TOKEN=... for other tools; python -m semurg down stops it.

Connect to a node you run yourself

1. Start a node

With Docker on an Intel or AMD x86_64 machine (Linux, or Windows through WSL2 with Ubuntu 24.04; Docker Desktop on Windows and Mac is being tested):

docker run -d --name semurg -p 127.0.0.1:4000:4000 \
  --ulimit memlock=-1 --ulimit nofile=1048576:1048576 --security-opt seccomp=unconfined \
  -v semurg-data:/var/lib/semurg one.semurg.io/semurg
until docker logs semurg 2>&1 | grep -q 'Your API token'; do sleep 1; done
export SEMURG_API_TOKEN=$(docker exec semurg cat /var/lib/semurg/.api_token)

Or install a node on Ubuntu 24.04: curl -fsSL https://one.semurg.io/install | sudo bash (what it needs). The first node is free.

2. Install

python3 -m venv .venv && . .venv/bin/activate   # Ubuntu 24.04 and Homebrew Python refuse a system-wide pip install
pip install semurg

3. Remember and recall

import os
from semurg import Client

with Client("http://127.0.0.1:4000", token=os.environ["SEMURG_API_TOKEN"]) as mem:
    mem.remember(scope="demo", content="Ada Lovelace works at Acme on the analytics team.")
    print(mem.recall(scope="demo", subject="Ada Lovelace"))          # what is stored about one entity, with its source
    print(mem.context(scope="demo", query="Where does Ada work?"))  # passages and facts for a question

A scope is a separate, named memory. Send user_id to keep each of your end users' memories apart.

Your agent can also send the entities and relations it found, so they are stored as a graph at once:

mem.remember(
    scope="demo",
    facts={"entities": [{"name": "Acme", "type": "Company"}, {"name": "Dana", "type": "Person"}],
           "relations": [{"source": "Dana", "target": "Acme", "type": "WORKS_AT"}]},
    passages=[{"text": "Dana works at Acme.", "mentions": ["Dana", "Acme"]}],
)

The memory calls

memory_status, remember, recall, context, relate, forget (every form: an entity, a fact, a passage, a source, a whole scope or one attribute) and document, over HTTP, plus delete_user (HTTP only), which deletes one end user's whole memory. Over MCP the node serves the same seven memory tools to agent frameworks: see one.semurg.io/agents.

Use it from an MCP client that runs a local program

Most MCP clients connect to the node's own address (http://127.0.0.1:4000/v1/mcp). For a client that only starts local programs and talks to them over stdin/stdout, this package includes that program:

{
  "mcpServers": {
    "semurg": {
      "command": "python",
      "args": ["-m", "semurg", "mcp"],
      "env": {"SEMURG_URL": "http://127.0.0.1:4000", "SEMURG_API_TOKEN": "<your node's token>"}
    }
  }
}

It carries each message to your node and its answer back; the node does the work. SEMURG_SCOPE sets a default memory scope for the connection and SEMURG_USER pins one end user. With no node running, the client still sees the tool list, and every call answers that no node is reachable at SEMURG_URL.

Load a graph and walk it

Edges are written as storage containers built by semurg.container; an edge's id is its content address, so writing the same edge twice stores it once.

from semurg import container

mem.ingest([container.edge(1, 2), container.edge(2, 3), container.edge(3, 4)])
walk = mem.query("traverse", {"seeds": [1], "hops": 3})
print(walk["result"])   # the nodes reached, the edges walked, and a witness per level

Licence: Apache-2.0 (this client). The Semurg engine is licensed separately; the first node is free.

Metadata

Release files for semurg 0.1.5

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

Source distribution (sdist)

Source distribution for semurg 0.1.5
File Size Uploaded Provenance Actions
semurg-0.1.5.tar.gz 67.9 kB Without provenance Details for semurg-0.1.5.tar.gz

Built distribution (wheel)

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

Total release size: 128.7 kB

Release files / semurg-0.1.5.tar.gz

Download URL semurg-0.1.5.tar.gz
Size 67.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c96c57afa20f387d7a88d117fa7dbd0b34cc549a5e990ceefc7f7c6e30bf1c71
BLAKE2b-256 checksum
How to use checksums
981a23a5fb0a7b19b6e23018bf0ede57f7f90272aba81af85c464e04f87b0c21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / semurg-0.1.5-py3-none-any.whl

Download URL semurg-0.1.5-py3-none-any.whl
Size 60.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0b337ddf6989ae592de202a7ff38ecf01b86651076f93b9196a1c59b5e23e95
BLAKE2b-256 checksum
How to use checksums
a5160a550b8664c2d49c979fcf90143d5461d9cbbef9e0a7d9a0d7b023f36653
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for semurg 0.1.5

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