class documentation

class Schema:

Constructor: Schema(name, version)

View In Hierarchy

In-memory representation of a DataGraphs domain model schema.

Static Method create_from Create a Schema from a dictionary.
Method __init__ Create a new empty schema.
Method assign_baseclass Set or change the parent (base) class for an existing class.
Method assign_class_description Set or clear the description of a class.
Method assign_label_autogen Set an auto-generation pattern on the label property of a class.
Method assign_label_property Designate an existing property as the label property for a class.
Method assign_property_orders Reorder properties within classes.
Method clone Create a deep copy of the schema.
Method create_class Create a new class in the schema.
Method create_property Create a new property on a class.
Method create_subclass Create a subclass that inherits all properties from the parent class.
Method delete_class Delete a class from the schema.
Method delete_property Remove a property from a class.
Method find_class Find a class definition by name.
Method find_property Find a property by name within a list of property dicts.
Method find_subclasses Find all direct subclasses of a given class.
Method rename_property Rename a property.
Method to_dict Convert the schema to a plain dictionary.
Method to_json Serialise the schema to a JSON string.
Method update_class Update a class's name, description, or parent class.
Method update_property Update an existing property on a class.
Constant ALL_CLASSES Undocumented
Property classes The list of class definitions in the schema.
Property version The schema version string.
Static Method _is_legacy_format Detect whether a schema dict uses the legacy (old) format.
Method _assign_datatype Undocumented
Method _assign_enum Undocumented
Method _assign_inverse_of Undocumented
Method _assign_is_array Undocumented
Method _assign_is_filterable Undocumented
Method _assign_is_optional Undocumented
Method _assign_is_synonym Undocumented
Method _assign_property_description Undocumented
Method _delete_linked_properties Undocumented
Method _get_description_text Extract plain text from a description (handles both str and dict).
Method _is_valid_inverse_of Undocumented
Method _make_description Create a description dict in the new format.
Method _set_internal_schema Undocumented
Method _update_schema_metadata Undocumented
Method _validate_schema Undocumented
Instance Variable _schema Undocumented
Instance Variable _version Undocumented
@staticmethod
def create_from(data: dict, version: str = '') -> Self:

Create a Schema from a dictionary.

Automatically detects and converts legacy-format schemas.

Parameters
data:dictSchema dictionary (new or legacy format).
version:strSchema version override.
Returns
SelfA new Schema instance.
Raises
SchemaErrorIf the dict is missing required keys.
def __init__(self, name: str = '', version: str = ''):

Create a new empty schema.

Parameters
name:strModel name. Defaults to 'Domain Model' if empty.
version:strSchema version. Defaults to '1.0' if empty.
Raises
TypeErrorIf a dict is passed instead of keyword arguments.
def assign_baseclass(self, class_name: str, parent_class_name: str):

Set or change the parent (base) class for an existing class.

Parameters
class_name:strThe class to modify.
parent_class_name:strThe new parent class name.
Raises
ClassNotFoundErrorIf class_name does not exist.
def assign_class_description(self, class_name: str, description: str):

Set or clear the description of a class.

Parameters
class_name:strClass name.
description:strNew description. Pass an empty string to remove it.
Raises
ClassNotFoundErrorIf the class does not exist.
def assign_label_autogen(self, class_name: str, pattern: str):

Set an auto-generation pattern on the label property of a class.

Parameters
class_name:strClass name.
pattern:strAuto-generation expression.
Raises
ClassNotFoundErrorIf the class does not exist.
PropertyNotFoundErrorIf the label property does not exist.
def assign_label_property(self, class_name: str, prop_name: str, is_lang_string: bool = True):

Designate an existing property as the label property for a class.

The property is also marked as required (isOptional=False).

Parameters
class_name:strClass name.
prop_name:strProperty name to use as the label.
is_lang_string:boolWhether the label supports multiple languages.
Raises
ClassNotFoundErrorIf the class does not exist.
PropertyNotFoundErrorIf the property does not exist on the class.
def assign_property_orders(self, property_orders: dict):

