treeschema.catalog.data_field

class DataField(data_field_inputs: [<class 'int'>, <class 'str'>, typing.Dict], data_store_id: int, data_schema_id: int, *args, **kwargs)

Bases: treeschema.catalog.base_serializer.TreeSchemaSerializer

An object that represents a single data field.

Create a data field object with either the ID of a data field or the fully defined data field object as a dictionary.

Parameters
  • data_field_inputs – the inputs to create or retrieve the data field

  • data_store_id – The ID of the data store that this field belongs to

  • data_schema_id – The ID of the data schema that this field belongs to

add_tags(tags: List[str]) → Dict

Adds one or more tags to the data field

Parameters

tags – a list of tags, a single tag can also be passed

Returns

the API response

>>> my_field = ts.data_store('my data store').schema('some schema').field('my_field')
>>> my_field.add_tags(['new_tag', 'a second new tag'])
field_value(field_value_inputs: [<class 'int'>, typing.Dict], refresh: bool = False, raise_if_not_exist: bool = False) → treeschema.catalog.field_value.FieldValue

Creates or retrieves a field value object, Inputs can be an integer (for the field ID), a string (for the sample value) or a dictionary of values used to create the field value

Parameters
  • field_inputs – the inputs used to create or retrieve the field

  • refresh – whether or not to force a refresh from the database, the default is False

  • raise_if_not_exist – default is False, if True will raise a treescheam.exceptions.DataAssetDoesNotExist exception if the field value does not exists, when False None is returned for field values that do not exist

Returns

a FieldValue object

>>> field_value = my_field.field_value(1)
>>> field_value = my_field.field_value('101')
>>> field_value = my_field.field_value({
        'field_value': '02', 
        'description': 'a status code value'
    })

The required fields are managed by the API, all required fields for sample values can be found in BODY of the the API to Create a Field Value

property field_values
get_field_values(refresh: bool = False) → List

Retrieves all field values for this field from Tree Schema

remove_tags(tags: [<class 'str'>, typing.List[str]]) → Dict

Removes one or more tags from the data field

Parameters

tags – a list of tags, a single tag can also be passed

Returns

the API response

>>> my_field = ts.data_store('my data store').schema('some schema').field('my_field')
>>> my_field.remove_tags(['new_tag'])
>>> my_field.remove_tags('single tag')
property tags

Retrieves the tags for a given data store. If the tags have not already been retrieved for the data store then the existing tags are fetched from Tree Schema

>>> my_data_store = ts.data_store('my data store')
>>> my_data_store.tags
    # ['tag_1', 'tag_2']
update(*, _type: str = None, data_type: str = None, data_format: str = None, description: str = None, nullable: bool = None, tech_poc: [<class 'int'>, <class 'treeschema.catalog.user.TreeSchemaUser'>] = None, steward: [<class 'int'>, <class 'treeschema.catalog.user.TreeSchemaUser'>] = None)

Update an existing field. Only keyword arguments can be provided, positional arguments are not allowed.

Parameters
  • _type – the type of field, must be a Tree Schema field type

  • data_type – the data type of field, must be JSON compatible data type

  • data_format – a free form string that represents the data format

  • description – The description for the field

  • nullable – Whether or not the field can be null, True if yes, False if no

  • tech_poc – The technical point of contact

  • steward – The data steward

Returns

a DataField, an updated version of itself