Model Export Format¶
top level is a dict with one entry for each instance in the model
the key in this dict is the object reference handle
the value is the serialized instance
the serialized instance is a dict with three fields: type, attributes and relation.
type is the fully qualified name of the type
attributes is a dict, with as keys the names of the attributes and as values a dict with one entry.
- An attribute can have one or more of tree keys: unknows, nones and values. The “values” entry has as value a list with the attribute values.
If any of the values is Unknown or None, it is removed from the values array and the index at which it was removed is recorded in respective the unknowns or nones value
relations is like attributes, but the list of values contains the reference handles to which this relations points
Basic structure as pseudo jinja template
{
{% for instance in instances %}
'{{instance.handle}}':{
"type":"{{instance.type.fqn}}",
"attributes":[
{% for attribute in instance.attributes %}
"{{attribute.name}}": [ {{ attribute.values | join(",") }} ]
{% endfor %}
]
"relations" : [
{% for relation in instance.relations %}
"{{relation.name}}": [
{% for value in relation.values %}
{{value.handle}}
{% endfor %}
]
{% endfor %}
]
{% endif %}
}
Type Export Format¶
- class inmanta.model.Attribute(mytype: str, nullable: bool, multi: bool, comment: str, location: Location)[source]¶
Attribute defined on an entity
- Parameters:
mytype (str) – fully qualified name of the type of this attribute
nullable (bool) – can this attribute be null
multi (bool) – is this attribute a list
comment (str) – docstring for this attribute
location (inmanta.model.Location) – source location where this attribute is defined
- class inmanta.model.DirectValue(value: Value)[source]¶
A primitive value, directly represented in the serialized form.
- Parameters:
value – the value itself, as string or number
- class inmanta.model.Entity(parents: list[str], attributes: dict[str, Attribute], relations: dict[str, Relation], location: Location)[source]¶
An entity type
- Parameters:
parents (List[str]) – parent types
Attribute] (Dict[str,) – all attributes declared on this entity directly, by name
Relation] (Dict[str,) – all relations declared on this entity directly, by name
location (inmanta.model.Location) – source location this entity was defined at
- class inmanta.model.Location(file: str, lnr: int)[source]¶
Position in the source
- Parameters:
file (str) – source file name
lnr (int) – line in the source file
- class inmanta.model.ReferenceValue(reference)[source]¶
A reference to an instance of an entity.
- Parameters:
reference (str) – the handle for the entity this value refers to
- class inmanta.model.Relation(mytype: str, multi: tuple[int, int | None], reverse: str, comment: str, location: Location, source_annotations: list[Value], target_annotations: list[Value])[source]¶
A relation between two entities.
- Parameters:
mytype (str) – the type this relation refers to
multi (Tuple[int, int]) – the multiplicity of this relation in the form (lower,upper), -1 for unbounded
reverse (str) – the fully qualified name of the inverse relation
location (inmanta.model.Location) – source location this relation was defined at
source_annotations (List[Value]) – annotations on this relation on the source side
target_annotations (List[Value]) – annotations on this relation on the target side
- to_dict() dict[str, Any] [source]¶
Convert to serialized form:
{ "type": self.type, "multi": [self.multi[0], self.multi[1]], "reverse": self.reverse, "comment": self.comment, "location": self.location.to_dict(), "source_annotations": [x.to_dict() for x in self.source_annotations], "target_annotations": [x.to_dict() for x in self.target_annotations] }
- class inmanta.model.Value[source]¶
A value reference from a type either
DirectValue
orReferenceValue