Skip to main content

Small typed graph kernel with canonical stores, projections, and sparse algorithms.

Project description

simpleGraph

simpleGraph is a small typed graph kernel for projects that need stable refs, edge type definitions, observation audit rows, bounded traversal, and analytical graph projections.

The design keeps mutable application state separate from analytical views:

  • runtime configuration: open_graph(config)
  • canonical stores: memory and SQLite, plus a Postgres schema adapter
  • analytical projection: DuckDB export and sparse matrix snapshots
  • algorithms: PageRank, seed propagation, connected components, multi-source distance, and seed reachability

The project is intentionally not a Neo4j replacement. It provides graph building blocks that Katib and LogBD can share without inheriting each other's domain model.

Traversal

Traversal is intentionally bounded. simpleGraph supports indexed local graph operations, not arbitrary graph-query planning:

  • iter_nodes(...)
  • iter_edges(...)
  • iter_incoming_edges(...)
  • iter_outgoing_edges(...)
  • iter_incident_edges(...)
  • neighbors(..., direction="both")
  • subgraph(..., direction="both")
  • path(..., direction="outgoing")
  • traverse(..., max_depth=..., max_nodes=..., max_edges=...)

Directional edges follow their stored direction for outgoing traversal and reverse direction for incoming traversal. Edges whose EdgeType is not directional are traversable both ways. Deep traversal must set explicit limits so high-branching graphs and cycles cannot expand without bounds.

MemoryGraphStore is for small local graphs, tests, and embedded use. SQLiteGraphStore is durable local storage with in-process indexes. Larger graphs should use query-backed stores or DuckDB/sparse-matrix projections for bulk analysis.

Graph Model

Nodes are things. A node has ref, kind, label, properties, and created_at/updated_at timestamps. Custom fields belong in properties; node kinds do not create custom SQL columns or per-kind detail tables.

Edge types define connection kinds. An EdgeType has key, forward_label, reverse_label, directional, constraints, system, and created_at/updated_at timestamps.

Edges are actual connections. An edge has id, source_ref, target_ref, edge_type_key, free-form user annotation label, weight, properties, and created_at/updated_at timestamps. Custom connection data belongs in properties.

Observations record source, import, and process metadata as append-only support rows. They are audit evidence for a node or edge, not the source of truth for whether canonical graph rows exist. source is free text. Containment is a regular directional edge with edge_type_key="contains". Objects may have multiple parents. The only built-in containment validation for now is acyclic containment, represented by constraints={"acyclic": True} on the contains edge type.

Canonical storage tables are named sg_nodes, sg_edge_types, sg_edges, sg_observations, and sg_node_metrics.

Quick Start

from simplegraph import Edge, EdgeType, Node, Observation, open_graph

runtime = open_graph({"store": {"backend": "memory"}})
store = runtime.store
store.upsert_edge_type(EdgeType(key="contains", forward_label="Contains", reverse_label="Contained by", constraints={"acyclic": True}))
store.upsert_node(Node(ref="note:a", kind="note", label="A"))
store.upsert_node(Node(ref="file:b", kind="file", label="B", properties={"mime_type": "text/plain"}))
edge = store.upsert_edge(Edge(source_ref="note:a", target_ref="file:b", edge_type_key="contains"))
store.add_observation(Observation(subject_kind="edge", subject_id=edge.id, source="import"))

print(store.incoming_edges("file:b"))
print(list(store.iter_edges(source_ref="note:a", edge_type_key="contains")))
print(store.path("note:a", "file:b"))
print(store.traverse("note:a", depth=2, max_nodes=100, max_edges=100))

Runtime config keeps backend-specific settings inside adapter-owned options:

runtime = open_graph({
    "store": {
        "backend": "sqlite",
        "options": {"path": "/state/simplegraph.sqlite"},
    },
    "projections": {
        "analytics": {
            "backend": "duckdb",
            "options": {"path": "/state/simplegraph.duckdb"},
        }
    },
})

CLI

simpleGraph is a library plus deterministic CLI, not a server. It does not ship an HTTP API, daemon, auth layer, or deployment runtime. Applications that need a service should wrap the library or CLI themselves.

Supported command groups:

pip install simplegraph-kernel

simplegraph validate --input graph.json
simplegraph init --store sqlite --path graph.sqlite
simplegraph import --store sqlite --path graph.sqlite --input graph.json
simplegraph query neighbors --path graph.sqlite --ref note:a
simplegraph query path --path graph.sqlite --from note:a --to file:b
simplegraph export snapshot --path graph.sqlite --output snapshot.json
simplegraph project duckdb --path graph.sqlite --output graph.duckdb
simplegraph algorithm pagerank --snapshot snapshot.json --output pagerank.json

Graph input can be a JSON object with edge_types, nodes, edges, and observations arrays, or JSONL records with record_type set to edge_type, node, edge, or observation. Algorithm commands consume GraphSnapshot JSON exported by simplegraph export snapshot.

Optional Extras

pip install "simplegraph-kernel[dev]"

The core package has no required third-party dependencies. Sparse algorithms use NumPy and SciPy. DuckDB projections use DuckDB and PyArrow. The Postgres schema adapter uses psycopg.

Adapter Ownership

Project-specific adapters do not live in this package. Katib, LogBD, and other host applications should own their own translation layers and depend on simplegraph-kernel only for the shared graph models, stores, projections, algorithms, and CLI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simplegraph_kernel-0.1.0.tar.gz (30.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simplegraph_kernel-0.1.0-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

Details for the file simplegraph_kernel-0.1.0.tar.gz.

File metadata

  • Download URL: simplegraph_kernel-0.1.0.tar.gz
  • Upload date:
  • Size: 30.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for simplegraph_kernel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 af83aac919d519a348d06491a4178a6fe674e578312ed7a16be4ff233a96209e
MD5 ac472ff1f0db3130621db67d901a392d
BLAKE2b-256 1af44dbd0cb2cd085ff0269e93c3c1c933ba9d4924ffdc84794176173ea2c38a

See more details on using hashes here.

File details

Details for the file simplegraph_kernel-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for simplegraph_kernel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83c39ac2f1c7d8de0cb024655214a0dbf6d4bf221cefd57c606daa626bc2269e
MD5 d726a6e7314969cff4a84c086292b86d
BLAKE2b-256 5bdfd055877fec9ec60f89fa3774d10ed52f53f4ad547bf017f6b2eaf1248571

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page