Code — linkml documentation

# Code

## MetaModel

See Datamodel docs for full documentation

class linkml_runtime.linkml_model.meta.SchemaDefinition(*args, _if_missing: Optional[Callable[[jsonasobj2._jsonobj.JsonObj, str], Tuple[bool, Any]]] = None, **kwargs)

  a collection of subset, type, slot and class definitions

class linkml_runtime.linkml_model.meta.ClassDefinition(*args, _if_missing: Optional[Callable[[jsonasobj2._jsonobj.JsonObj, str], Tuple[bool, Any]]] = None, **kwargs)

  the definition of a class or interface

class linkml_runtime.linkml_model.meta.SlotDefinition(*args, _if_missing: Optional[Callable[[jsonasobj2._jsonobj.JsonObj, str], Tuple[bool, Any]]] = None, **kwargs)

  the definition of a property or a slot

## Generators

Code for various generators for schema definitions

## Loaders and Dumpers

class linkml_runtime.dumpers.json_dumper.JSONDumper
  dump(element: linkml_runtime.utils.yamlutils.YAMLRoot, to_file: str, contexts: Optional[Union[str, dict, jsonasobj2._jsonobj.JsonObj, List[Union[str, dict, jsonasobj2._jsonobj.JsonObj]]]] = None) → None

    Write element as json to to_file :param element: LinkML object to be serialized as YAML :param to_file: file to write to :param contexts: JSON-LD context(s) in the form of:

    > - file name

    > - URL

    > - JSON String

    > - dict

    > - JSON Object

    > - A list containing elements of any type named above

  dumps(element: linkml_runtime.utils.yamlutils.YAMLRoot, contexts: Optional[Union[str, dict, jsonasobj2._jsonobj.JsonObj, List[Union[str, dict, jsonasobj2._jsonobj.JsonObj]]]] = None, inject_type=True) → str

    Return element as a JSON or a JSON-LD string :param element: LinkML object to be emitted :param contexts: JSON-LD context(s) in the form of:

    > - file name

    > - URL

    > - JSON String

    > - dict

    > - JSON Object

    > - A list containing elements of any type named above

    Parameters

      inject_type – if True (default), add a @type at the top level

    Returns

      JSON Object representing the element

class linkml_runtime.loaders.JSONLoader
  loads(source: str, target_class: Type[linkml_runtime.utils.yamlutils.YAMLRoot], *, metadata: Optional[hbreader.FileInfo] = None, **_) → linkml_runtime.utils.yamlutils.YAMLRoot

    Load source as a string @param source: source @param target_class: destination class @param metadata: metadata about the source @param _: extensions @return: instance of taarget_class

## Schema Utils

class linkml_runtime.utils.schemaview.SchemaView(schema: Union[str, linkml_runtime.linkml_model.meta.SchemaDefinition], importmap: Optional[Mapping[str, str]] = None)

  A SchemaView provides a virtual schema layered on top of a schema plus its import closure

  Most operations are parameterized by imports. If this is set to True (default), then the full import closure is considered when answering

  This class utilizes caching for efficient lookup operations.

  TODO: decide how to use this in conjunction with the existing schemaloader, which injects into the schema rather than providing dynamic methods.

  See:

    - https://github.com/linkml/linkml/issues/59

    - https://github.com/linkml/linkml/discussions/144

    - https://github.com/linkml/linkml/issues/48

    - https://github.com/linkml/linkml/issues/270

## Utils

Utilities