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.

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.3

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.3
File Size Uploaded Provenance
semurg-0.1.3.tar.gz 35.2 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 66.0 kB

Release files / semurg-0.1.3.tar.gz

Download URL semurg-0.1.3.tar.gz
Size 35.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3076da86c7b485a5157e94d404e178e0e81117663bd0efbe72e6cb4f713531bb
BLAKE2b-256 checksum
How to use checksums
832640903cc11d47345b290a2240f7c9e8c8c4e31f4c5131f6e6738475980970
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.3-py3-none-any.whl

Download URL semurg-0.1.3-py3-none-any.whl
Size 30.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3cb948b135a5f65756f7e06602adced02c45f6d124c96443fcfd29828d7d7d57
BLAKE2b-256 checksum
How to use checksums
68c569be49525338805e931e623597ac5083026007f8d9cf794bd971d86edc8c
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.3

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