metad package

Module contents

Top-level package for MetaData.

Classes

MetaData()

Read, write, and validate metadata.

class metad.MetaData[source]

Bases: object

Read, write, and validate metadata.

The MetaData object provides methods to help read, write, and validate metadata. It uses the JSON schema, which can be found in schema.json, to validate the structure of the metadata and applies additional logic checks internally.

Methods

add_constraint(constraint)

Add the constraint object to the metadata.

add_field(table_name, field)

add_foreign_key(foreign_key)

Add the foreign key object to the metadata.

add_table(table)

Add the table object to the metadata.

from_json(path_to_json)

Load a MetaData object from a JSON file.

get_foreign_keys([table_name])

get_table(table_name)

get_table_names()

get_tables()

set_foreign_keys(foreign_keys)

set_tables(tables)

to_json([path_to_json])

Export the MetaData object to a JSON file.

validate()

Validate the contents of this metadata object.

add_constraint(constraint)[source]

Add the constraint object to the metadata.

The constraint table object must conform the the JSON schema specification.

Parameters

constraint (dict) – A dictionary representing the constraint relationship.

add_field(table_name, field)[source]
add_foreign_key(foreign_key)[source]

Add the foreign key object to the metadata.

The foreign key object must conform the the JSON schema specification.

Parameters

foreign_key (dict) – A dictionary representing the foreign key relationship.

add_table(table)[source]

Add the table object to the metadata.

The table object must conform the the JSON schema specification.

Parameters

table (dict) – A dictionary representing the table.

static from_json(path_to_json)[source]

Load a MetaData object from a JSON file.

Parameters

path_to_json (str) – The path to the JSON file.

Returns

An instance of the MetaData object.

Return type

MetaData

get_foreign_keys(table_name=None)[source]
get_table(table_name)[source]
get_table_names()[source]
get_tables()[source]
set_foreign_keys(foreign_keys)[source]
set_tables(tables)[source]
to_json(path_to_json=None)[source]

Export the MetaData object to a JSON file.

Parameters
  • path_to_json (str, optional) – The path to the JSON file

  • should be created. If set to None, the JSON object (which) –

  • returned as a string. (is) –

validate()[source]

Validate the contents of this metadata object.

This validates the metadata against the JSON schema. It also performs additional logic checks (i.e. that table/field names are unique) to ensure that the metadata is valid.

Raises

AssertionError – If the metadata is not valid.