Skip to main content

SelfGraph

SelfGraph

Turn unstructured text into a queryable, versioned knowledge graph.
One graph API over any graph backend.

Python 3.10+ License Apache-2.0 Any graph backend Interfaces SDK, CLI, MCP Built by HydraDB Discord

What's included

  • Text-to-graph extraction with any LLM provider, or without an LLM via spaCy NER or a zero-dependency fallback.
  • Typed CRUD over entities, relations, preferences, and decision traces.
  • Bitemporal versioning, source provenance, and per-namespace isolation.
  • Retrieval from keyword seeds and bounded BFS or DFS, returning source passages and relationships, no vector store.
  • A CLI and an MCP server over the same API.
  • One storage interface across backends: Neo4j, Memgraph, FalkorDB, embedded Kuzu, HydraDB, or a custom store.

Install

pip install selfgraph                 # core: Neo4j, the openCypher family, and HydraDB
pip install "selfgraph[llm]"          # LLM text extraction for any provider
pip install "selfgraph[ner]"          # LLM-free extraction via spaCy NER
pip install "selfgraph[falkordb]"     # the FalkorDB backend
pip install "selfgraph[kuzu]"         # the embedded Kuzu backend
pip install "selfgraph[all]"          # llm, tokenizer, falkordb, kuzu, mcp

Quickstart

No server and no LLM. pip install "selfgraph[kuzu]" and run:

import asyncio

from selfgraph import KuzuStore, SelfGraph


async def main() -> None:
    async with SelfGraph(store=KuzuStore("graph.kuzu")) as graph:
        await graph.insert.ontology(
            {
                "entities": [
                    {"id": "person:jane", "type": "Person", "name": "Jane Doe"},
                    {"id": "company:acme", "type": "Company", "name": "Acme"},
                ],
                "relations": [
                    {"from_entity": "person:jane", "type": "WORKS_AT", "to_entity": "company:acme"},
                ],
            }
        )
        result = await graph.retrieve("who works at Acme")
        print(result.context)


asyncio.run(main())

async with initializes the store on entry and closes it on exit; it also initializes lazily on first use, so a bare SelfGraph(...) works too. Prefer synchronous code? SyncSelfGraph has the same API without await.

Add an LLM and a server when you want text extraction at scale:

from selfgraph import LLMConfig, Neo4jStore, SelfGraph

async with SelfGraph(
    store=Neo4jStore("bolt://localhost:7687", auth=("neo4j", "password")),
    llm=LLMConfig(provider="anthropic", model="claude-sonnet-5-5"),
) as graph:
    await graph.insert.text("Soham prefers HydraDB. The team picked it for temporal history.")
    result = await graph.retrieve("which database and why", strategy="bfs", depth=3)
    print(result.context)

llm= is optional. Without it, insert.text extracts with spaCy NER (the ner extra) or a built-in regex fallback. Skip extraction entirely with insert.ontology(...) or by passing your own extractor=.

Backends

All logic lives in Python; a store only implements a small set of graph primitives, so the same graph runs on any backend.

from selfgraph import Neo4jStore, CypherStore, FalkorDBStore, KuzuStore, HydraDBStore

Neo4jStore("bolt://localhost:7687", auth=("neo4j", "password"))
CypherStore("bolt://localhost:7687", auth=("user", "password"))
FalkorDBStore(host="localhost", port=6379)
KuzuStore("selfgraph.kuzu")
HydraDBStore("bolt://127.0.0.1:17687", auth=("neo4j", "<token>"))

CypherStore covers the Bolt and openCypher family (Neo4j and Memgraph are tested); FalkorDBStore runs over FalkorDB's Redis protocol; KuzuStore is an embedded, in-process graph; HydraDBStore targets HydraDB. To add another database, implement the GraphStore primitives and pass your store to SelfGraph(store=...).

The CLI and the MCP server wrap the same API:

selfgraph --store neo4j --uri bolt://localhost:7687 --auth neo4j:password insert text "..." --source-id notes
selfgraph --store neo4j --uri bolt://localhost:7687 --auth neo4j:password mcp

Documentation

Full docs are in docs/: install, quickstart, inserting, resources, retrieval, backends, CLI, MCP, and errors.

Contributing

Issues and pull requests are welcome. Contributions start with an approved issue; see CONTRIBUTING.md. Join the community on Discord.

License

Apache-2.0.

Metadata

Release files for selfgraph 0.0.2

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

Source distribution (sdist)

Source distribution for selfgraph 0.0.2
File Size Uploaded Provenance Actions
selfgraph-0.0.2.tar.gz 73.5 kB Without provenance Details for selfgraph-0.0.2.tar.gz

Built distribution (wheel)

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

Total release size: 144.2 kB

Release files / selfgraph-0.0.2.tar.gz

Download URL selfgraph-0.0.2.tar.gz
Size 73.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b9a391fc3216b53dde7bb21d34eeea3ac7ea2930e156ff2ff573112bbc9207f2
BLAKE2b-256 checksum
How to use checksums
484a1cd16e947be547db38c3a5bb7f733f760959d19f8ec4b499d4a7a9b2eb58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / selfgraph-0.0.2-py3-none-any.whl

Download URL selfgraph-0.0.2-py3-none-any.whl
Size 70.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
611b8374ede01400f38125496d79db34a60515e7f9247560c54d84f966c4e3d4
BLAKE2b-256 checksum
How to use checksums
1528130eeb861ecf2c9adcedb63673cf50ee8b2a6837ce8255714b2ce4400a50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for selfgraph 0.0.2

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