Deprecated

Templates

Create Template groups

TemplateGroupsAPI.create(template_groups: Union[cognite.client.data_classes.templates.TemplateGroup, Sequence[cognite.client.data_classes.templates.TemplateGroup]]) → Union[cognite.client.data_classes.templates.TemplateGroup, cognite.client.data_classes.templates.TemplateGroupList]

Create one or more template groups.

Parameters:template_groups (Union[TemplateGroup, Sequence[TemplateGroup]]) –
Returns:Created template group(s)
Return type:Union[TemplateGroup, TemplateGroupList]

Examples

Create a new template group:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import TemplateGroup
>>> c = CogniteClient()
>>> template_group_1 = TemplateGroup("sdk-test-group", "This is a test group")
>>> template_group_2 = TemplateGroup("sdk-test-group-2", "This is another test group")
>>> c.templates.groups.create([template_group_1, template_group_2])

Upsert Template groups

TemplateGroupsAPI.upsert(template_groups: Union[cognite.client.data_classes.templates.TemplateGroup, Sequence[cognite.client.data_classes.templates.TemplateGroup]]) → Union[cognite.client.data_classes.templates.TemplateGroup, cognite.client.data_classes.templates.TemplateGroupList]

Upsert one or more template groups. Will overwrite existing template group(s) with the same external id(s).

Parameters:template_groups (Union[TemplateGroup, Sequence[TemplateGroup]]) –
Returns:Created template group(s)
Return type:Union[TemplateGroup, TemplateGroupList]

Examples

Upsert a template group:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import TemplateGroup
>>> c = CogniteClient()
>>> template_group_1 = TemplateGroup("sdk-test-group", "This is a test group")
>>> template_group_2 = TemplateGroup("sdk-test-group-2", "This is another test group")
>>> c.templates.groups.upsert([template_group_1, template_group_2])

Retrieve Template groups

TemplateGroupsAPI.retrieve_multiple(external_ids: Sequence[str], ignore_unknown_ids: bool = False) → cognite.client.data_classes.templates.TemplateGroupList

Retrieve multiple template groups by external id.

Parameters:
  • external_ids (Sequence[str]) – External IDs
  • ignore_unknown_ids (bool) – Ignore external IDs that are not found rather than throw an exception.
Returns:

The requested template groups.

Return type:

TemplateGroupList

Examples

Get template groups by external id:

>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> res = c.templates.groups.retrieve_multiple(external_ids=["abc", "def"])

List Template groups

TemplateGroupsAPI.list(limit: int = 25, owners: Optional[Sequence[str]] = None) → cognite.client.data_classes.templates.TemplateGroupList

Lists template groups stored in the project based on a query filter given in the payload of this request. Up to 1000 template groups can be retrieved in one operation.

Parameters:
  • owners (Sequence[str]) – Include template groups that have any of these values in their owner field.
  • limit (int) – Maximum number of template groups to return. Defaults to 25. Set to -1, float(“inf”) or None to return all items.
Returns:

List of requested template groups

Return type:

TemplateGroupList

Examples

List template groups:

>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> template_group_list = c.templates.groups.list(limit=5)

Delete Template groups

TemplateGroupsAPI.delete(external_ids: Union[str, Sequence[str]], ignore_unknown_ids: bool = False) → None

Delete one or more template groups.

Parameters:
  • external_ids (Union[str, Sequence[str]]) – External ID or list of external ids
  • ignore_unknown_ids (bool) – Ignore external IDs that are not found rather than throw an exception.
Returns:

None

Examples

Delete template groups by external id:

>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> c.templates.groups.delete(external_ids=["a", "b"])

Upsert a Template group version

TemplateGroupVersionsAPI.upsert(external_id: str, version: cognite.client.data_classes.templates.TemplateGroupVersion) → cognite.client.data_classes.templates.TemplateGroupVersion

Upsert a template group version. A Template Group update supports specifying different conflict modes, which is used when an existing schema already exists.

Patch -> It diffs the new schema with the old schema and fails if there are breaking changes. Update -> It sets the new schema as schema of a new version. Force -> It ignores breaking changes and replaces the old schema with the new schema. The default mode is “patch”.

Parameters:
  • external_id (str) – The external id of the template group.
  • version (TemplateGroupVersion) – The GraphQL schema of this version.
Returns:

Created template group version

Return type:

TemplateGroupVersion

Examples

