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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trugs_store-2.1.0.tar.gz (53.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trugs_store-2.1.0-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

File details

Details for the file trugs_store-2.1.0.tar.gz.

File metadata

  • Download URL: trugs_store-2.1.0.tar.gz
  • Upload date:
  • Size: 53.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for trugs_store-2.1.0.tar.gz
Algorithm Hash digest
SHA256 43fb5516fcb8bcff1e177be97c3184af4ffae233568011cb3520d1f759943853
MD5 b48fe45f51a4ada9ac5c4ed077da5cfd
BLAKE2b-256 6f9eac4962d5af2bb09d3a762463259eda12726c2ae1c261895a3b33f425d4c8

See more details on using hashes here.

File details

Details for the file trugs_store-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: trugs_store-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for trugs_store-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2636a8b4ba33ac67930c40d5045005a39e7e115da7cd923ef6508dcfc46cfe1
MD5 f175b86297b2522e3d3ad23058d1c822
BLAKE2b-256 64586f95491b45c3b2f9f7f549fa7b4c7353c3775bcb42028f9c4dea5c3af14d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page