Hydra SDK
Python interface to the Dominir data layer. Rust-native scan engine, zero-copy Arrow interchange, ontology-validated writes, and in-memory graph traversal.
Exports
HydraStore
Constructor
No arguments needed inside Dominir. repo_root is only for external use.
Properties
| Property | Type | Description |
|---|---|---|
default_store | str | None | Get/set the workspace scope. Writable. |
store_ids | list[str] | All store IDs in storage/fragments/. |
model_names | list[str] | All model names from the ontology. |
Reading Data
store.scan()
All filters are AND-combined. Filtering executes in Rust during the scan — never post-hoc in Python.
| Parameter | Matches |
|---|---|
object_key | Schema type. Accepts raw keys (person_Instance) or model names (Person). |
instance_id | Exact instance ID (Pe-00-a3bX9k). |
of_branch | Leaf branch name (Gender, GivenName). |
value_str | Exact leaf value string. |
Store scoping:
store_id | default_store | Scans |
|---|---|---|
"Demo" | any | Demo only |
None | "Demo" | Demo only |
None | None | All stores |
store.scan_all()
Same filters as scan(). Ignores default_store — always scans every store.
store.scan_json()
Same as scan() but returns list[dict] instead of InstanceFrame.
Writing Data
store.write_instance()
petioles is a flat {slot_name: value} dict:
Returns a ValidationReport:
| Key | Type | Description |
|---|---|---|
success | bool | True if no hard errors. |
canonical_count | int | Petioles written to the primary index. |
shadow_petioles | list[str] | Slots not in the ontology (written with shadow:: prefix). |
errors | list[dict] | Validation errors. Each has a type key. |
Raises:
| Exception | When |
|---|---|
HydraMissingField | Required petiole absent or unknown object_key. |
HydraTypeMismatch | Cardinality constraint violated. |
HydraLockTimeout | Write lock not acquired within 5 seconds. |
HydraInvalidID | Manual instance_id doesn't match HydraID format. |
store.validate_write()
Dry-run validation. Same return as write_instance() but no disk I/O.
InstanceFrame
Thin wrapper around pyarrow.Table. All filtering returns a new frame (chainable).
| Member | Returns | Description |
|---|---|---|
table | pa.Table | Underlying Arrow table (zero-copy). |
types | list[str] | Unique instance types in the frame. |
to_pandas() | DataFrame | Convert to Pandas. Auto-parses JSON columns. |
to_dicts() | list[dict] | Rows as plain Python dicts. |
filter_type(t) | InstanceFrame | Keep rows where instance_type == t. |
filter_id(id) | InstanceFrame | Keep rows where instance_id == id. |
len(frame) | int | Row count. |
Columns
| Column | Type | Content |
|---|---|---|
instance_type | str | Model name (Person, Case). |
instance_id | str | Unique ID (Pe-00-FQiher). |
version | int64 | Monotonic version counter. |
timestamp | str (nullable) | ISO-8601 write timestamp. |
leaf_values | str (JSON) | {slot: {ofBranch, values: [...]}} |
petiole_order | str (JSON) | Ordered list of slot names. |
In the raw Arrow table,
leaf_valuesandpetiole_orderare UTF-8 strings containing JSON. Onlyto_pandas()andto_dicts()inflate them into Python objects.
leaf_values structure
Each instance's leaf_values is a nested dict:
Tidy Helpers
hoist()
Extracts the first value from each slot. Returns a pyarrow.Table (zero-copy where possible).
to_chart_df()
Equivalent to hoist(...).to_pandas().
HydraGraph
In-memory graph with BFS/DFS traversal. Nodes are instances keyed as ModelName-InstanceId. Edges are derived from cross-reference leaf values in the ontology.
Building
graph.traverse()
Root key formats:
| Format | Example | Seeds |
|---|---|---|
ModelName-InstanceId | "Person-Pe-00-abc" | Single instance at depth 0. |
leaf::Branch::Value | "leaf::Gender::Female" | All instances with that value at depth 1. |
type::ModelName | "type::Person" | All instances of that type at depth 0. |
TraverseResult
| Field | Type | Description |
|---|---|---|
algo | str | "bfs" or "dfs". |
start_key | str | The root key used. |
max_depth | int | Depth limit applied. |
levels | dict[str, int] | Node key → depth from root. |
order | list[str] | Keys in visit order. |
edges | list[tuple[str, str]] | Undirected (source, target) pairs. |
instances | list[dict] | Full instance data for each node. |
Schema Introspection
| Method | Returns |
|---|---|
store.model_names | All model names from the ontology (list[str]). |
store.validate_write(object_key, petioles) | Validation report with errors for missing/invalid slots. |
For full slot-level schema: call the hydra_schema agent tool with object_key="person_Instance".
HydraID
Structured 12-character identifier: Pe-NB-FQiher.
Pe-NB-FQiher
│ │ └── 6-char base62 suffix (timestamp + entropy, 35 bits)
│ └────── 2-char batch prefix (write source provenance)
└────────── 2-char type prefix (from ontology id_prefix)
| Batch ID | Source |
|---|---|
00 | Default / unspecified |
NB | Notebook |
AI | Agent |
AP | API / backend |
MG | Data migration |
Exceptions
| Exception | Raised when |
|---|---|
HydraMissingField | Required petiole absent, or object_key unknown. |
HydraTypeMismatch | Cardinality constraint violated. |
HydraLockTimeout | Write lock not acquired within 5 s (another writer active). |
HydraInvalidID | Manual instance_id not in HydraID format. |
All are raised from Rust before any disk mutation.
Shadow Petioles
Slots not in the ontology are stored with a shadow::ModelName branch prefix.
Agent Mode
When running under an agent context, store is a read-only proxy. Write attempts raise PermissionError. Agents write via the hydra_write tool, which goes through the policy engine for human approval.