create a new template group version modeling Covid-19:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import TemplateGroup
>>> c = CogniteClient()
>>> template_group = TemplateGroup("sdk-test-group", "This template group models Covid-19 spread")
>>> c.templates.groups.create(template_group)
>>> schema = '''
>>>     type Demographics @template {
>>>         "The amount of people"
>>>         populationSize: Int,
>>>         "The population growth rate"
>>>         growthRate: Float,
>>>     }
>>>     type Country @template {
>>>         name: String,
>>>         demographics: Demographics,
>>>         deaths: TimeSeries,
>>>         confirmed: TimeSeries,
>>>     }'''
>>> template_group_version = TemplateGroupVersion(schema)
>>> c.templates.versions.upsert(template_group.external_id, template_group_version)

List Temple Group versions

TemplateGroupVersionsAPI.list(external_id: str, limit: int = 25, min_version: Optional[int] = None, max_version: Optional[int] = None) → cognite.client.data_classes.templates.TemplateGroupVersionList

Lists versions of a specified template group. Up to 1000 template group version can be retrieved in one operation.

Parameters:
  • external_id (str) – The external id of the template group.
  • limit (int) – Maximum number of template group versions to return. Defaults to 25. Set to -1, float(“inf”) or None to return all items.
  • min_version – (Optional[int]): Exclude versions with a version number smaller than this.
  • max_version – (Optional[int]): Exclude versions with a version number larger than this.
Returns:

List of requested template group versions

Return type:

TemplateGroupVersionList

Examples

List template group versions:

>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> template_group_list = c.templates.versions.list("template-group-ext-id", limit=5)

Delete a Temple Group version

TemplateGroupVersionsAPI.delete(external_id: str, version: int) → None

Delete a template group version.

Parameters:
  • external_id (str) – External ID of the template group.
  • version (int) – The version of the template group to delete.
Returns:

None

Examples

Delete template groups by external id:

>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> c.templates.versions.delete("sdk-test-group", 1)

Run a GraphQL query

TemplatesAPI.graphql_query(external_id: str, version: int, query: str) → cognite.client.data_classes.templates.GraphQlResponse

Run a GraphQL Query. To learn more, see https://graphql.org/learn/

Parameters:
  • external_id (str) – The external id of the template group.
  • version (int) – The version of the template group to run the query on.
  • query (str) – The GraphQL query to run.
Returns:

the result of the query.

Return type:

GraphQlResponse

Examples

Run a GraphQL query:

>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> query = '''
>>>    {
>>>        countryQuery {
>>>           name,
>>>           demographics {
>>>               populationSize,
>>>               growthRate
>>>           },
>>>           deaths {
>>>               datapoints(limit: 100) {
>>>                   timestamp,
>>>                   value
>>>               }
>>>           }
>>>        }
>>>    }
>>>    '''
>>> result = c.templates.graphql_query("template-group-ext-id", 1, query)

Create Template instances

TemplateInstancesAPI.create(external_id: str, version: int, instances: Union[cognite.client.data_classes.templates.TemplateInstance, Sequence[cognite.client.data_classes.templates.TemplateInstance]]) → Union[cognite.client.data_classes.templates.TemplateInstance, cognite.client.data_classes.templates.TemplateInstanceList]

Create one or more template instances.

Parameters:
  • external_id (str) – The external id of the template group.
  • version (int) – The version of the template group to create instances for.
  • instances (Union[TemplateInstance, Sequence[TemplateInstance]]) – The instances to create.
Returns:

Created template instance(s).

Return type:

Union[TemplateInstance, TemplateInstanceList]

Examples

Create new template instances for Covid-19 spread:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import TemplateInstance
>>> c = CogniteClient()
>>> template_instance_1 = TemplateInstance(external_id="norway",
>>>                               template_name="Country",
>>>                               field_resolvers={
>>>                                   "name": ConstantResolver("Norway"),
>>>                                   "demographics": ConstantResolver("norway_demographics"),
>>>                                   "deaths": ConstantResolver("Norway_deaths"),
>>>                                   "confirmed": ConstantResolver("Norway_confirmed"),
>>>                                   }
>>>                               )
>>> template_instance_2 = TemplateInstance(external_id="norway_demographics",
>>>                               template_name="Demographics",
>>>                               field_resolvers={
>>>                                   "populationSize": ConstantResolver(5328000),
>>>                                   "growthRate": ConstantResolver(value=0.02)
>>>                                   }
>>>                               )
>>> c.templates.instances.create("sdk-test-group", 1, [template_instance_1, template_instance_2])

Upsert Template instances

