Relationships Between Assets and Timeseries

  • 15 September 2023
  • 5 replies

Userlevel 1

We are having a multilevel asset hierarchy in cdf, and ground level assets are only having timeseries linked.

we are trying to create Relationships between every parent asset and its child asset’s Timeseries.

we used python sdk code snippets to do this. Which are been attached to this for your reference.

In python sdk, after running the python relationship code, it is showing relationships are established. But in UI it is not showing from Assets, But we are able to see under Timeseries.

even after we tried interchanging the Source and target between assets and timeseries, same result.

one unique observation is that we could see the relationship established just for 1 asset which is having 3 timeseries linkage. rest others are not showing(they have more than 20 relations, even 500 for root asset.)

we would like to know are we following correct manner, or any restrictions are from CDF tool. plz help us in this regard.

from cognite.client import CogniteClient
from cognite.client.data_classes import Relationship

# Initialize the Cognite client
#client = CogniteClient()

# Define your project-specific data set ID (replace with your actual data set ID)
data_set_id = 434501746932720

# Define the maximum chunk size for asset_external_ids
max_chunk_size = 100

def establish_relationships_for_asset_new(asset_id):
# Retrieve the subtree assets
subtree_assets = list(client.assets.retrieve_subtree(external_id=asset_id).to_pandas()['externalId'])

# Split the subtree assets into chunks of max_chunk_size
chunks = [subtree_assets[i:i + max_chunk_size] for i in range(0, len(subtree_assets), max_chunk_size)]

relationships_to_create = []

# Process each chunk of asset_external_ids
for chunk in chunks:
time_series_list = client.time_series.list(asset_external_ids=chunk)

for ts in time_series_list:
relationship = Relationship(

# Create the relationships in Cognite
if relationships_to_create:
created_relationships = client.relationships.create(relationships_to_create)
print(f"Upserted {len(created_relationships)} relationships for asset {asset_id}")
print(f"No Timeseries in asset {asset_id} to upsert")



Best answer by Carin Meems 18 September 2023, 10:58

View original

5 replies

Badge +2

Yes its not showing for other assets


Thanks for reporting this. This looks like a bug.

Are you able to provide which project you are working on?

Userlevel 1

We are working in Dev Env of a chemical client who have a valid CDF subscription. would like to know if there is any workaround for this. Thanks!

Are you able to provide the project name? We think this is a bug on the UI.

Userlevel 3

Hi @Viswanadha Sai Akhil Pujyam, feel free to send a ticket to with the details so we can help you further if you need!