Skip to main content
Committed ⭐️⭐️⭐️
May 31, 2023 5:53 AM UTC
Solved

Uploading P&ID diagrams to CDF Through Python SDK [Community Contributed]

hello Community,

can anyone help me understand how to upload P&ID diagram files to CDF, Using Python SDK.

Anders  Albert
Expert ⭐️⭐️⭐️⭐️
May 31, 2023 6:33 AM UTC

If you want to use the Python-SDK, there is a method in the FilesAPI: https://cognite-sdk-python.readthedocs-hosted.com/en/latest/core_data_model.html#upload-a-file-or-directory

You would call it for example like this to upload a P&ID, which I assume is in a PDF format on your local drive.

from cognite.client import CogniteClient
from pathlib import Path


client = CogniteClient()

data_set_id = client.data_sets.retrieve("src:p&id").id
my_PandID = Path("data/my_super_P&ID.pdf")

client.files.upload(
my_PandID,
external_id=f"file:p&id:{my_PandID.name.replace(' ', '_')}",
name=my_PandID.name,
mime_type="application/pdf",
data_set_id=data_set_id,
)

 

4 replies

Michael Reisinger
Active ⭐️⭐️⭐️
Active ⭐️⭐️⭐️
May 31, 2023 6:27 AM UTC

Hi, we are uploading P&IDs via the file API from a python script, works pretty easy and stable

Anders  Albert
Expert ⭐️⭐️⭐️⭐️
Expert ⭐️⭐️⭐️⭐️
May 31, 2023 6:33 AM UTC

If you want to use the Python-SDK, there is a method in the FilesAPI: https://cognite-sdk-python.readthedocs-hosted.com/en/latest/core_data_model.html#upload-a-file-or-directory

You would call it for example like this to upload a P&ID, which I assume is in a PDF format on your local drive.

from cognite.client import CogniteClient
from pathlib import Path


client = CogniteClient()

data_set_id = client.data_sets.retrieve("src:p&id").id
my_PandID = Path("data/my_super_P&ID.pdf")

client.files.upload(
my_PandID,
external_id=f"file:p&id:{my_PandID.name.replace(' ', '_')}",
name=my_PandID.name,
mime_type="application/pdf",
data_set_id=data_set_id,
)

 

Dilini Fernando
Expert ⭐️⭐️⭐️⭐️
Expert ⭐️⭐️⭐️⭐️
Jun 15, 2023 6:06 AM UTC

Hi @Viswanadha Sai Akhil Pujyam,

I hope Anders’s reply was helped you to solve the issue. As of now, I will close this thread. Please feel free to reach out to us if you have more questions.

Best regards,
Dilini 

Dilini Fernando
Expert ⭐️⭐️⭐️⭐️
Expert ⭐️⭐️⭐️⭐️
Jul 7, 2023 2:09 PM UTC

Hi @Viswanadha Sai Akhil Pujyam,

We appreciate your contribution to our community hub! We have chosen to move your article to our hub's How-To section as it will greatly benefit other members of our community. Thank you for your understanding, and we look forward to seeing more great contributions from you in the future! 

Best regards,
Dilini