Skip to main content

kaos-graph

Part of Kelvin Agentic OS (KAOS) — open agentic infrastructure for legal work, built by 273 Ventures. See the full KAOS package map for the rest of the stack.

PyPI - Version Python License CI

kaos-graph is a high-performance graph library for KAOS — a typed Python API over a pure-Rust core backed by petgraph and the oxrdf RDF engine. It provides the graph-algorithm and knowledge-graph building blocks the rest of the stack relies on: 40+ algorithms (PageRank, shortest paths, centrality, community detection, DAG ops), RDF/SPARQL parsing, and typed Python wrappers throughout.

It is dependency-light: the BASE install pulls only kaos-graph itself plus defusedxml (~250 KB pure-Python). Optional extras layer in the rest of the KAOS ecosystem.

Install

uv add "kaos-graph>=0.1.0"
# or
pip install "kaos-graph>=0.1.0"

kaos-graph requires Python 3.13 or newer. The published wheels are cp313-abi3 — one wheel per OS/architecture covers every CPython 3.13+ minor (3.13, 3.14, 3.15, …). No re-release needed when 3.15 ships.

Platform coverage: Linux x86_64 (manylinux + musllinux), Linux aarch64 (manylinux + musllinux), macOS arm64, Windows x86_64, Windows arm64.

Quick start

from kaos_graph import Graph
from kaos_graph.algorithms import pagerank, shortest_paths, topological_sort

g = Graph()
g.add_node("alice", role="engineer")
g.add_node("bob", role="manager")
g.add_edge("alice", "bob", relationship="reports_to")

# Algorithms
ranks = pagerank(g)
costs = shortest_paths(g, "alice")
order = topological_sort(g)

Concepts

The package is built around a small set of typed primitives.

