Graph storage backends for TRUGS specifications — InMemory, PostgreSQL, JSON file persistence
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.
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
- 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: 0.1.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-0.1.0.tar.gz.
File metadata
- Download URL: trugs_store-0.1.0.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df2bed9a25978d4fd3ca10d3a77587147e2cdad183e67c07f95dbe1537d1160a
|
|
| MD5 |
adfc0cf3fbbd93a93bb7edce4ffafad2
|
|
| BLAKE2b-256 |
e835685585b09d419dfd27e54c31c3652af24f60d1781d8d76699ff0df4acaa5
|
File details
Details for the file trugs_store-0.1.0-py3-none-any.whl.
File metadata
- Download URL: trugs_store-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f34eba5ce6042a7b38775b28f7218ffe3caefc9165641d5054671ec6ed00437c
|
|
| MD5 |
dd84982ed67e75e8ba3ed82f018b69c2
|
|
| BLAKE2b-256 |
5e2ede0907aeaa9e3dfdce8afe5e3d153d09996e952f979b71232cbccc2a3919
|