Reorder properties within classes.

Properties not listed in the order are appended at the end.

Parameters
property_orders:dictA dict mapping class names to ordered lists of property names.
def clone(self) -> Self:

Create a deep copy of the schema.

Returns
SelfA new independent Schema instance.
def create_class(self, class_name: str, description: str = '', parent_class_name: str = '', label_prop_name: str = 'label', is_label_prop_lang_string: bool = True):

Create a new class in the schema.

Parameters
class_name:strName of the new class.
description:strHuman-readable description.
parent_class_name:strName of the parent class (for inheritance).
label_prop_name:strName of the label property created by default.
is_label_prop_lang_string:boolWhether the label property supports multiple languages.
Raises
SchemaErrorIf a class with the same name already exists.
def create_property(self, class_name: str, prop_name: str, datatype: DATATYPE | str, description: str = '', is_optional: bool = True, is_array: bool = False, is_nested: bool = False, is_lang_string: bool = True, inverse_of: str = '', enums: list | None = None, is_synonym: bool = False, is_filterable: bool = False, apply_to_subclasses: bool = False):

Create a new property on a class.

Parameters
class_name:strClass to add the property to.
prop_name:strProperty name.
datatype:DATATYPE | strA DATATYPE enum value for primitive types, or a class name string for object (relationship) properties.
description:strHuman-readable description.
is_optional:boolWhether the property is optional.
is_array:boolWhether the property holds multiple values.
is_nested:boolWhether an object property is nested (embedded).
is_lang_string:boolFor text properties, whether to support multiple languages.
inverse_of:strName of the inverse property on the target class (object properties only).
enums:list | NoneAllowed values for DATATYPE.ENUM properties.
is_synonym:boolWhether this property is a label synonym.
is_filterable:boolWhether the property is available as a facet/filter.
apply_to_subclasses:boolIf True, also creates the property on all existing subclasses.
Raises
ClassNotFoundErrorIf the class (or referenced class) does not exist.
PropertyExistsErrorIf a property with the same name already exists.
InvalidInversePropertyErrorIf the inverse property specification is invalid.
def create_subclass(self, class_name: str, description: str, parent_class_name: str):

Create a subclass that inherits all properties from the parent class.

Parameters
class_name:strName of the new subclass.
description:strDescription for the subclass.
parent_class_name:strName of the parent class to inherit from.
Raises
ClassNotFoundErrorIf the parent class does not exist.
def delete_class(self, class_name: str, include_linked_properties: bool = False, cascade_to_subclasses: bool = True):

Delete a class from the schema.

Parameters
class_name:strName of the class to delete.
include_linked_properties:boolIf True, also removes ObjectProperties on other classes that reference this class.
cascade_to_subclasses:boolIf True, removes subClassOf links from any subclasses of the deleted class.
Raises
ClassNotFoundErrorIf the class does not exist.
def delete_property(self, class_name: str, prop_name: str):

Remove a property from a class.

Parameters
class_name:strClass containing the property.
prop_name:strProperty name to delete.
Raises
ClassNotFoundErrorIf the class does not exist.
PropertyNotFoundErrorIf the property does not exist.
def find_class(self, name: str) -> dict | None:

Find a class definition by name.

Parameters
name:strThe class name to look up.
Returns
dict | NoneThe class dict, or None if not found.
def find_property(self, props: list, name: str) -> dict | None:

Find a property by name within a list of property dicts.

Parameters
props:listList of property dicts to search.
name:strThe property name to look up.
Returns
dict | NoneThe property dict, or None if not found.
def find_subclasses(self, baseclass: str) -> list[dict]:

Find all direct subclasses of a given class.

Parameters
baseclass:strThe parent class name.
Returns
list[dict]A list of class dicts whose subClassOf matches baseclass.
def rename_property(self, class_name: str, old_prop_name: str, new_prop_name: str):

Rename a property.

If the property is the class's label property, the label property reference is updated automatically.

