madbot_cli.manifest
The deposit file: read it, check it, and give access to its parts.
The file is YAML or JSON. It is checked against the JSON Schema of its version, then against the rules a schema cannot say (titles unique in the file, sources declared at the top and named where they are used, one key per connection, a valid pattern), before any request to the API. Every error comes with its path in the file.
Attributes
| Name | Description |
|---|---|
FORMS | The forms of a data entry, by definition of the schema: the key that tells |
JSON_TYPES | The Python types of the JSON types a choice of the format names. |
NEXT_TO | How many keys of a place a message names. |
PLACES | The places of the format a person knows, by definition of the schema, with |
SUPPORTED_VERSIONS | The versions of the format this release reads. |
Classes
| Name | Description |
|---|---|
Loader | Reads YAML as yaml.safe_load does; its numbers keep how they are written. |
Manifest | A deposit file, checked. |
ManifestError | The deposit file is invalid. |
Node | A node and what it holds, as the file describes it. |
Source | A source of data, declared once at the top of the file. |
Submission | A submission of data of a node to a repository, as the file describes it. |
WrittenFloat | A decimal number of the file that keeps how it is written, such as 1.10. |
WrittenInt | An integer of the file that keeps how it is written, such as 01. |
Functions
| Name | Description |
|---|---|
as_text | Read as names the numbers of the paths and names of the data entries. |
check_pattern | Check the pattern of the rule of samples of a node. |
check_rules | Check the rules of a deposit file that its JSON Schema cannot say. |
connection_of | Tell which connection a source of the file stands for, as the file writes it. |
credentials | Read credentials from an environment variable holding a JSON object. |
descendants | List the paths of a node of the document and of the nodes under it. |
details_of | Explain the errors inside a choice, each with its path from the choice. |
each | Convert each item of a list, and leave anything else as it is. |
entry_as_text | Read as names the numbers of the path and names of a data entry. |
label_of_path | Write the path of a node for a person. |
load | Read and check a deposit file. |
load_schema | Return the JSON Schema of a version of the deposit file. |
message_of | Explain an error of the format, saying where a misplaced key goes. |
message_of_forms | Explain a data entry that takes none of its forms, or several. |
message_of_type | Explain a value that takes the one choice of its type with an error in it. |
name_of | Read a number given as a name as the text it is written with. |
node_as_text | Read as names the numbers of the data entries of a node and its children. |
node_of | Read a node of a checked document, and the nodes under it. |
parse | Check a deposit document and return it as a Manifest. |
path_of | Write a path in a document the way a person reads it. |
places_of | List, for each key of the format, the places it goes and the keys beside it. |
read_yaml | Read a YAML or JSON document with Loader, a safe loader. |
rule_as_text | Read as names the numbers of the data of the associations of a rule. |
via_path | Read the via of a data entry as a path of titles. |
without_empty | Drop the empty parts of a metadata value, at any depth. |
written_number | Read a number of the file, with the text it is written with. |
FORMSattributemodule attribute#
FORMS = {
'externalIdEntry': ('external_id', '{source, external_id}'),
'browseEntry': ('browse', '{source, browse: {path, match or names}}'),
'matchEntry': ('match', '{source, match}'),
'namesEntry': ('names', '{source, names}')
}The forms of a data entry, by definition of the schema: the key that tells the form, and the keys the form takes.
JSON_TYPESattributemodule attribute#
JSON_TYPES = {'object': Mapping, 'array': list, 'string': str, 'boolean': bool}The Python types of the JSON types a choice of the format names.
NEXT_TOattributemodule attribute#
NEXT_TO = 3How many keys of a place a message names.
PLACESattributemodule attribute#
PLACES = {
'source': ('a source', 'sources'),
'node': ('a node', 'nodes'),
'submission': ('a submission', 'submissions'),
'samples': ('the samples of a node', 'samples'),
'associationRule': ('an association rule', 'associations'),
'listedAssociation': ('an association of a list', 'list'),
'externalIdEntry': ('a data entry', 'data'),
'browseEntry': ('a data entry', 'data'),
'matchEntry': ('a data entry', 'data'),
'namesEntry': ('a data entry', 'data')
}The places of the format a person knows, by definition of the schema, with the key of the file under which they are.
SUPPORTED_VERSIONSattributemodule attribute#
SUPPORTED_VERSIONS = (1)The versions of the format this release reads.
Loaderclass#
class Loader(yaml.SafeLoader)Bases: yaml.SafeLoader
Reads YAML as yaml.safe_load does; its numbers keep how they are written.
Manifestclassdataclass#
class Manifest(version: int, workspace: str, nodes: list[Node], sources: dict[str, Source] = dict(), source: str = '<file>')A deposit file, checked.
Attributes
nodesattributeinstance attribute#
nodes: list[Node]sourceattributeclass attributeinstance attribute#
source: str = '<file>'sourcesattributeclass attributeinstance attribute#
sources: dict[str, Source] = field(default_factory=dict)versionattributeinstance attribute#
version: intworkspaceattributeinstance attribute#
workspace: strfind_sourcemethod#
def find_source(key: str) -> SourceFind a source of the file by its key.
Parameters
| Name | Type | Description |
|---|---|---|
key | str | The key of the source. |
Returns
Source- The source.
Raises
MadbotError- When the file has no source of that key.
find_submissionmethod#
def find_submission(title: str) -> tuple[Node, Submission]Find a submission of the file by its title.
Parameters
| Name | Type | Description |
|---|---|---|
title | str | The title of the submission. |
Returns
tuple- The node and the submission.
Raises
MadbotError- When the file has no submission of that title.
submissionsmethod#
def submissions() -> Iterator[tuple[Node, Submission]]List the submissions of the file with their node.
Yields
tuple- The node and the submission.
walkmethod#
def walk() -> Iterator[Node]List every node of the file, each before its children.
Yields
Node- The nodes, at every depth.
ManifestErrorclass#
class ManifestError(source: str, errors: list[str])Bases: MadbotError
The deposit file is invalid.
Attributes
| Name | Type | Description |
|---|---|---|
errors | list of str | One message per error, each starting with its path in the file. |
Parameters
| Name | Type | Description |
|---|---|---|
source | str | The file, or what the content came from. |
errors | list of str | One message per error. |
Nodeclassdataclass#
class Node(title: str, description: str | None = None, data: list[dict] = list(), samples: dict[str, Any] | None = None, associations: list[dict] = list(), submissions: list[Submission] = list(), nodes: list[Node] = list(), path: tuple[str, ...] = ())A node and what it holds, as the file describes it.
associationsattributeclass attributeinstance attribute#
associations: list[dict] = field(default_factory=list)The rules that make the associations of the data of the node.
dataattributeclass attributeinstance attribute#
data: list[dict] = field(default_factory=list)The data entries to link to the node, each naming its source.
descriptionattributeclass attributeinstance attribute#
description: str | None = Nonenodesattributeclass attributeinstance attribute#
nodes: list[Node] = field(default_factory=list)The child nodes, in the order of the file.
pathattributeclass attributeinstance attribute#
path: tuple[str, ...] = ()The titles from the top of the workspace to the node, its own last.
samplesattributeclass attributeinstance attribute#
samples: dict[str, Any] | None = Nonesubmissionsattributeclass attributeinstance attribute#
submissions: list[Submission] = field(default_factory=list)titleattributeinstance attribute#
title: strsource_keysmethod#
def source_keys() -> list[str]List the sources the data of the node come from.
Returns
list of str- The keys of the sources, in the order the entries name them.
walkmethod#
def walk() -> Iterator[Node]List the node and the nodes under it, each before its children.
Yields
Node- The node, then its descendants.
Sourceclassdataclass#
class Source(key: str, plugin: str, shared_params: dict[str, Any], credentials_env: str | None = None)A source of data, declared once at the top of the file.
Submissionclassdataclass#
class Submission(title: str, repository: dict[str, Any], data: list[dict] = list(), take_all: bool = False, via: tuple[str, ...] | None = None, metadata: dict[str, dict[str, Any]] = dict())A submission of data of a node to a repository, as the file describes it.
dataattributeclass attributeinstance attribute#
data: list[dict] = field(default_factory=list)The data entries the submission takes; empty when it takes them all.
metadataattributeclass attributeinstance attribute#
metadata: dict[str, dict[str, Any]] = field(default_factory=dict)repositoryattributeinstance attribute#
repository: dict[str, Any]take_allattributeclass attributeinstance attribute#
take_all: bool = FalseWhether the submission takes every data of its node and the nodes under it.
titleattributeinstance attribute#
title: strviaattributeclass attributeinstance attribute#
via: tuple[str, ...] | None = NoneWith take_all, the node a data linked to several nodes goes through.
WrittenFloatclass#
class WrittenFloat(float)Bases: float
A decimal number of the file that keeps how it is written, such as 1.10.
WrittenIntclass#
class WrittenInt(int)Bases: int
An integer of the file that keeps how it is written, such as 01.
as_textfunction#
def as_text(document: Any) -> AnyRead as names the numbers of the paths and names of the data entries.
YAML reads path: [24343971] or names: [2026] as numbers, while
a folder or a file is named by text. A number read by Loader gives
the text it is written with, so that 01 stays "01" and 1.10
stays "1.10". Only the places of the format that hold names are
read again; a value of a metadata field keeps its number.
Parameters
| Name | Type | Description |
|---|---|---|
document | Any | The content of the file, as Loader reads it. |
Returns
Any- A copy of the document, with those numbers written as text.
check_patternfunction#
def check_pattern(samples: Mapping, where: list) -> list[str]Check the pattern of the rule of samples of a node.
Parameters
| Name | Type | Description |
|---|---|---|
samples | mapping | The samples of a node. |
where | list | The path of the node in the file. |
Returns
list of str- The errors, each starting with its path.
check_rulesfunction#
def check_rules(document: Mapping) -> list[str]Check the rules of a deposit file that its JSON Schema cannot say.
Parameters
| Name | Type | Description |
|---|---|---|
document | mapping | A document valid against the JSON Schema. |
Returns
list of str- The errors, each starting with its path.
connection_offunction#
def connection_of(spec: Mapping) -> tuple[str, tuple]Tell which connection a source of the file stands for, as the file writes it.
Parameters
| Name | Type | Description |
|---|---|---|
spec | mapping | A source: its plugin and shared_params. |
Returns
tuple- The plugin and the shared parameters, as text and sorted.
credentialsfunction#
def credentials(env_name: str | None, environ: Mapping[str, str] | None = None) -> dict | NoneRead credentials from an environment variable holding a JSON object.
Parameters
Raises
MadbotError- When the variable does not hold a JSON object.
descendantsfunction#
def descendants(node: Mapping) -> set[tuple[str, ...]]List the paths of a node of the document and of the nodes under it.
Parameters
| Name | Type | Description |
|---|---|---|
node | mapping | A node of the document. |
Returns
set of tuple- The paths under the node,
()for the node itself.
details_offunction#
def details_of(errors: list[jsonschema.ValidationError], schema: Mapping) -> strExplain the errors inside a choice, each with its path from the choice.
Parameters
| Name | Type | Description |
|---|---|---|
errors | list of ValidationError | The errors of the choice. |
schema | mapping | The JSON Schema of the format. |
Returns
str- The messages, joined by
;.
eachfunction#
def each(items: Any, convert: Any) -> AnyConvert each item of a list, and leave anything else as it is.
Parameters
Returns
Any- The converted list, or
itemsitself.
entry_as_textfunction#
def entry_as_text(entry: Any) -> AnyRead as names the numbers of the path and names of a data entry.
Parameters
| Name | Type | Description |
|---|---|---|
entry | Any | A data entry of a node or a submission, or a data of an association. |
Returns
Any- A copy of the entry, with those numbers written as text.
label_of_pathfunction#
def label_of_path(path: Iterable[str]) -> strWrite the path of a node for a person.
Parameters
| Name | Type | Description |
|---|---|---|
path | iterable of str | The titles from the top of the workspace. |
Returns
str- The titles joined by
/.
loadfunction#
def load(path: str | os.PathLike) -> ManifestRead and check a deposit file.
Parameters
| Name | Type | Description |
|---|---|---|
path | str or path - like | The file, YAML or JSON. |
Returns
Manifest- The checked deposit.
Raises
ManifestError- When the file cannot be read or is invalid.
load_schemafunction#
def load_schema(version: int = 1) -> dictReturn the JSON Schema of a version of the deposit file.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
version | int | 1 | The version of the format. |
Returns
dict- The JSON Schema.
message_offunction#
def message_of(error: jsonschema.ValidationError, schema: Mapping) -> strExplain an error of the format, saying where a misplaced key goes.
Parameters
| Name | Type | Description |
|---|---|---|
error | ValidationError | An error of the file against the format. |
schema | mapping | The JSON Schema of the format. |
Returns
str- The message; for a key not expected where it is, the place the format expects it (those on the path of the key first), or the keys expected there.
message_of_formsfunction#
def message_of_forms(error: jsonschema.ValidationError, schema: Mapping) -> str | NoneExplain a data entry that takes none of its forms, or several.
Parameters
| Name | Type | Description |
|---|---|---|
error | ValidationError | A oneOf error of the file against the format. |
schema | mapping | The JSON Schema of the format. |
message_of_typefunction#
def message_of_type(error: jsonschema.ValidationError, schema: Mapping) -> str | NoneExplain a value that takes the one choice of its type with an error in it.
Parameters
| Name | Type | Description |
|---|---|---|
error | ValidationError | A oneOf error of the file against the format. |
schema | mapping | The JSON Schema of the format. |
name_offunction#
def name_of(item: Any) -> AnyRead a number given as a name as the text it is written with.
Parameters
| Name | Type | Description |
|---|---|---|
item | Any | An item of a path or of a list of names. |
Returns
Any"01"for01,"1.10"for1.10; any other item as it is.
node_as_textfunction#
def node_as_text(node: Any) -> AnyRead as names the numbers of the data entries of a node and its children.
Parameters
| Name | Type | Description |
|---|---|---|
node | Any | A node of the file. |
Returns
Any- A copy of the node, with the names of its data entries, those of its submissions and of its associations given one by one, as text.
node_offunction#
def node_of(node: Mapping, parent: tuple[str, ...] = ()) -> NodeRead a node of a checked document, and the nodes under it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
node | mapping | required | A node of the document. |
parent | tuple of str | () | The path of its parent. |
Returns
Node- The node.
parsefunction#
def parse(document: Any, source: str = '<file>') -> ManifestCheck a deposit document and return it as a Manifest.
Parameters
Returns
Manifest- The checked deposit.
Raises
ManifestError- With the path of each error.
path_offunction#
def path_of(parts: Any) -> strWrite a path in a document the way a person reads it.
Parameters
| Name | Type | Description |
|---|---|---|
parts | iterable | The keys and indexes from the root. |
Returns
str- Such as
sources.instrument.plugin;(file)for the root.
places_offunction#
def places_of(schema: Mapping) -> dict[str, dict[tuple[str, str], list[str]]]List, for each key of the format, the places it goes and the keys beside it.
Parameters
| Name | Type | Description |
|---|---|---|
schema | mapping | The JSON Schema of the format. |
Returns
dict- For each key, each place it goes, as
(name, key of the file it is under)such as("a submission", "submissions"), with the keys of that place, the required ones first.
read_yamlfunction#
def read_yaml(text: str) -> AnyRead a YAML or JSON document with Loader, a safe loader.
Parameters
| Name | Type | Description |
|---|---|---|
text | str | The document. |
Returns
Any- Its content, its numbers keeping how they are written.
Raises
yaml.YAMLError- When the text is not valid YAML.
rule_as_textfunction#
def rule_as_text(rule: Any) -> AnyRead as names the numbers of the data of the associations of a rule.
Parameters
| Name | Type | Description |
|---|---|---|
rule | Any | A rule of associations of a node. |
Returns
Any- A copy of the rule,
data: [{names: [2026]}]read as["2026"].
via_pathfunction#
def via_path(via: str | list[str] | None) -> tuple[str, ...] | NoneRead the via of a data entry as a path of titles.
Parameters
| Name | Type | Description |
|---|---|---|
via | str or list of str or None | The title of a child node, a path of titles, or [] for the node of
the submission itself. |
Returns
tuple of str or None- The path under the node of the submission; None when not given.
without_emptyfunction#
def without_empty(value: Any) -> AnyDrop the empty parts of a metadata value, at any depth.
A skeleton of madbot-cli fields writes an object field with its keys
and empty values: the parts left empty are no value, so that a part
filled is sent alone and a part forgotten is named as missing.
Parameters
| Name | Type | Description |
|---|---|---|
value | Any | The value, as the file gives it. |
Returns
Any- The value, each mapping and list without its empty parts.
written_numberfunction#
def written_number(loader: Loader, node: yaml.ScalarNode) -> WrittenInt | WrittenFloatRead a number of the file, with the text it is written with.
Parameters
| Name | Type | Description |
|---|---|---|
loader | Loader | The loader reading the file. |
node | ScalarNode | The number, as written. |
Returns
WrittenInt or WrittenFloat- The number, its
writtentext such as01,1.10or0x1F.

