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) load and save as before; since 2.2.0, validation also reports hierarchy cycles that 2.1.0 missed, in graphs of either version.
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("trugs_store_folder", 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.2.0 (TRUGS 2.0 native — core_v2.0.0 support)
Phase: Beta
License: Apache 2.0 — TRUGS LLC
Metadata
Release files for trugs-store 2.2.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 | Provenance | |
|---|---|---|---|---|
| trugs_store-2.2.0.tar.gz | 58.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| trugs_store-2.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 92.8 kB
Release files / trugs_store-2.2.0.tar.gz
| Download URL | trugs_store-2.2.0.tar.gz |
|---|---|
| Size | 58.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
29ef77c487f868054fef204a4c2a75bc305ad7e256a15f0f6fa272400f4d7bd0
|
|
BLAKE2b-256 checksum How to use checksums |
5d3f5668ebec90e80bb71cb8c15c54dfce211aba8f834b392cd89a1df57ff561
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / trugs_store-2.2.0-py3-none-any.whl
| Download URL | trugs_store-2.2.0-py3-none-any.whl |
|---|---|
| Size | 34.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f831795a9f58a3c66c13151572cf05cd90951d4fe24639669875bcfef0a0bab3
|
|
BLAKE2b-256 checksum How to use checksums |
6947f2095b0ab7e5e14a47f2dab3d5bb8db974ed9a835ce3310e0abd21d6dd9d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Security for trugs-store 2.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.