Model Export Format

  1. top level is a dict with one entry for each instance in the model
  2. the key in this dict is the object reference handle
  3. the value is the serialized instance
  4. the serialized instance is a dict with three fields: type, attributes and relation.
  5. type is the fully qualified name of the type
  6. attributes is a dict, with as keys the names of the attributes and as values a dict with one entry.
  7. 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
  8. 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

Copyright 2018 Inmanta

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contact: code@inmanta.com

class inmanta.model.Attribute(mytype: str, nullable: bool, multi: bool, comment: str, location: inmanta.model.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 (Location) – source location where this attribute is defined
to_dict()[source]

Convert to serialized form:

{
    "type": self.type,
    "multi": self.multi,
    "nullable": self.nullable,
    "comment": self.comment,
    "location": self.location.to_dict()
}
class inmanta.model.DirectValue(value)[source]

A primitive value, directly represented in the serialized form.

Parameters:value – the value itself, as string or number
to_dict()[source]

Convert to serialized form:

{"value": self.value}
class inmanta.model.Entity(parents: List[str], attributes: Dict[str, inmanta.model.Attribute], relations: Dict[str, inmanta.model.Relation], location: inmanta.model.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 (Location) – source location this entity was defined at
to_dict()[source]

Convert to serialized form:

{
"parents": self.parents,
"attributes": {n: a.to_dict() for n, a in self.attributes.items()},
"relations": {n: r.to_dict() for n, r in self.relations.items()},
"location": self.location.to_dict(),
}
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
to_dict()[source]

Convert to serialized form:

{
    "file": self.file,
    "lnr": self.lnr
}
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
to_dict()[source]

Convert to serialized form:

{"reference": self.reference}
class inmanta.model.Relation(mytype: str, multi: Tuple[int, int], reverse: str, comment: str, location: inmanta.model.Location, source_annotations: List[inmanta.model.Value], target_annotations: List[inmanta.model.Value])[source]

A relation between two entities.

Parameters:
  • mytype (str) – the type this relation refers to
  • int] multi (Tuple[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 (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()[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 or ReferenceValue