Skip to main content

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

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)

Source distribution for trugs-store 2.1.0
File Size Uploaded
trugs_store-2.1.0.tar.gz 53.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trugs-store 2.1.0
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.0

2 release files

0.1.0

2 release files

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