yams package

Submodules

yams.buildobjs module

Classes used to build a schema.

class yams.buildobjs.EntityType(name: Optional[str] = None, **kwargs)

Bases: yams.buildobjs.Definition

classmethod add_relation(relation_definition: yams.buildobjs.ObjectRelation, name: Optional[str] = None) → Callable
classmethod expand_relation_definitions(defined: Dict[Union[str, Tuple[str, str, str]], Union[autopackage, Definition]], schema: Schema) → None

schema building step 2:

register all relations definition, expanding wildcards if necessary

classmethod expand_type_definitions(defined: Dict[Union[str, Tuple[str, str, str]], Union[autopackage, Definition]]) → None

Schema building step 1: register definition objects by adding them to the defined dictionnary.

classmethod extend(other_meta_definition_class) → None

add all relations of other_meta_definition_class to the current class

classmethod get_relation(name: str) → yams.buildobjs.ObjectRelation

Return relation definitions by name. Fails if there is multiple one.

classmethod get_relations(name: str) → Generator[yams.buildobjs.ObjectRelation, Any, None]

Iterate over relations definitions that match the name parameters

It may iterate multiple definitions when the class is both object and sujet of a relation:

classmethod insert_relation_after(after_relation_name: str, name: str, relation_definition: yams.buildobjs.ObjectRelation) → Callable
package = '<builtin>'
classmethod remove_relation(name: str) → None

Remove relation from the class

specialized_by
class yams.buildobjs.RelationType(name: Optional[str] = None, **kwargs)

Bases: yams.buildobjs.Definition

classmethod expand_relation_definitions(defined: Dict[Union[str, Tuple[str, str, str]], Union[autopackage, Definition]], schema: Schema) → None

schema building step 2:

register all relations definition, expanding wildcard if necessary

classmethod expand_type_definitions(defined: Dict[Union[str, Tuple[str, str, str]], Union[autopackage, Definition]]) → None

schema building step 1:

register definition objects by adding them to the defined dictionnary

fulltext_container = <nullobject>
inlined = <nullobject>
package = '<builtin>'
rule = <nullobject>
symmetric = <nullobject>
class yams.buildobjs.RelationDefinition(subject: Optional[str] = None, name: Optional[str] = None, object: Optional[str] = None, package: Optional[str] = None, **kwargs)

Bases: yams.buildobjs.Definition

cardinality = <nullobject>
constraints = <nullobject>
classmethod expand_relation_definitions(defined: Dict[Union[str, Tuple[str, str, str]], Union[autopackage, Definition]], schema: Schema) → None

schema building step 2:

register all relations definition, expanding wildcard if necessary

classmethod expand_type_definitions(defined: Dict[Union[str, Tuple[str, str, str]], Union[autopackage, Definition]]) → None

schema building step 1:

register definition objects by adding them to the defined dictionnary

formula = <nullobject>
inlined = <nullobject>
object = <nullobject>
package = '<builtin>'
subject = <nullobject>
symmetric = <nullobject>
class yams.buildobjs.SubjectRelation(entity_type: str, override: bool = False, **kwargs)

Bases: yams.buildobjs.ObjectRelation

default = <nullobject>
fulltextindexed = <nullobject>
indexed = <nullobject>
internationalizable = <nullobject>
uid = <nullobject>
class yams.buildobjs.ObjectRelation(entity_type: str, override: bool = False, **kwargs)

Bases: object

