Schema

The Schema class defines a set of target fields for a data wranglng Method.

class whyqd.schema.schema.Schema(source: Optional[str] = None, schema: Optional[whyqd.models.schema_model.SchemaModel] = None)

Create and manage a target schema for a wrangling process.

Parameters:
  • source (str, optional) – Path to a json file containing a saved schema, default is None.
  • schema (SchemaModel, optional) – A dictionary conforming to the SchemaModel, default is None.
describe

Get the schema name, title and description.

  • name: Term used for filename and referencing. Will be lower-cased and spaces replaced with _
  • title: Human-readable term used as name.
  • description: Detailed description for the schema. Reference its objective and use-case.
Returns:
Return type:dict or None
get

Get the schema model.

Returns:
Return type:SchemaModel or None
set(schema: whyqd.models.schema_model.SchemaModel) → None

Update or create the schema.

Parameters:schema (SchemaModel) – A dictionary conforming to the SchemaModel.
get_field(name: str) → Optional[whyqd.models.fields_model.FieldModel]

Get a specific field from the list of fields defining this schema, called by a unique name.

Parameters:name (string) – Field names must be unique, so a valid name in the field list will have no collisions.
Returns:
Return type:FieldModel, or None if no such name
add_field(field: whyqd.models.fields_model.FieldModel) → None

Add the parameters for a specific field, called by a unique name. If the name already exists, then this will raise a ValueError.

Parameters:field (FieldModel) – A dictionary conforming to the FieldModel.
Raises:ValueError: if field already exists.
update_field(field: whyqd.models.fields_model.FieldModel) → None

Update the parameters for a specific field, called by a unique name. If the name does not exist, then this will raise a ValueError.

Parameters:field (FieldModel) – A dictionary conforming to the FieldModel.
Raises:ValueError: if field does not exist
remove_field(name: str) → None

Remove a specific field, called by a unique name.

Parameters:name (str) – Unique schema field name.
reorder_fields(order: List[uuid.UUID]) → None

Reorder a list of fields.

Parameters:order (list of UUID) –
Raises:ValueError if the list of uuid4s doesn’t conform to that in the list of fields.
get_field_constraints(name: str) → Optional[whyqd.models.constraints_model.ConstraintsModel]

Get the constraint parameters for a specific field defined in this schema, called by a unique name already in the schema.

Parameters:name (string) – Specific name for a field already in the Schema
Returns:
Return type:ConstraintsModel or None
set_field_constraints(name: str, constraints: Optional[whyqd.models.constraints_model.ConstraintsModel]) → None

Set the constraint parameters for a specific field to define this schema, called by a unique name already in the schema.

Parameters:
  • name (string) – Specific name for a field already in the Schema
  • constraints (ConstraintsModel or None) – A dictionary conforming to the ConstraintsModel, or None. If None, then constraints are deleted.
get_field_category(field: str, category: Union[bool, str]) → Optional[whyqd.models.category_model.CategoryModel]

Get a specific field from the list of fields defining this schema, called by a unique name.

Parameters:
  • field (str) – Field names must be unique, so a valid name in the field list will have no collisions.
  • category (str) – Category name for a destination category term from the schema.
Raises:

ValueError if FieldModel has not category in ConstraintModel.

Returns:

Return type:

List of , or None if no such name

get_json(hide_uuid: Optional[bool] = False) → Optional[pydantic.types.Json]

Get the json schema model.

Parameters:hide_uuid (str, default False) – Hide all UUIDs in the nested JSON output.
Returns:
Return type:Json or None
save(directory: str, filename: Optional[str] = None, created_by: Optional[str] = None, hide_uuid: Optional[bool] = False) → bool

Save schema as a json file.

Parameters:
  • directory (strthe destination directory) –
  • filename (defaults to schema name) –
  • overwrite (bool, True if overwrite existing file) –
  • created_by (string, or None, to define the schema creator/updater) –
  • hide_uuid (str, default False) – Hide all UUIDs in the nested JSON output.
Returns:

Return type:

bool True if saved