Deprecated
Templates
Create Template groups
- TemplateGroupsAPI.create(template_groups: cognite.client.data_classes.templates.TemplateGroup | collections.abc.Sequence[cognite.client.data_classes.templates.TemplateGroup]) cognite.client.data_classes.templates.TemplateGroup | cognite.client.data_classes.templates.TemplateGroupList
Create one or more template groups.
- Parameters
template_groups (TemplateGroup | Sequence[TemplateGroup]) – No description.
- Returns
Created template group(s)
- Return type
TemplateGroup | TemplateGroupList
Examples
Create a new template group:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes import TemplateGroup >>> client = 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") >>> client.templates.groups.create([template_group_1, template_group_2])
Upsert Template groups
- TemplateGroupsAPI.upsert(template_groups: cognite.client.data_classes.templates.TemplateGroup | collections.abc.Sequence[cognite.client.data_classes.templates.TemplateGroup]) 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 (TemplateGroup | Sequence[TemplateGroup]) – No description.
- Returns
Created template group(s)
- Return type
TemplateGroup | TemplateGroupList
Examples
Upsert a template group:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes import TemplateGroup >>> client = 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") >>> client.templates.groups.upsert([template_group_1, template_group_2])
Retrieve Template groups
- TemplateGroupsAPI.retrieve_multiple(external_ids: SequenceNotStr[str], ignore_unknown_ids: bool = False) TemplateGroupList
Retrieve multiple template groups by external id.
- Parameters
external_ids (SequenceNotStr[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 >>> client = CogniteClient() >>> res = client.templates.groups.retrieve_multiple(external_ids=["abc", "def"])
List Template groups
- TemplateGroupsAPI.list(limit: int | None = 25, owners: Optional[SequenceNotStr[str]] = None) 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
limit (int | None) – Maximum number of template groups to return. Defaults to 25. Set to -1, float(“inf”) or None to return all items.
owners (SequenceNotStr[str] | None) – Include template groups that have any of these values in their owner field.
- Returns
List of requested template groups
- Return type
TemplateGroupList
Examples
List template groups:
>>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> template_group_list = client.templates.groups.list(limit=5)
Delete Template groups
- TemplateGroupsAPI.delete(external_ids: Union[str, SequenceNotStr[str]], ignore_unknown_ids: bool = False) None
Delete one or more template groups.
- Parameters
external_ids (str | SequenceNotStr[str]) – External ID or list of external ids
ignore_unknown_ids (bool) – Ignore external IDs that are not found rather than throw an exception.
Examples
Delete template groups by external id:
>>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> client.templates.groups.delete(external_ids=["a", "b"])
Upsert a Template group version
- TemplateGroupVersionsAPI.upsert(external_id: str, version: TemplateGroupVersion) 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 >>> client = CogniteClient() >>> template_group = TemplateGroup("sdk-test-group", "This template group models Covid-19 spread") >>> client.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) >>> client.templates.versions.upsert(template_group.external_id, template_group_version)
List Temple Group versions
- TemplateGroupVersionsAPI.list(external_id: str, limit: int | None = 25, min_version: Optional[int] = None, max_version: Optional[int] = None) 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 | None) – Maximum number of template group versions to return. Defaults to 25. Set to -1, float(“inf”) or None to return all items.
min_version (int | None) – (Optional[int]): Exclude versions with a version number smaller than this.
max_version (int | None) – (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 >>> client = CogniteClient() >>> template_group_list = client.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.
Examples
Delete template groups by external id:
>>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> client.templates.versions.delete("sdk-test-group", 1)
Run a GraphQL query
- TemplatesAPI.graphql_query(external_id: str, version: int, query: str) 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 >>> client = CogniteClient() >>> query = ''' >>> { >>> countryQuery { >>> name, >>> demographics { >>> populationSize, >>> growthRate >>> }, >>> deaths { >>> datapoints(limit: 100) { >>> timestamp, >>> value >>> } >>> } >>> } >>> } >>> ''' >>> result = client.templates.graphql_query("template-group-ext-id", 1, query)
Create Template instances
- TemplateInstancesAPI.create(external_id: str, version: int, instances: cognite.client.data_classes.templates.TemplateInstance | collections.abc.Sequence[cognite.client.data_classes.templates.TemplateInstance]) 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 (TemplateInstance | Sequence[TemplateInstance]) – The instances to create.
- Returns
Created template instance(s).
- Return type
TemplateInstance | TemplateInstanceList
Examples
Create new template instances for Covid-19 spread:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes import TemplateInstance >>> client = 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) >>> } >>> ) >>> client.templates.instances.create("sdk-test-group", 1, [template_instance_1, template_instance_2])
Upsert Template instances
- TemplateInstancesAPI.upsert(external_id: str, version: int, instances: cognite.client.data_classes.templates.TemplateInstance | collections.abc.Sequence[cognite.client.data_classes.templates.TemplateInstance]) 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 (TemplateInstance | Sequence[TemplateInstance]) – The instances to create.
- Returns
Created template instance(s).
- Return type
TemplateInstance | TemplateInstanceList
Examples
Create new template instances for Covid-19 spread:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes import TemplateInstance >>> client = 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) >>> } >>> ) >>> client.templates.instances.upsert("sdk-test-group", 1, [template_instance_1, template_instance_2])
Update Template instances
- TemplateInstancesAPI.update(external_id: str, version: int, item: cognite.client.data_classes.templates.TemplateInstanceUpdate | collections.abc.Sequence[cognite.client.data_classes.templates.TemplateInstanceUpdate]) cognite.client.data_classes.templates.TemplateInstance | cognite.client.data_classes.templates.TemplateInstanceList
Update one or more template instances :param external_id: No description. :type external_id: str :param version: No description. :type version: int :param item: Templates instance(s) to update :type item: TemplateInstanceUpdate | Sequence[TemplateInstanceUpdate]
- Returns
Updated template instance(s)
- Return type
TemplateInstance | TemplateInstanceList
Examples
Perform a partial update on a template instance:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes import TemplateInstanceUpdate >>> client = CogniteClient() >>> my_update = TemplateInstanceUpdate(external_id="test").field_resolvers.add({ "name": ConstantResolver("Norway") }) >>> res = client.templates.instances.update("sdk-test-group", 1, my_update)
Retrieve Template instances
- TemplateInstancesAPI.retrieve_multiple(external_id: str, version: int, external_ids: SequenceNotStr[str], ignore_unknown_ids: bool = False) 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 (SequenceNotStr[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 >>> client = CogniteClient() >>> res = client.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 | None = 25, data_set_ids: Optional[Sequence[int]] = None, template_names: Optional[SequenceNotStr[str]] = None) 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 | None) – 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 (Sequence[int] | None) – (Optional[Sequence[int]]): Only include instances which has one of these values in their data_set_id field.
template_names (SequenceNotStr[str] | None) – (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 >>> client = CogniteClient() >>> template_instances_list = client.templates.instances.list("template-group-ext-id", 1, limit=5)
Delete Template instances
- TemplateInstancesAPI.delete(external_id: str, version: int, external_ids: SequenceNotStr[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 (SequenceNotStr[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.
Examples
Delete template groups by external id:
>>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> client.templates.instances.delete("sdk-test-group", 1, external_ids=["a", "b"])
Create Template Views
- TemplateViewsAPI.create(external_id: str, version: int, views: cognite.client.data_classes.templates.View | collections.abc.Sequence[cognite.client.data_classes.templates.View]) cognite.client.data_classes.templates.View | cognite.client.data_classes.templates.ViewList
Create one or more template views.
- Parameters
- Returns
Created view(s).
- Return type
Examples
Create new views:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes.templates import View, Source >>> client = CogniteClient() >>> view = View(external_id="view", >>> source=Source( >>> type='events', >>> filter={ >>> "startTime": { >>> "min": "$startTime" >>> }, >>> "type": "Test", >>> } >>> mappings={ >>> "author": "metadata/author" >>> } >>> ) >>> ) >>> client.templates.views.create("sdk-test-group", 1, [view])
Upsert Template Views
- TemplateViewsAPI.upsert(external_id: str, version: int, views: cognite.client.data_classes.templates.View | collections.abc.Sequence[cognite.client.data_classes.templates.View]) cognite.client.data_classes.templates.View | cognite.client.data_classes.templates.ViewList
Upsert one or more template views.
- Parameters
- Returns
Created view(s).
- Return type
Examples
Upsert new views:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes.templates import View >>> client = CogniteClient() >>> view = View(external_id="view", >>> source=Source( >>> type: 'events', >>> filter: { >>> startTime: { >>> min: "$startTime" >>> }, >>> type: "Test", >>> } >>> mappings: { >>> author: "metadata/author" >>> } >>> ) >>> ) >>> client.templates.views.upsert("sdk-test-group", 1, [view])
List Template Views
- TemplateViewsAPI.list(external_id: str, version: int, limit: int | None = 25) 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 | None) – 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
Examples
List views:
>>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> client.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: dict[str, Any] | None, limit: int | None = 25) 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.
view_external_id (str) – No description.
input (dict[str, Any] | None) – The input for the View.
limit (int | None) – 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 >>> client = CogniteClient() >>> client.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[SequenceNotStr[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 (SequenceNotStr[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.
Examples
Delete views by external id:
>>> from cognite.client import CogniteClient >>> client = CogniteClient() >>> client.templates.views.delete("sdk-test-group", 1, external_id=["a", "b"])