cardinality = <nullobject>
constraints = <nullobject>
etype
yams.buildobjs.RichString(default_format: str = 'text/plain', format_constraints: Optional[List[yams.constraints.BaseConstraint]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

RichString is a convenience attribute type for attribute containing text in a format that should be specified in another attribute.

The following declaration:

class Card(EntityType):
    content = RichString(fulltextindexed=True, default_format='text/rest')

is equivalent to:

class Card(EntityType):
    content_format = String(internationalizable=True,
                            default='text/rest', constraints=[FORMAT_CONSTRAINT])
    content  = String(fulltextindexed=True)
class yams.buildobjs.BigInt(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'BigInt'
class yams.buildobjs.Boolean(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'Boolean'
class yams.buildobjs.TZDatetime(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'TZDatetime'
class yams.buildobjs.Datetime(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'Datetime'
class yams.buildobjs.Password(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'Password'
class yams.buildobjs.Decimal(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'Decimal'
class yams.buildobjs.Time(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'Time'
class yams.buildobjs.TZTime(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'TZTime'
class yams.buildobjs.Int(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'Int'
class yams.buildobjs.Bytes(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'Bytes'
class yams.buildobjs.Interval(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'Interval'
class yams.buildobjs.String(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'String'
class yams.buildobjs.Float(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'Float'
class yams.buildobjs.Date(metadata: Optional[Dict[str, AbstractTypedAttribute]] = None, required: bool = False, maxsize: Optional[int] = None, formula=<nullobject>, vocabulary: Optional[List[str]] = None, unique: Optional[bool] = None, override: bool = False, **kwargs)

Bases: yams.buildobjs.AbstractTypedAttribute

entity_type = 'Date'

yams.constraints module

Some common constraint classes.

class yams.constraints.Attribute(attr)

Bases: object

value(entity) → Any
class yams.constraints.BaseConstraint(msg: Optional[str] = None)

Bases: object

base class for constraints

check_consistency(subjschema: EntitySchema, objschema: EntitySchema, rdef: RelationDefinition) → None
classmethod deserialize(value: str) → Any

called to restore serialized data of a constraint. Should return a cls instance

failed_message(key: str, value, entity=None) → Tuple[Optional[str], Dict[str, Any]]
serialize() → str

called to make persistent valuable data of a constraint

type() → str
class yams.constraints.BoundaryConstraint(op: str, boundary: Union[Attribute, NOW, TODAY, None] = None, msg=None)

Bases: yams.constraints.BaseConstraint

the int/float bound constraint :

set a minimal or maximal value to a numerical value

check(entity, rtype: RelationType, value) → bool

return true if the value satisfies the constraint, else false

check_consistency(subjschema: EntitySchema, objschema: EntitySchema, rdef: RelationDefinition) → None
classmethod deserialize(value: str) → yams.constraints.BoundaryConstraint

simple text deserialization

serialize() → str

simple text serialization

class yams.constraints.ConstraintJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: json.encoder.JSONEncoder

default(obj: Union[Any, NOW, TODAY]) → Union[Any, dict]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class yams.constraints.FormatConstraint(msg: Optional[str] = None, **kwargs)

Bases: yams.constraints.StaticVocabularyConstraint

check_consistency(subjschema: EntitySchema, objschema: EntitySchema, rdef: RelationDefinition) → None
regular_formats = ('text/rest', 'text/markdown', 'text/html', 'text/plain')
class yams.constraints.IntervalBoundConstraint(minvalue: Union[int, float, None] = None, maxvalue: Union[int, float, None] = None, msg: Optional[str] = None)

Bases: yams.constraints.BaseConstraint

an int/float bound constraint :

sets a minimal and / or a maximal value to a numerical value This class replaces the BoundConstraint class

check(entity, rtype: RelationType, value: Union[int, float]) → bool
check_consistency(subjschema: EntitySchema, objschema: EntitySchema, rdef: RelationDefinition) → None
classmethod deserialize(value: str) → yams.constraints.IntervalBoundConstraint

simple text deserialization

serialize() → str

simple text serialization

class yams.constraints.MultipleStaticVocabularyConstraint(values: Sequence[str], msg: Optional[str] = None)

Bases: yams.constraints.StaticVocabularyConstraint

Enforce a list of values to be in a predefined set vocabulary.

check(entity, rtype: RelationType, values: Sequence[str]) → bool

return true if the values satisfy the constraint, else false

class yams.constraints.NOW(offset: Optional[datetime.timedelta] = None)

Bases: object

value(entity) → datetime.date
class yams.constraints.RegexpConstraint(regexp: str, flags: int = 0, msg: Optional[str] = None)

Bases: yams.constraints.BaseConstraint

specifies a set of allowed patterns for a string value

check(entity, rtype: RelationType, value: str) → Optional[Match[str]]

return true if the value maches the regular expression

check_consistency(subjschema: EntitySchema, objschema: EntitySchema, rdef: RelationDefinition) → None
classmethod deserialize(value: str) → yams.constraints.RegexpConstraint

simple text deserialization

serialize() → str

simple text serialization

class yams.constraints.SizeConstraint(max: Optional[int] = None, min: Optional[int] = None, msg: Optional[str] = None)

Bases: yams.constraints.BaseConstraint

the string size constraint :

if max is not None the string length must not be greater than max if min is not None the string length must not be shorter than min

check(entity, rtype: RelationType, value: Sequence[T_co]) → bool

return true if the value is in the interval specified by self.min and self.max

check_consistency(subjschema: EntitySchema, objschema: EntitySchema, rdef: RelationDefinition) → None
classmethod deserialize(value: str) → yams.constraints.SizeConstraint

simple text deserialization

serialize() → str

simple text serialization

class yams.constraints.StaticVocabularyConstraint(values: Sequence[str], msg: Optional[str] = None)

Bases: yams.constraints.BaseConstraint

Enforces a predefined vocabulary set for the value.

check(entity, rtype: RelationType, value: str) → bool

return true if the value is in the specific vocabulary

classmethod deserialize(value: str) → yams.constraints.StaticVocabularyConstraint

deserialize possible values from a csv list of evaluable strings

serialize() → str

serialize possible values as a json object

vocabulary(**kwargs) → Tuple[str, ...]

return a list of possible values for the attribute

class yams.constraints.TODAY(offset: Optional[datetime.timedelta] = None, type: str = 'Date')

Bases: object

value(entity) → datetime.date
class yams.constraints.UniqueConstraint(msg: Optional[str] = None)

Bases: yams.constraints.BaseConstraint

object of relation must be unique

check(entity, rtype: RelationType, values) → bool

return true if the value satisfy the constraint, else false

check_consistency(subjschema: EntitySchema, objschema: EntitySchema, rdef: RelationDefinition) → None
yams.constraints.actual_value(value, entity) → Any
yams.constraints.check_boolean(eschema, value) → bool

check value is a boolean

yams.constraints.check_decimal(eschema, value) → bool

check value is a Decimal

yams.constraints.check_file(eschema, value) → bool

check value has a getvalue() method (e.g. StringIO or cStringIO)

yams.constraints.check_float(eschema, value) → bool

check value is a float

yams.constraints.check_int(eschema, value) → bool

check value is an integer

yams.constraints.check_password(eschema, value) → bool

check value is an encoded string

yams.constraints.check_string(eschema, value) → bool

check value is an unicode string

yams.constraints.cstr_json_dumps(obj: jsonSerializable) → str
yams.constraints.patch_sqlite_decimal() → None

patch Decimal checker and converter to bypass SQLITE Bug (SUM of Decimal return float in SQLITE)

yams.constraints.yes(*args, **kwargs) → bool

dunno how to check

yams.diff module

Compare two yams schemas

Textual representation of schema are created and standard diff algorithm are applied.

class yams.diff.attr_scope

Bases: object

indentation = 2
nextline = ','
spacer = ''
class yams.diff.class_scope

Bases: object

indentation = 1
nextline = ''
spacer = ' '
yams.diff.format_constraint(cstr: yams.interfaces.IConstraint) → str
yams.diff.format_expression(expr) → str
yams.diff.format_perms(perms: Dict[str, Iterable[T_co]], scope: Union[Type[yams.diff.attr_scope], Type[yams.diff.class_scope]], isdefault: bool) → str
yams.diff.format_props(props: Dict[KT, VT], scope: Union[Type[yams.diff.attr_scope], Type[yams.diff.class_scope]], ignore: Sequence[T_co] = ()) → str
yams.diff.format_tuple(iterator: Iterable[T_co]) → str
yams.diff.identity(x: _x_type) → _x_type
yams.diff.nullhandler(relation, perms: perms_type) → Tuple[perms_type, bool]
yams.diff.properties_from(relation: yams.schema.RelationDefinitionSchema, permissionshandler: Callable[[Any, perms_type], Tuple[perms_type, bool]] = <function nullhandler>) → Dict[str, Union[str, int, bool, Any, List[Union[str, Any]]]]

return a dictionary containing properties of an attribute or a relation (if specified with is_relation option)

yams.diff.quoted(obj: Union[str, Any]) → str
yams.diff.schema2descr(schema: Schema, permissionshandler: Callable[[Any, perms_type], Tuple[perms_type, bool]], ignore: Sequence[T_co] = ()) → str

convert a yams schema into a text description

yams.diff.schema2file(schema: Schema, output: str, permissionshandler: Callable[[Any, perms_type], Tuple[perms_type, bool]], ignore: Sequence[T_co] = ()) → None

Save schema description of schema find in directory schema_dir into output file

yams.diff.schema_diff(schema1: Schema, schema2: Schema, permissionshandler: Callable[[Any, perms_type], Tuple[perms_type, bool]] = <function nullhandler>, diff_tool: Optional[str] = None, ignore: Sequence[T_co] = ()) → Tuple[str, str]

schema 1 and 2 are CubicwebSchema diff_tool is the name of tool use for file comparison

yams.interfaces module

Public interfaces for yams.

class yams.interfaces.IConstraint

Bases: logilab.common.interface.Interface

Represents a constraint on a relation.

class yams.interfaces.IEntitySchema

Bases: logilab.common.interface.Interface

An entity has a type, a set of subject and or object relations. The entity schema defines the possible relations for a given type and some constraints on those relations.

Attributes are defined with relations pointing to a ‘final’ entity

attribute_definitions() → Iterator[T_co]

return an iterator on attribute definitions

attribute relations are a subset of subject relations where the object’s type is a final entity

an attribute definition is a 2-uple : * name of the relation * schema of the destination entity type

check(entity) → None

check the entity and raises an InvalidEntity exception if it contains some invalid fields (ie some constraints failed)

constraints(rtype) → Any

return the existing constraints on the <rtype> subject relation

default(rtype) → Any

return the default value of a subject relation

is_final() → bool

return true if the entity is a final entity (ie cannot be used as subject of a relation)

object_relation(rtype) → Any

return the relation schema for the rtype object relation

Raise KeyError if rtype is not known.

object_relations() → List[T]

return a list of relations that may have this type of entity as object

If schema is not None, return a list of schemas instead of relation’s types.

relation_definitions() → Iterator[T_co]

return an iterator on “real” relation definitions

“real” relations are a subset of subject relations where the object’s type is not a final entity

a relation definition is a 2-uple : * name of the relation * schema of the destination entity type

subject_relation(rtype) → Any

return the relation schema for the rtype subject relation

Raise KeyError if rtype is not known.

subject_relations() → List[T]

return a list of relations that may have this type of entity as subject

If schema is not None, return a list of schemas instead of relation’s types.

class yams.interfaces.IRelationSchema

Bases: logilab.common.interface.Interface

A relation is a named ordered link between two entities. A relation schema defines the possible types of both extremities.

associations(schema: Schema = None) → List[Tuple[Any, List[Any]]]

return a list of (subject_type, [object_types]) defining between which types this relation may exists

If schema is not None, return a list of schemas instead of type.

objects(etype=None) → List[T]

return a list of types which can be object of this relation.

If e_type is not None, return a list of types which can be object of this relation with e_type as subject. If schema is not None, return a list of schemas instead of type. Raise KeyError if e_type is not known.

subjects(etype=None) → List[T]

return a list of types which can be subject of this relation

If e_type is not None, return a list of types which can be subject of this relation with e_type as object. If schema is not None, return a list of schemas instead of type. Raise KeyError if e_type is not known

class yams.interfaces.ISchema

Bases: logilab.common.interface.Interface

a schema is a collection of relation and entity schemas

entities(schema: Optional[Schema] = None) → List[T]

return a list of possible entity’s type

If schema is not None, return a list of schemas instead of types.

eschema(e_type) → Any

return the entity’s schema for the given type

has_entity(e_type) → bool

return true the type is defined in the schema

has_relation(rtype) → bool

return true the relation is defined in the schema

relations(schema: Schema = None) → List[T]

return the list of possible relation’types

If schema is not None, return a list of schemas instead of relation’s types.

rschema(rtype) → None

return the relation schema for the given relation type

class yams.interfaces.IVocabularyConstraint

Bases: yams.interfaces.IConstraint

a specific constraint restricting the set of possible value for an attribute value

vocabulary() → List[T]

return a list of possible values for the attribute

yams.reader module

ER schema loader.

Use either a sql derivated language for entities and relation definitions files or a direct python definition file.

class yams.reader.SchemaLoader

Bases: object

the schema loader is responsible to build a schema object from a set of files

add_definition(definition_object: Type[yams.buildobjs.Definition], file_path: Optional[str] = None) → Callable
context = {'BigInt': <class 'yams.buildobjs.BigInt'>, 'Boolean': <class 'yams.buildobjs.Boolean'>, 'BoundConstraint': <class 'logilab.common.deprecation.BoundConstraint'>, 'BoundaryConstraint': <class 'yams.constraints.BoundaryConstraint'>, 'Bytes': <class 'yams.buildobjs.Bytes'>, 'Date': <class 'yams.buildobjs.Date'>, 'Datetime': <class 'yams.buildobjs.Datetime'>, 'Decimal': <class 'yams.buildobjs.Decimal'>, 'EntityType': <class 'yams.buildobjs.EntityType'>, 'Float': <class 'yams.buildobjs.Float'>, 'FormatConstraint': <class 'yams.constraints.FormatConstraint'>, 'Int': <class 'yams.buildobjs.Int'>, 'Interval': <class 'yams.buildobjs.Interval'>, 'IntervalBoundConstraint': <class 'yams.constraints.IntervalBoundConstraint'>, 'MultipleStaticVocabularyConstraint': <class 'yams.constraints.MultipleStaticVocabularyConstraint'>, 'ObjectRelation': <class 'yams.buildobjs.ObjectRelation'>, 'Password': <class 'yams.buildobjs.Password'>, 'RegexpConstraint': <class 'yams.constraints.RegexpConstraint'>, 'RelationDefinition': <class 'yams.buildobjs.RelationDefinition'>, 'RelationType': <class 'yams.buildobjs.RelationType'>, 'RichString': <function RichString>, 'SizeConstraint': <class 'yams.constraints.SizeConstraint'>, 'StaticVocabularyConstraint': <class 'yams.constraints.StaticVocabularyConstraint'>, 'String': <class 'yams.buildobjs.String'>, 'SubjectRelation': <class 'yams.buildobjs.SubjectRelation'>, 'TZDatetime': <class 'yams.buildobjs.TZDatetime'>, 'TZTime': <class 'yams.buildobjs.TZTime'>, 'Time': <class 'yams.buildobjs.Time'>, 'UniqueConstraint': <class 'yams.constraints.UniqueConstraint'>}
exec_file(file_path: str, module_name: Optional[str]) → Callable
extra_path = None
extrapath
get_schema_files(directory: str) → List[str]

return an ordered list of files defining a schema

look for a schema.py file and or a schema sub-directory in the given directory

handle_file(file_path: str, module_name: Optional[str] = None) → Callable
load(module_names: Sequence[Tuple[Any, str]], name: Optional[str] = None, register_base_types: bool = True, construction_mode: str = 'strict', remove_unused_relation_types: bool = True) → Callable
main_schema_directory = 'schema'
schema_class

alias of yams.schema.Schema

schemacls
unhandled_file(file_path: str) → Callable
yams.reader.build_schema_from_namespace(items: Sequence[Tuple[Any, Any]]) → yams.schema.Schema
yams.reader.fill_schema_from_namespace(schema: Schema, items: Sequence[Tuple[Any, Any]], **kwargs) → None

yams.schema module

Classes to define generic Entities/Relations schemas.

class yams.schema.ERSchema(schema: Schema, entity_relation_definition: RelationDefinition = None)

Bases: object

Base class shared by entity and relation schema.

class yams.schema.EntitySchema(schema: Schema = None, relation_definition: EntityType = None, *args, **kwargs)

Bases: yams.schema.PermissionMixIn, yams.schema.ERSchema

An entity has a type, a set of subject and or object relations the entity schema defines the possible relations for a given type and some constraints on those relations.

ACTIONS = ('read', 'add', 'update', 'delete')
add_object_relation(relation_schema: RelationSchema) → Callable
add_subject_relation(relation_schema: RelationSchema) → Callable
advertise_new_add_permission() → None
ancestors() → List[yams.schema.EntitySchema]
attribute_definitions() → Generator[Tuple[yams.schema.RelationSchema, yams.schema.EntitySchema], Any, None]

return an iterator on attribute definitions

attribute relations are a subset of subject relations where the object’s type is a final entity

an attribute definition is a 2-uple : * schema of the (final) relation * schema of the destination entity type

check(entity: Dict[RelationSchema, Any], creation: bool = False, _=None, relations: Optional[List[RelationSchema]] = None) → None

check the entity and raises an ValidationError exception if it contains some invalid fields (ie some constraints failed)

check_unique_together() → None
check_value(value: Any) → bool

check the value of a final entity (ie a const value)

convert_value(value: Any) → Any

check the value of a final entity (ie a const value)

default(relation_type: NewType.<locals>.new_type) → Callable
defaults() → Generator[Tuple[yams.schema.RelationSchema, Any], Any, None]

return an iterator on (attribute name, default value)

del_object_relation(relation_schema: RelationSchema) → Callable
del_subject_relation(relation_schema: RelationSchema) → Callable
destination(relation_schema: RelationSchema) → Callable
field_checkers = {'BigInt': <function check_int>, 'Boolean': <function check_boolean>, 'Bytes': <function check_file>, 'Date': <function yes>, 'Datetime': <function yes>, 'Decimal': <function check_decimal>, 'Float': <function check_float>, 'Int': <function check_int>, 'Interval': <function yes>, 'Password': <function check_password>, 'String': <function check_string>, 'TZDatetime': <function yes>, 'TZTime': <function yes>, 'Time': <function yes>}
field_converters = {'BigInt': <class 'int'>, 'Boolean': <class 'bool'>, 'Decimal': <class 'decimal.Decimal'>, 'Float': <class 'float'>, 'Int': <class 'int'>, 'Password': <class 'bytes'>, 'String': <class 'str'>}
fulltext_containers() → Generator[Tuple[yams.schema.RelationSchema, str], Any, None]

return relations whose extremity points to an entity that should contains the full text index content of entities of this type

fulltext_relations() → Generator[Tuple[yams.schema.RelationSchema, str], Any, None]

return the (name, role) of relations to index

has_metadata(attribute, metadata) → Callable
has_relation(relation_type: RelationType, role: str) → Callable
has_unique_values(relation_type: NewType.<locals>.new_type) → Callable
indexable_attributes() → Generator[yams.schema.RelationSchema, Any, None]

return the relation schema of attribtues to index

is_metadata(attribute) → Callable
is_subobject(strict: bool = False, skip_relations: Sequence[Tuple[RelationSchema, str]] = ()) → Callable
main_attribute() → Optional[yams.schema.RelationSchema]

convenience method that returns the main (i.e. the first non meta) attribute defined in the entity schema

meta_attributes(**kwargs)

return a dictionnary defining meta-attributes: * key is an attribute schema * value is a 2-uple (metadata name, described attribute name)

a metadata attribute is expected to be named using the following scheme:

<described attribute name>_<metadata name>

for instance content_format is the format metadata of the content attribute (if it exists).

object_relations() → List[yams.schema.RelationSchema]

return a list of relations that may have this type of entity as object

objrels
ordered_relations(**kwargs)

return subject relations in an ordered way

rdef(relation_type: NewType.<locals>.new_type, role: str = 'subject', target_type: NewType.<locals>.new_type = None, take_first: bool = False) → RelationDefinitionSchema
relation_definition(relation_type: NewType.<locals>.new_type, role: str = 'subject', target_type: NewType.<locals>.new_type = None, take_first: bool = False) → Callable
relation_definitions(include_final: bool = False) → Callable
specialized_by(recursive: bool = True) → List[yams.schema.EntitySchema]
specializes() → Optional[yams.schema.EntitySchema]
subject_relations() → List[yams.schema.RelationSchema]

return a list of relations that may have this type of entity as subject

subjrels
vocabulary(relation_type: NewType.<locals>.new_type) → Callable
class yams.schema.PermissionMixIn

Bases: object

mixin class for permissions handling

action_permissions(action: str) → Tuple[str, ...]
check_permission_definitions() → None

check permissions are correctly defined

set_action_permissions(action: str, permissions: Tuple[str, ...]) → None
class yams.schema.RelationDefinitionSchema(subject: EntitySchema, relation_type: RelationSchema, object: EntitySchema, package: str, values: Optional[Dict[str, Any]] = None)

Bases: yams.schema.PermissionMixIn

a relation definition is fully caracterized relation, eg

<subject type> <relation type> <object type>

ACTIONS
classmethod ALL_PROPERTIES() → Set[str]
BASE_TYPE_PROPERTIES = {'Bytes': {'fulltextindexed': False}, 'String': {'fulltextindexed': False, 'internationalizable': False}}
advertise_new_add_permission() → None

handle backward compatibility with pre-add permissions

  • if the update permission was () [empty tuple], use the default attribute permissions for add
  • else copy the update rule for add
as_triple() → Tuple[yams.schema.EntitySchema, yams.schema.RelationSchema, yams.schema.EntitySchema]
check_permission_definitions() → None

check permissions are correctly defined

constraint_by_class(cls: Type[yams.constraints.BaseConstraint]) → Optional[yams.constraints.BaseConstraint]
constraint_by_interface(interface: Type[yams.interfaces.IConstraint]) → Callable
constraint_by_type(constraint_type: str) → Callable
dump(subject: yams.schema.EntitySchema, object: yams.schema.EntitySchema) → yams.schema.RelationDefinitionSchema
final
get(key, default=None) → Any
role_cardinality(role) → Any
rproperties() → Dict[str, Any]

same as .rproperty_defs class method, but for instances (hence destination is known to be self.object).

classmethod rproperty_defs(destination_type) → Callable
rtype
update(values: Dict[str, Any]) → None
class yams.schema.RelationSchema(schema: Schema, relation_definition: RelationType = None, **kwargs)

Bases: yams.schema.ERSchema

A relation is a named and oriented link between two entities. A relation schema defines the possible types of both extremities.

Cardinality between the two given entity’s type is defined as a 2 characters string where each character is one of:

  • 1 <-> 1..1 <-> one and only one
  • ? <-> 0..1 <-> zero or one
    • <-> 1..n <-> one or more
    • <-> 0..n <-> zero or more
associations() → List[Tuple[yams.schema.EntitySchema, List[T]]]

return a list of (subject, [objects]) defining between which types this relation may exists

check_permission_definitions() → None

check permissions are correctly defined

del_relation_def(subject_schema: EntitySchema, object_schema: EntitySchema, _recursing: bool = False) → Callable
final = False
fulltext_container = None
init_rproperties(subject: EntitySchema, object: EntitySchema, build_relation_definition: RelationDefinition) → Callable
inlined = False
objects(entity_schema: Optional[EntitySchema] = None) → Callable
permissions = None
rdef(subject: NewType.<locals>.new_type, object: NewType.<locals>.new_type) → RelationDefinitionSchema
rdef_class
rdefs
relation_definition(subject: NewType.<locals>.new_type, object: NewType.<locals>.new_type) → RelationDefinitionSchema

return the properties dictionary of a relation

relation_definition_class

alias of RelationDefinitionSchema

role_rdef(entity_type: NewType.<locals>.new_type, target_type: NewType.<locals>.new_type, role: str) → RelationDefinitionSchema
role_relation_definition(entity_type: NewType.<locals>.new_type, target_type: NewType.<locals>.new_type, role: str) → Callable
rule = None
subjects(entity_schema: Optional[EntitySchema] = None) → Callable
symmetric = False
targets(entity_schema: Optional[EntitySchema] = None, role: str = 'subject') → Callable
update(subject_schema: EntitySchema, object_schema: EntitySchema, relation_definition: RelationDefinition) → Callable
class yams.schema.Schema(name: str, construction_mode: str = 'strict')

Bases: object

set of entities and relations schema defining the possible data sets used in an application

Variables:
  • name – name of the schema, usually the application identifier
  • base – path of the directory where the schema is defined
add_entity_type(entity_definition: EntityType) → Callable
add_relation_def(relation_definition: RelationDefinition) → Callable
add_relation_type(relation_type_definition: RelationType) → Callable
classmethod critical(msg, *args, **kwargs)

Log ‘msg % args’ with severity ‘CRITICAL’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.critical(“Houston, we have a %s”, “major disaster”, exc_info=1)

classmethod debug(msg, *args, **kwargs)

Log ‘msg % args’ with severity ‘DEBUG’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.debug(“Houston, we have a %s”, “thorny problem”, exc_info=1)

del_entity_type(entity_type: str) → Callable
del_relation_def(subject_type: NewType.<locals>.new_type, relation_type: NewType.<locals>.new_type, object_type: NewType.<locals>.new_type) → Callable
del_relation_type(relation_type: RelationSchema) → Callable
entities() → List[yams.schema.EntitySchema]

return a list of possible entity’s type

Relation_type:list
Returns:defined entity’s types (str) or schemas (EntitySchema)
entity_class

alias of EntitySchema

entity_schema_for(entity_type: NewType.<locals>.new_type) → Callable
classmethod error(msg, *args, **kwargs)

Log ‘msg % args’ with severity ‘ERROR’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.error(“Houston, we have a %s”, “major problem”, exc_info=1)

eschema(entity_type: NewType.<locals>.new_type) → EntitySchema
classmethod exception(msg, *args, exc_info=True, **kwargs)

Convenience method for logging an ERROR with exception information.

finalize() → None

Finalize schema

Can be used to, e.g., infer relations from inheritance, computed relations, etc.

get(name: NewType.<locals>.new_type, default=None) → Any
has_entity(entity_type: str) → Callable
has_relation(relation_type: NewType.<locals>.new_type) → Callable
infer_specialization_rules() → None
classmethod info(msg, *args, **kwargs)

Log ‘msg % args’ with severity ‘INFO’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.info(“Houston, we have a %s”, “interesting problem”, exc_info=1)

no_specialization_inference = ()
rebuild_infered_relations() → None

remove any infered definitions and rebuild them

relation_class

alias of RelationSchema

relation_schema_for(relation_type: NewType.<locals>.new_type) → Callable
relations() → List[yams.schema.RelationSchema]

return the list of possible relation’types

Relation_type:list
Returns:defined relation’s types (str) or schemas (RelationSchema)
remove_infered_definitions() → None

remove any infered definitions added by infer_specialization_rules

rename_entity_type(old_name: str, new_name: str) → Callable
rschema(relation_type: NewType.<locals>.new_type) → yams.schema.RelationSchema
classmethod warning(msg, *args, **kwargs)

Log ‘msg % args’ with severity ‘WARNING’.

To pass exception information, use the keyword argument exc_info with a true value, e.g.

logger.warning(“Houston, we have a %s”, “bit of a problem”, exc_info=1)

yams.schema.rehash(dictionary: Dict[KT, VT]) → dict

this function manually builds a copy of dictionary but forces hash values to be recomputed. Note that dict(d) or d.copy() don’t do that.

It is used to :
  • circumvent Pyro / (un)pickle problems (hash mode is changed during reconstruction)

  • force to recompute keys’ hash values. This is needed when a schema’s type is changed because the schema’s hash method is based on the type attribute. This problem is illusrated by the pseudo-code below :

    >>> topic = EntitySchema(type='Topic')
    >>> d = {topic : 'foo'}
    >>> d[topic]
    'foo'
    >>> d['Topic']
    'foo'
    >>> topic.type = 'folder'
    >>> topic in d
    False
    >>> 'Folder' in d
    False
    >>> 'Folder' in d.keys() # but it can be found "manually"
    True
    >>> d = rehash(d) # explicit rehash()
    >>> 'Folder' in d
    True
    

yams.schema2dot module

Write a schema as a dot file.

class yams.schema2dot.FullSchemaVisitor(schema: Schema, skiptypes: Sequence[T_co] = ())

Bases: yams.schema2dot.SchemaVisitor

edges() → Generator[Tuple[str, str, Optional[RelationSchema]], Any, None]
nodes() → Generator[Tuple[str, EntitySchema], Any, None]
class yams.schema2dot.OneHopESchemaVisitor(eschema: EntitySchema, skiptypes: Sequence[T_co] = ())

Bases: yams.schema2dot.SchemaVisitor

class yams.schema2dot.OneHopRSchemaVisitor(rschema: RelationSchema, skiptypes: Sequence[T_co] = ())

Bases: yams.schema2dot.SchemaVisitor

class yams.schema2dot.SchemaDotPropsHandler(visitor: yams.schema2dot.SchemaVisitor)

Bases: object

edge_properties(rschema: Optional[RelationSchema], subjnode: NewType.<locals>.new_type, objnode: NewType.<locals>.new_type) → Dict[str, str]

return default DOT drawing options for a relation schema

node_properties(eschema: EntitySchema) → Dict[str, str]

return default DOT drawing options for an entity schema

class yams.schema2dot.SchemaVisitor(skiptypes: Sequence[T_co] = ())

Bases: object

display_rel(rschema: RelationSchema, setype: NewType.<locals>.new_type, tetype: NewType.<locals>.new_type) → bool
edges() → Any
nodes() → Any
should_display_attr(eschema: EntitySchema, rschema: RelationSchema) → bool
should_display_schema(erschema: ERSchema) → bool
yams.schema2dot.run() → None

main routine when schema2dot is used as a script

yams.schema2dot.schema2dot(schema: Optional[Schema] = None, outputfile: Optional[str] = None, skiptypes: Sequence[T_co] = (), visitor: Union[yams.schema2dot.SchemaVisitor, yams.schema2dot.FullSchemaVisitor, None] = None, prophdlr=None, size=None) → Any

write to the output stream a dot graph representing the given schema

yams.serialize module

yams.serialize.serialize_to_python(schema: Schema) → str

yams.tools module

some yams command line tools

yams.tools.check_schema() → int
yams.tools.schema_image() → int

yams.xy module

XML vocabularies <-> Yams schema mapping

exception yams.xy.UnsupportedVocabulary

Bases: Exception

class yams.xy.XYRegistry

Bases: object

registry of equivalence to translate yams into various xml schema such as dublin core, foaf, doap…

add_equivalence(yamssnippet: str, xmlsnippet: str) → None
register_prefix(prefix: str, xmlns: str, overwrite: bool = False) → None
remove_equivalence(yamssnippet: str, xmlsnippet: str) → None
xeq(yamssnippet: str) → List[Tuple[str, Union[str, Tuple[str, str]], str]]
yeq(xmlsnippet: str, isentity: bool = False) → List[Tuple[str, Union[str, Tuple[str, str]], str]]

Module contents

Object model and utilities to define generic Entities/Relations schemas.

yams.convert_default_value(rdef: rdef_rdefschema, default: _type_of_default) → Union[_type_of_default, datetime.datetime, datetime.date, float, str, int, bool]
yams.register_base_type(name: str, parameters: Union[Dict[str, Any], Iterable[str]] = (), check_function: Callable = None) → None

register a yams base (final) type. You’ll have to call base_type_class to generate the class.

yams.unregister_base_type(name: str) → None

Unregister a yams base (final) type