Graph storage backends for TRUGS specifications — InMemory, PostgreSQL, JSON file persistence. Native TRUGS 2.0 (core_v2.0.0) support: LEVEL_PREFIX hierarchy validation, inheritance stamping, canonical re-emit.
Project description
trugs-store
Graph storage backends for TRUGS specifications — InMemory, PostgreSQL, JSON file persistence.
trugs-store is the shared persistence layer for all TRUGS tooling. Every tool that reads or writes .trug.json files goes through this package. It supports JSON file storage for development and PostgreSQL for production scale.
As of 2.0.0, trugs-store natively supports TRUGS 2.0 (core_v2.0.0): vocabulary dispatch on a TRUG's declared capabilities.vocabularies, LEVEL_PREFIX hierarchy validation, inheritance stamping, and canonical re-emit on save. v1 TRUGs (core_v1.0.0, project_v1) continue to validate unchanged — the upgrade is purely additive.
Install
pip install trugs-store
# With PostgreSQL support:
pip install trugs-store[postgres]
Quick Example
from trugs_store import InMemoryGraphStore, JsonFilePersistence
# Load a .trug.json file
persistence = JsonFilePersistence()
store = persistence.load("folder.trug.json")
# Query
print(store.node_count())
print(store.find_nodes(type="FUNCTION"))
# Validate against TRUGS CORE rules
violations = store.validate_graph()
for v in violations:
print(f"{v.severity}: {v.rule} — {v.message}")
Architecture
| Component | What it does |
|---|---|
GraphStore protocol |
PEP 544 structural interface — 22 methods across 8 categories |
InMemoryGraphStore |
Dict-backed store — O(1) node lookup, O(degree) edge access |
PostgresGraphStore |
SQL-backed store — indexed queries, transactional writes, COPY bulk insert |
JsonFilePersistence |
Load/save .trug.json files to/from InMemoryGraphStore |
PostgresPersistence |
Load/save graphs to/from PostgreSQL |
| Dual-write bridge | write_trug() / read_trug() — writes JSON + optionally PostgreSQL |
Basic Usage
Load and query a TRUG
from trugs_store import JsonFilePersistence
p = JsonFilePersistence()
store = p.load("folder.trug.json")
# Find all FUNCTION nodes
functions = store.find_nodes(type="FUNCTION")
# Traverse outgoing edges from a node
for node, edge, depth in store.traverse("root", direction="outgoing", max_depth=2):
print(f" {' ' * depth}{node['id']} via {edge['relation']}")
Create a graph in memory
from trugs_store import InMemoryGraphStore
store = InMemoryGraphStore()
store.set_metadata("name", "my_graph")
store.set_metadata("version", "1.0.0")
store.add_node({"id": "root", "type": "FOLDER", "properties": {},
"parent_id": None, "contains": [], "metric_level": "KILO_FOLDER",
"dimension": "main"})
store.add_node({"id": "child", "type": "DOCUMENT", "properties": {},
"parent_id": None, "contains": [], "metric_level": "BASE_DOCUMENT",
"dimension": "main"}, parent_id="root")
store.add_edge({"from_id": "root", "to_id": "child", "relation": "REFERENCES"})
print(store.node_count()) # 2
print(store.get_children("root")) # [child node]
Validate a graph
violations = store.validate_graph()
if violations:
for v in violations:
print(f"{v.severity}: {v.rule} on {v.node_id} — {v.message}")
else:
print("Graph is valid.")
Documentation
- Package boundary: BOUNDARY.md — what STORE owns vs what TRUGS-TOOLS owns, and the deliberate two-validator split (structural vs CORE-16)
- TRUGS Specification: TRUGS-LLC/TRUGS — protocol, language, validator
- GraphStore Protocol: SPEC_844_graphstore_protocol.py — full PEP 544 interface
- TRUG Graph Index: folder.trug.json — machine-readable structure of this repo
- Dark Code Standard: TRUGS-LLC/TRUGS/REFERENCE/STANDARD_dark_code_compliance.md
Status
Version: 2.0.0 (TRUGS 2.0 native — first release with core_v2.0.0 support; lockstep with trugs-tools/trugs-folder 2.0.0)
Phase: Beta
License: Apache 2.0 — TRUGS LLC
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trugs_store-2.0.0.tar.gz.
File metadata
- Download URL: trugs_store-2.0.0.tar.gz
- Upload date:
- Size: 52.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c7f5665ad5397b0be97c75a53b23e9f88590e0133d6bd19879cd00e686bd917
|
|
| MD5 |
0d0f870c5f77526c5de0d4119eeca04e
|
|
| BLAKE2b-256 |
63b49f00a5417cdfe1f76a69387bb290fb3eed943fc2c15a29d1554f5c621f1a
|
File details
Details for the file trugs_store-2.0.0-py3-none-any.whl.
File metadata
- Download URL: trugs_store-2.0.0-py3-none-any.whl
- Upload date:
- Size: 28.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f15517093871a9e16aed67b3f01f5336a6118162ee65c593d64154199fc09ca2
|
|
| MD5 |
04fbb8e3f3a0a25b088716b02001677c
|
|
| BLAKE2b-256 |
41ce8e37a717d3a1053f8c7949d712c66b4305a34b8388433b717a77c5e9f058
|