Skip to main content

SelfGraph

SelfGraph

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

Python 3.10+ TypeScript, Node 20+ 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.
  • An optional schema that guides extraction and validates inserts, with warn, strict, or off modes.
  • Bitemporal versioning, source provenance, and per-namespace isolation.
  • Retrieval from keyword seeds and bounded BFS, DFS, or personalized PageRank, 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.
  • A pure TypeScript SDK in typescript/ that reads and writes the same graph as the Python one.

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, ner, falkordb, kuzu, mcp

spaCy NER also needs its English model: python -m spacy download en_core_web_sm. Without it, extraction falls back to a built-in regex pass.

For TypeScript, npm install @hydradb/selfgraph. See typescript/README.md.

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 the SDK; 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, schema, resources, retrieval, backends, CLI, MCP, errors, and TypeScript.

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

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.4
File Size Uploaded Provenance Actions
selfgraph-0.0.4.tar.gz 122.9 kB Without provenance Details for selfgraph-0.0.4.tar.gz

Built distribution (wheel)

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

Total release size: 223.7 kB

Release files / selfgraph-0.0.4.tar.gz

Download URL selfgraph-0.0.4.tar.gz
Size 122.9 kB
Tags Source
SHA-256 checksum
How to use checksums
05b60963f2f71d8c994ed457fa008ee3fb0bfe685ab1947f2c847c263961c5df
BLAKE2b-256 checksum
How to use checksums
cb39e12cd80f64c1c041d5b7e58c43b2f328a266f8085a3176620b8225eef40c
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.4-py3-none-any.whl

Download URL selfgraph-0.0.4-py3-none-any.whl
Size 100.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
408a7da45685a47d3c1882b50720a37ae7e4bd19381efc73ab5c3d289aaf2ddb
BLAKE2b-256 checksum
How to use checksums
45e1a0e9777d1a851cd536b6457088862851801a8a60d37d7f98b23d44387ccc
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.4

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