Skip to content

inspect

relationalai.semantics

Inspect a PyRel model’s schema and rules without an engine connection.

A PyRel Model declares:

  • Concepts — entity types (e.g. Person, Order). Each concept can have identity properties (from identify_by=) and other properties (attributes). In the DSL, Property is a subclass of Relationship; both are represented as RelationshipInfo with is_property.
  • Relationships — multi-valued associations between concepts (Customer placed Order).
  • Tables — external table references (for example Snowflake tables) or temporary table-like objects backed by in-memory data (model.data([...])). TableInfo.loads shows which concepts a table populates; ConceptInfo.data_sources shows the reverse.
  • Enums — enumeration types (Priority: LOW, MEDIUM, HIGH).
  • Rulesdefine() and require() fragments registered on the model, exposed as RuleInfo with rendered text.

Standalone declarations (not owned by any concept) appear in bare_relationships on ModelSchema.

Example usage:

from relationalai.semantics import inspect
ms = inspect.schema(model)
print(ms) # human-readable summary
ms["Person"].identify_by # identity properties
ms["Person"].has_data # True if loaded from a table or model.data()
ms.defines # all define() rules as RuleInfo
ms.to_dict() # JSON-safe dictionary
concept = inspect.to_concept(Person.name) # resolve Chain -> Concept
refs = inspect.fields(Person.friends) # FieldRefs for select()

This module is read-only and frontend-level only — nothing is mutated and no compiler or engine connection is required.

For table-backed concepts (define(Concept.new(table.to_schema()))), identity properties only appear when identify_by= is passed to the Concept constructor:

Customer = m.Concept("Customer", identify_by={"C_CUSTKEY": Integer})
define(Customer.new(customer_tbl.to_schema()))

Without identify_by, all properties are reported as non-identity properties.

Example output of print(ms):

Model: scheduling
=================
Task
Identity:
id: Integer
Properties:
name: String
priority: Priority
Relationships:
Worker is assigned to Task
Data Sources:
db.tasks -> Task [ID: Integer, NAME: String, PRIORITY: String]
Standalone Declarations:
Task costs Float:cost
Enums:
Priority: LOW, MEDIUM, HIGH
Defines: (2 rules)
...
Requires: (1 rules)
...

Functions

Functions exposed by this module.

Classes

Classes exposed by this module.

Referenced By

RelationalAI Documentation
└──  Release Notes
    └──  Python API Release Notes
        └──  What’s New in Version 1.24.0
            └──  New Features and Enhancements