Parameters
class_name:strClass containing the property.
old_prop_name:strCurrent property name.
new_prop_name:strNew property name.
Raises
ClassNotFoundErrorIf the class does not exist.
PropertyNotFoundErrorIf old_prop_name does not exist.
PropertyExistsErrorIf new_prop_name is already in use.
def to_dict(self) -> dict:

Convert the schema to a plain dictionary.

Returns
dictThe schema as a dict.
def to_json(self) -> str:

Serialise the schema to a JSON string.

Returns
strA JSON-formatted string.
def update_class(self, class_name: str, new_name: str = '', new_description: str = '', parent_class_name: str = ''):

Update a class's name, description, or parent class.

Parameters
class_name:strCurrent class name.
new_name:strNew class name, or empty to leave unchanged.
new_description:strNew description, or empty to leave unchanged.
parent_class_name:strNew parent class. Empty string removes the parent.
Raises
ClassNotFoundErrorIf the class does not exist.
def update_property(self, class_name: str, prop_name: str, datatype: DATATYPE | str = None, description: str = None, is_optional: bool = None, is_array: bool = None, is_nested: bool = None, is_lang_string: bool = None, inverse_of: str = '', enums: list | None = None, is_synonym: bool = False, is_filterable: bool = None, apply_to_subclasses: bool = None):

Update an existing property on a class.

Only parameters that are explicitly provided (non-None) will be changed.

Parameters
class_name:strClass containing the property.
prop_name:strProperty name to update.
datatype:DATATYPE | strNew data type.
description:strNew description.
is_optional:boolWhether the property is optional.
is_array:boolWhether the property holds multiple values.
is_nested:boolWhether an object property is nested.
is_lang_string:boolWhether the property supports multiple languages.
inverse_of:strName of the inverse property on the target class.
enums:list | NoneAllowed enumeration values.
is_synonym:boolWhether this property is a label synonym.
is_filterable:boolWhether the property is available as a filter.
apply_to_subclasses:boolIf True, also updates the property on all existing subclasses.
Raises
ClassNotFoundErrorIf the class does not exist.
PropertyNotFoundErrorIf the property does not exist.
ALL_CLASSES: str =

Undocumented

Value
'__all_classes__'
@property
classes: list[dict] =

The list of class definitions in the schema.

@property
version: str =

The schema version string.

@staticmethod
def _is_legacy_format(schema: dict) -> bool:

Detect whether a schema dict uses the legacy (old) format.

def _assign_datatype(self, prop_def: dict, datatype: DATATYPE | str, is_nested: bool = False, is_lang_string: bool = True):

Undocumented

def _assign_enum(self, prop_def: dict, datatype: DATATYPE | str, enums: list):

Undocumented

def _assign_inverse_of(self, prop_def: dict, class_name: str, inverse_of: str, datatype: DATATYPE | str):

Undocumented

def _assign_is_array(self, prop_def: dict, is_array: bool = False):

Undocumented

def _assign_is_filterable(self, prop_def: dict, is_filterable: bool):

Undocumented

def _assign_is_optional(self, prop_def: dict, is_optional: bool = False):

Undocumented

def _assign_is_synonym(self, prop_def: dict, is_synonym: bool):

Undocumented

def _assign_property_description(self, prop_def: dict, description: str):

Undocumented

def _delete_linked_properties(self, class_name: str):

Undocumented

def _get_description_text(self, desc: str | dict) -> str:

Extract plain text from a description (handles both str and dict).

def _is_valid_inverse_of(self, class_name: str, inverse_of: str, datatype: DATATYPE | str) -> bool:

Undocumented

def _make_description(self, text: str) -> dict:

Create a description dict in the new format.

def _set_internal_schema(self, data: dict, version: str):

Undocumented

def _update_schema_metadata(self, name: str = '', version: str = ''):

Undocumented

def _validate_schema(self, schema: dict):

Undocumented

_schema =

Undocumented

_version =

Undocumented