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:
src/trugs_store/protocol.py— full PEP 544 interface (22 methods) - 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
Metadata
Release files for trugs-store 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| trugs_store-2.1.0.tar.gz | 53.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| trugs_store-2.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 83.0 kB
Release files / trugs_store-2.1.0.tar.gz
| Download URL | trugs_store-2.1.0.tar.gz |
|---|---|
| Size | 53.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
43fb5516fcb8bcff1e177be97c3184af4ffae233568011cb3520d1f759943853
|
|
BLAKE2b-256 checksum How to use checksums |
6f9eac4962d5af2bb09d3a762463259eda12726c2ae1c261895a3b33f425d4c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / trugs_store-2.1.0-py3-none-any.whl
| Download URL | trugs_store-2.1.0-py3-none-any.whl |
|---|---|
| Size | 29.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2636a8b4ba33ac67930c40d5045005a39e7e115da7cd923ef6508dcfc46cfe1
|
|
BLAKE2b-256 checksum How to use checksums |
64586f95491b45c3b2f9f7f549fa7b4c7353c3775bcb42028f9c4dea5c3af14d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|