treeschema.catalog.data_store

class DataStore(data_store_inputs: [<class 'int'>, typing.Dict])

Bases: treeschema.catalog.base_serializer.TreeSchemaSerializer

An object that represents a single data store. Data stores contain schemas and each data store object is able to interact with the schemas that belong to it.

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

Parameters
  • id – the ID for the data store

  • inputs – a dictionary of inputs that can

fully serialize a data store

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

Adds one or more tags to the data store

Parameters

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

Returns

the API response

>>> my_data_store = ts.data_store('my data store')
>>> my_data_store.add_tags(['new_tag', 'a second new tag'])
>>> my_data_store.add_tags('single tag')
delete_schemas(remove_schemas: [<class 'int'>, typing.List[int], <class 'treeschema.catalog.data_schema.DataSchema'>, typing.List[treeschema.catalog.data_schema.DataSchema]]) → bool

Deletes (deprecates) a single schema or list of schemas from the data store

Parameters

remove_schemas – a single schema or a list of schemas (these can be the schema ID or a list of DataSchema objects)

Returns

True if the schemas are deprecated

>>> my_data_store = ts.data_store('my data store')
>>> delete_schema = my_data_store.schema('some.schema')
>>> my_data_store.delete_schemas([delete_schema])
True
get_schemas(refresh: bool = False) → List

Retrieves all schemas from the data store. After this is called for the first time the schemas are cached locally.

Parameters

refresh – Default False, if True, will force all schemas to be retrieved from Tree Schema and not the local cache

Returns

a list of DataSchema objects that belong to this data store

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

Removes one or more tags from the data store

Parameters

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

Returns

the API response

>>> my_data_store = ts.data_store('my data store')
>>> my_data_store.remove_tags(['new_tag'])
>>> my_data_store.remove_tags('single tag')
schema(schema_inputs: [<class 'int'>, typing.Dict], refresh: bool = False, pre_fetch: bool = True, raise_if_not_exist: bool = False) → treeschema.catalog.data_schema.DataSchema

Creates or retrieves a DataSchema object, Inputs can be an integer (for the schema ID), a string (for the schema name), or a dictionary of values used to create the schema

Parameters
  • schema_inputs – the inputs used to create or retrieve the data schema

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

  • pre_fetch – whether or not to pre-fetch all of the schemas for this data store during the initial load. This should primiarly be used when the inputs are a dictionary and you have already batch-retrieved the data assets required. Note - you do have the option to not pre-fetch and then request a pre-fetch later.

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

Returns

a Data Schema object

>>> my_data_store = ts.data_store('my data store')
>>> schema_1 = my_data_store.schema(1)
>>> schema_2 = my_data_store.schema('second.schema')
>>> field_3 = my_data_store.field({'name': 'new_field', 'type': 'other'})

The required fields are managed by the API, all required fields for data schemas can be found in BODY of the the API to Create a Data Schema

property schemas
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']