Concept What it is
Graph Property graph backed by petgraph::StableDiGraph. String-keyed nodes with JSON-valued properties; edges with arbitrary properties; multi-graph semantics opt-in. Stable node refs across mutations (additions/removals don't invalidate handles).
Node / Edge / Triple Typed dataclass results emitted at the FFI boundary. Node(id, properties), Edge(source, target, properties), Triple(subject, predicate, object).
Algorithms 40+ functions in kaos_graph.algorithms covering traversal (BFS/DFS, topological sort), shortest paths (Dijkstra, A*, Bellman-Ford, Floyd-Warshall), centrality (PageRank, betweenness, closeness, eigenvector), community (Louvain, label propagation), connectivity (SCC, weakly-connected, articulation points, bridges), structure (cycles, cliques, isomorphism, max flow), and DAG ops (longest path, critical path).
Sparse PageRank O((V+E)·n) instead of petgraph's O(V²·E·n). FOLIO ontology (~25K nodes, ~36K edges): 7 ms vs petgraph's 105 s. The marketing-grade benchmark exercised on every CI run.
RDF / SPARQL oxrdf + oxrdfio parsers (Turtle, N-Triples, N-Quads, RDF/XML, TriG) with byte / triple / size caps applied at the FFI boundary. SPARQL via pyoxigraph opt-in through the [rdf] extra.
I/O & bridges JSON (round-trippable), GraphML / GEXF (defusedxml-hardened), adjacency-list, mermaid, dot. kaos-content TabularDocument bridge available via the [tabular] extra.
Schema GraphSchema, NodeType, EdgeType, SchemaViolation for property-graph validation.
Storage VFS-backed save_to_vfs / load_from_vfs with name validation against namespace escape.

CLI

kaos-graph ships a kaos-graph administrative CLI plus an optional kaos-graph-serve MCP server (loopback-only by default):

kaos-graph version          # version info
kaos-graph serve            # forwards to kaos-graph-serve (stdio MCP)
kaos-graph-serve            # MCP server, stdio transport
kaos-graph-serve --http     # MCP server, streamable HTTP (loopback only)

Note: 17 MCP tools are registered by register_graph_tools() and are available with pip install "kaos-graph[mcp]>=0.1.0" (pulls in kaos-mcp).

Compatibility & status

Aspect
Python 3.13, 3.14 (informational matrix entries for 3.14t free-threaded and 3.15-dev). One cp313-abi3 wheel per OS/arch covers all 3.13+ minors.
OS Linux (manylinux + musllinux, x86_64 + aarch64), macOS arm64, Windows x86_64, Windows arm64. macOS x86_64 deliberately skipped (Apple ended Intel sales in 2023).
Maturity 0.1.0 GA. The top-level kaos_graph.__all__ documents the core types (Graph, Node, Edge, Triple, BfsNode, DfsEvent, __version__). The full public API is layered by subpackage and is documented in each subpackage's own __all__: kaos_graph.algorithms.__all__ (42 algorithm functions), kaos_graph.schema.__all__ (GraphSchema, NodeType, EdgeType, SchemaViolation), kaos_graph.io.__all__ (JSON, GraphML, GEXF, adjacency-list, mermaid, dot), kaos_graph.rdf.__all__ (RDF/SPARQL via the [rdf] extra), kaos_graph.knowledge.__all__, kaos_graph.tools.__all__ (MCP tools), and kaos_graph.errors.__all__. Import from the subpackage that owns the symbol (from kaos_graph.algorithms import pagerank, etc.).
Stability policy Pre-1.0: minor bumps may change behaviour. Every change is documented in CHANGELOG.md.
Test coverage 173 Rust unit tests + 402 Python tests passing (575 total). 38 dedicated security regressions covering the audit-pass A2 + two follow-up rounds.
Type checker Validated with ty, Astral's Python type checker.

Documentation

Per-package reference: docs/ in this repo.

Cross-cutting KAOS guides (agentic patterns, persona presets, settings policy, citations, MCP data flow, migration to 0.1.0 GA) live in kaos-modules/docs/guides/.

Companion packages

kaos-graph is one of the packages in the Kelvin Agentic OS. The broader stack:

Package Layer What it does
kaos-core Core Foundational runtime, MCP-native types, registries, execution engine, VFS
kaos-content Core Typed document AST: Block/Inline, provenance, views
kaos-mcp Bridge FastMCP server, kaos management CLI, MCP resource templates
kaos-pdf Extraction PDF → AST with provenance
kaos-web Extraction Web extraction, browser automation, search, domain intelligence
kaos-office Extraction DOCX / PPTX / XLSX readers + writers to AST
kaos-tabular Extraction DuckDB-powered SQL analytics
kaos-source Data Government + financial data connectors (Federal Register, eCFR, EDGAR, GovInfo, PACER, GLEIF)
kaos-llm-client LLM Multi-provider LLM transport
kaos-llm-core LLM Typed LLM programming (Signatures, Programs, Optimizers)
kaos-nlp-core Primitives (Rust) High-performance NLP primitives
kaos-nlp-transformers ML Dense embeddings + retrieval
kaos-graph Primitives (Rust) Graph algorithms + RDF/SPARQL
kaos-ml-core Primitives (Rust) Classical ML on the document AST
kaos-citations Legal Legal citation extraction, resolution, verification
kaos-agents Agentic Agent runtime, memory, recipes
kaos-reference Sample Reference module for module authors

Packages depend on kaos-core; everything else is opt-in. Mix and match the ones you need.

Development

git clone https://github.com/273v/kaos-graph
cd kaos-graph
uv sync --group dev --extra rdf
uv run maturin develop --release

Install pre-commit hooks (recommended — they run the same checks as CI on every commit, scoped to staged files):

uvx pre-commit install
uvx pre-commit run --all-files     # one-time full sweep

Manual QA commands (the same set CI runs):

cargo fmt --check
cargo clippy --no-default-features --all-targets -- -D warnings
cargo test --no-default-features --lib
uv run ruff format --check python/kaos_graph tests
uv run ruff check python/kaos_graph tests
uv run ty check python/kaos_graph tests
uv run pytest tests/

Build from source

uv build
uv pip install dist/*.whl

Contributing

Issues and pull requests are welcome. See CONTRIBUTING.md for setup, quality gates, pull request expectations, and engineering standards. By contributing you agree to follow the project conduct expectations and certify the Developer Certificate of Origin v1.1 — sign every commit with git commit -s. Please open an issue before starting on a non-trivial change so we can align on scope.

Security

For security issues, please do not file a public issue. Report privately via GitHub Private Vulnerability Reporting or email security@273ventures.com. See SECURITY.md for the full disclosure policy.

License

Apache License 2.0 — see LICENSE and NOTICE.

Copyright 2026 273 Ventures LLC. Built for kelvin.legal.

Release files for kaos-graph 0.1.6

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

Source distribution (sdist)

Source distribution for kaos-graph 0.1.6
File Size Uploaded
kaos_graph-0.1.6.tar.gz 268.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for kaos-graph 0.1.6
File
kaos_graph-0.1.6-cp313-abi3-win_arm64.whl CPython 3.13 abi3 Windows ARM64 Details
kaos_graph-0.1.6-cp313-abi3-win_amd64.whl CPython 3.13 abi3 Windows x86-64 Details
kaos_graph-0.1.6-cp313-abi3-manylinux_2_28_x86_64.whl CPython 3.13 abi3 Linux glibc 2.28+ x86-64 Details
kaos_graph-0.1.6-cp313-abi3-manylinux_2_28_aarch64.whl CPython 3.13 abi3 Linux glibc 2.28+ ARM64 Details
kaos_graph-0.1.6-cp313-abi3-macosx_11_0_arm64.whl CPython 3.13 abi3 macOS 11.0+ ARM64 Details

Total release size: 5.4 MB

Release files / kaos_graph-0.1.6.tar.gz

Download URL kaos_graph-0.1.6.tar.gz
Size 268.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4d6640afe972367e2d19c6ff0d13d484aba8ea792479da5ad37be499b0d19efb
BLAKE2b-256 checksum
How to use checksums
f4b0b379dc66385e57fb02edac41e348e875bcd31835e220a12ef88e263ee641
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / kaos_graph-0.1.6-cp313-abi3-win_arm64.whl

Download URL kaos_graph-0.1.6-cp313-abi3-win_arm64.whl
Size 962.8 kB
Tags CPython 3.13 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
69000489bc79bb414fa0dbf835b4582f020280daf55a041a149ebd403f33da1b
BLAKE2b-256 checksum
How to use checksums
9767c64fa3ef4d877dd2a4b564df66306526f7830c22eee234cd91882c186d57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / kaos_graph-0.1.6-cp313-abi3-win_amd64.whl

Download URL kaos_graph-0.1.6-cp313-abi3-win_amd64.whl
Size 1.0 MB
Tags CPython 3.13 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d6a29794e60bafe40820e69e4600c815176a932ae345cfdca136dbb57049b533
BLAKE2b-256 checksum
How to use checksums
4f8fe07441c1a8582dfffe6e30b17fadea5a9698cef7ba2647cf019b0c9d32cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / kaos_graph-0.1.6-cp313-abi3-manylinux_2_28_x86_64.whl

Download URL kaos_graph-0.1.6-cp313-abi3-manylinux_2_28_x86_64.whl
Size 1.1 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
88072e1374a2505b6b0b84a329b5cb608431aecf9eb0be741dc3a781d6b8c0c0
BLAKE2b-256 checksum
How to use checksums
a6273c78b96505fa093045a6d7566560a9e3d8aba12f14c8b59d6d9ef25fbd48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / kaos_graph-0.1.6-cp313-abi3-manylinux_2_28_aarch64.whl

Download URL kaos_graph-0.1.6-cp313-abi3-manylinux_2_28_aarch64.whl
Size 1.0 MB
Tags CPython 3.13 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
78e3c56608ef296f5216bde3ff1f52235c6d002b2f4ce8d374ea5f8f3942ef9f
BLAKE2b-256 checksum
How to use checksums
23c62aab2c25e6c03c5b97e0f474012b8e7dcbeb415c99c7eaa22a37167d63c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log

Release files / kaos_graph-0.1.6-cp313-abi3-macosx_11_0_arm64.whl

Download URL kaos_graph-0.1.6-cp313-abi3-macosx_11_0_arm64.whl
Size 1.0 MB
Tags CPython 3.13 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
73bb442493db79bffdb684111737d2e15f965e20b8573b5a34cc47e6e8dac693
BLAKE2b-256 checksum
How to use checksums
08f902c3379f574f96c1d1cd95b6d82d51662974f5774c8bc870e3034024c2b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 23, 2026.

Transparency log
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