TemplateInstancesAPI.upsert(external_id: str, version: int, instances: Union[cognite.client.data_classes.templates.TemplateInstance, Sequence[cognite.client.data_classes.templates.TemplateInstance]]) → Union[cognite.client.data_classes.templates.TemplateInstance, cognite.client.data_classes.templates.TemplateInstanceList]

Upsert one or more template instances. Will overwrite existing instances.

Parameters:
  • external_id (str) – The external id of the template group.
  • version (int) – The version of the template group to create instances for.
  • instances (Union[TemplateInstance, Sequence[TemplateInstance]]) – The instances to create.
Returns:

Created template instance(s).

Return type:

Union[TemplateInstance, TemplateInstanceList]

Examples

Create new template instances for Covid-19 spread:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import TemplateInstance
>>> c = CogniteClient()
>>> template_instance_1 = TemplateInstance(external_id="norway",
>>>        template_name="Country",
>>>        field_resolvers={
>>>            "name": ConstantResolver("Norway"),
>>>            "demographics": ConstantResolver("norway_demographics"),
>>>            "deaths": ConstantResolver("Norway_deaths"),
>>>            "confirmed": ConstantResolver("Norway_confirmed"),
>>>        }
>>>    )
>>> template_instance_2 = TemplateInstance(external_id="norway_demographics",
>>>       template_name="Demographics",
>>>       field_resolvers={
>>>           "populationSize": ConstantResolver(5328000),
>>>           "growthRate": ConstantResolver(0.02)
>>>           }
>>>   )
>>> c.templates.instances.upsert("sdk-test-group", 1, [template_instance_1, template_instance_2])

Update Template instances

TemplateInstancesAPI.update(external_id: str, version: int, item: Union[cognite.client.data_classes.templates.TemplateInstanceUpdate, Sequence[cognite.client.data_classes.templates.TemplateInstanceUpdate]]) → Union[cognite.client.data_classes.templates.TemplateInstance, cognite.client.data_classes.templates.TemplateInstanceList]

Update one or more template instances :param item: Templates instance(s) to update :type item: Union[TemplateInstanceUpdate, Sequence[TemplateInstanceUpdate]]

Returns:Updated template instance(s)
Return type:Union[TemplateInstance, TemplateInstanceList]

Examples

Perform a partial update on a template instance:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes import TemplateInstanceUpdate
>>> c = CogniteClient()
>>> my_update = TemplateInstanceUpdate(external_id="test").field_resolvers.add({ "name": ConstantResolver("Norway") })
>>> res = c.templates.instances.update("sdk-test-group", 1, my_update)

Retrieve Template instances

TemplateInstancesAPI.retrieve_multiple(external_id: str, version: int, external_ids: Sequence[str], ignore_unknown_ids: bool = False) → cognite.client.data_classes.templates.TemplateInstanceList

Retrieve multiple template instances by external id.

Parameters:
  • external_id (str) – The template group to retrieve instances from.
  • version (int) – The version of the template group.
  • external_ids (Sequence[str]) – External IDs of the instances.
  • ignore_unknown_ids (bool) – Ignore external IDs that are not found rather than throw an exception.
Returns:

The requested template groups.

Return type:

TemplateInstanceList

Examples

Get template instances by external id:

>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> res = c.templates.instances.retrieve_multiple(external_id="sdk-test-group", version=1, external_ids=["abc", "def"])

List Template instances

TemplateInstancesAPI.list(external_id: str, version: int, limit: int = 25, data_set_ids: Optional[Sequence[int]] = None, template_names: Optional[Sequence[str]] = None) → cognite.client.data_classes.templates.TemplateInstanceList

Lists instances in a template group. Up to 1000 template instances can be retrieved in one operation.

Parameters:
  • external_id (str) – The external id of the template group.
  • version (int) – The version of the template group.
  • limit (int) – Maximum number of template group versions to return. Defaults to 25. Set to -1, float(“inf”) or None to return all items.
  • data_set_ids – (Optional[Sequence[int]]): Only include instances which has one of these values in their data_set_id field.
  • template_names – (Optional[Sequence[str]]): Only include instances which has one of these values in their template_name field.
Returns:

List of requested template instances

Return type:

TemplateInstanceList

Examples

List template instances:

>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> template_instances_list = c.templates.instances.list("template-group-ext-id", 1, limit=5)

Delete Template instances

TemplateInstancesAPI.delete(external_id: str, version: int, external_ids: Sequence[str], ignore_unknown_ids: bool = False) → None

Delete one or more template instances.

Parameters:
  • external_id (str) – External ID of the template group.
  • version (int) – The version of the template group.
  • external_ids (Sequence[str]) – The external ids of the template instances to delete
  • ignore_unknown_ids (bool) – Ignore external IDs that are not found rather than throw an exception.
