SelfGraph
Turn unstructured text into a queryable, versioned knowledge graph.
One graph API over any graph backend, in Python and TypeScript.
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, 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, falkordb, kuzu, mcp
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, 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.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| selfgraph-0.0.3.tar.gz | 101.0 kB | Without provenance | Details for selfgraph-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| selfgraph-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for selfgraph-0.0.3-py3-none-any.whl |
Total release size: 196.2 kB
Release files / selfgraph-0.0.3.tar.gz
| Download URL | selfgraph-0.0.3.tar.gz |
|---|---|
| Size | 101.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a77c28a4cda21446ca4ff70e2b3ef92191bca2e618c6128529f52718ccebc40
|
|
BLAKE2b-256 checksum How to use checksums |
a3fa321cdc01ae71cde6249422e42911909819a6a58c296fad65d06f78cd1812
|
| 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.3-py3-none-any.whl
| Download URL | selfgraph-0.0.3-py3-none-any.whl |
|---|---|
| Size | 95.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ae235ee4e01902e4fbdd8721168889ed246ea66d4b135ccfeb3fe84858e2bd86
|
|
BLAKE2b-256 checksum How to use checksums |
38e1754b0979a8319f1fab12bbe44982397e29759fdc570c1fdcdc0237612726
|
| 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.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.