Returns:

None

Examples

Delete template groups by external id:

>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> c.templates.instances.delete("sdk-test-group", 1, external_ids=["a", "b"])

Create Template Views

TemplateViewsAPI.create(external_id: str, version: int, views: Union[cognite.client.data_classes.templates.View, Sequence[cognite.client.data_classes.templates.View]]) → Union[cognite.client.data_classes.templates.View, cognite.client.data_classes.templates.ViewList]

Create one or more template views.

Parameters:
  • external_id (str) – The external id of the template group.
  • version (int) – The version of the template group to create views for.
  • views (Union[View, Sequence[View]]) – The views to create.
Returns:

Created view(s).

Return type:

Union[View, ViewList]

Examples

Create new views:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes.templates import View, Source
>>> c = CogniteClient()
>>> view = View(external_id="view",
>>>             source=Source(
>>>                 type='events',
>>>                 filter={
>>>                     "startTime": {
>>>                         "min": "$startTime"
>>>                     },
>>>                     "type": "Test",
>>>                 }
>>>                 mappings={
>>>                     "author": "metadata/author"
>>>                 }
>>>             )
>>>        )
>>> c.templates.views.create("sdk-test-group", 1, [view])

Upsert Template Views

TemplateViewsAPI.upsert(external_id: str, version: int, views: Union[cognite.client.data_classes.templates.View, Sequence[cognite.client.data_classes.templates.View]]) → Union[cognite.client.data_classes.templates.View, cognite.client.data_classes.templates.ViewList]

Upsert one or more template views.

Parameters:
  • external_id (str) – The external id of the template group.
  • version (int) – The version of the template group to create views for.
  • views (Union[View, Sequence[View]]) – The views to create.
Returns:

Created view(s).

Return type:

Union[View, ViewList]

Examples

Upsert new views:

>>> from cognite.client import CogniteClient
>>> from cognite.client.data_classes.templates import View
>>> c = CogniteClient()
>>> view = View(external_id="view",
>>>             source=Source(
>>>                 type: 'events',
>>>                 filter: {
>>>                     startTime: {
>>>                         min: "$startTime"
>>>                     },
>>>                     type: "Test",
>>>                 }
>>>                 mappings: {
>>>                     author: "metadata/author"
>>>                 }
>>>             )
>>>        )
>>> c.templates.views.upsert("sdk-test-group", 1, [view])

List Template Views

TemplateViewsAPI.list(external_id: str, version: int, limit: int = 25) → cognite.client.data_classes.templates.ViewList

Lists view in a template group. Up to 1000 views can be retrieved in one operation.

Parameters:
  • external_id (str) – The external id of the template group.
  • version (int) – The version of the template group.
  • limit (int) – Maximum number of views to return. Defaults to 25. Set to -1, float(“inf”) or None to return all items.
Returns:

List of requested views

Return type:

ViewList

Examples

List views:

>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> c.templates.views.list("template-group-ext-id", 1, limit=5)

Resolve Template View

TemplateViewsAPI.resolve(external_id: str, version: int, view_external_id: str, input: Optional[Dict[str, Any]], limit: int = 25) → cognite.client.data_classes.templates.ViewResolveList

Resolves a View. It resolves the source specified in a View with the provided input and applies the mapping rules to the response.

Parameters:
  • external_id (str) – The external id of the template group.
  • version (int) – The version of the template group.
  • input (Optional[Dict[str, any]]) – The input for the View.
  • limit (int) – Maximum number of views to return. Defaults to 25. Set to -1, float(“inf”) or None to return all items.
Returns:

The resolved items.

Return type:

ViewResolveList

Examples

Resolve view:

>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> c.templates.views.resolve("template-group-ext-id", 1, "view", { "startTime": 10 }, limit=5)

Delete Template Views

TemplateViewsAPI.delete(external_id: str, version: int, view_external_id: Union[Sequence[str], str], ignore_unknown_ids: bool = False) → None

Delete one or more views.

Parameters:
  • external_id (str) – External ID of the template group.
  • version (int) – The version of the template group.
  • view_external_id (Union[Sequence[str], str]) – The external ids of the views to delete
  • ignore_unknown_ids (bool) – Ignore external IDs that are not found rather than throw an exception.
Returns:

None

Examples

Delete views by external id:

>>> from cognite.client import CogniteClient
>>> c = CogniteClient()
>>> c.templates.views.delete("sdk-test-group", 1, external_id=["a", "b"])