Generation of SDK¶
In the usage section, we wil work with the following model of for wind turbines.
Generation of SDK¶
To create a new Python SDK for the data model above, we assume you have installed cognite-pygen[cli]
withe the CLI option.
Furthermore, we have the model above located in the space sp_pygen_power
with the external id WindTurbine
and this is version 1
.
We generate a new SDK with the following command
pygen generate --space sp_pygen_power --external-id WindTurbine --version 1 --tenant-id <tenant-id> --client-id <client-id> --client-secret <client-secret> --cdf-cluster <cdf-cluster> --cdf-project <cdf-project>
This create the SDK with the following folder structure
wind_turbine/
├── _api
│ ├── __init__.py
│ ├── _core.py
│ ├── blade.py
│ ├── blade_query.py
│ ├── blade_sensor_positions.py
...
│ ├── wind_turbine.py
│ ├── wind_turbine_metmast.py
│ └── wind_turbine_query.py
├── data_classes
│ ├── `__init__`.py
│ ├── _core.py
│ ├── _blade.py
│ ├── _gearbox.py
│ ├── _generator.py
│ ├── _high_speed_shaft.py
│ ├── _main_shaft.py
│ ├── _metmast.py
│ ├── _nacelle.py
│ ├── _power_inverter.py
│ ├── _rotor.py
│ ├── _sensor_position.py
│ └── _wind_turbine.py
├── __init__.py
└── _api_client.py
This is now available and can be imported
Creating Client¶
Creating a Client using CogniteClient¶
First, we need an instantiate CogniteClient
, we can obtain this from any of the supported
methods in the cognite-sdk
:
from cognite.client import CogniteClient
Service Principal in Microsoft Entra
cognite_client = CogniteClient.default_oauth_client_credentials(
project="<my-cdf-project>",
cdf_cluster="<my-cdf-cluster>",
tenant_id="<my_domain>.onmicrosoft.com",
client_id="<my_service_principal_client_id>",
client_secret="<my_service_principal_client_secret>",
)
Interactive Login Microsoft Entra
cognite_client = CogniteClient.default_oauth_interactive(
project="<my-cdf-project>",
cdf_cluster="<my-cdf-cluster>",
tenant_id="cognitepygen.onmicrosoft.com",
client_id="<my_service_principal_client_id>",
)
Device Code
from cognite.client import ClientConfig
from cognite.client.credentials import OAuthDeviceCode
credentials = OAuthDeviceCode.default_for_azure_ad(
tenant_id="cognitepygen.onmicrosoft.com",
client_id="<device_client_id>",
cdf_cluster="<my-cdf-cluster>",
)
cognite_client = CogniteClient(
ClientConfig(client_name="client-name", project="<my-cdf-project>", credentials=credentials)
)
With this cognite_client
we can now instansiate a WindmillClient
from wind_turbine import WindTurbineClient
pygen = WindTurbineClient(cognite_client)
Creating a Client from TOML¶
An alternative way of creating a WindTurbineClient
is directly from a TOML
file.
We have a configuration file next to this notebook with the format
[cognite]
project = "<cdf-project>"
tenant_id = "<tenant-id>"
cdf_cluster = "<cdf-cluster>"
client_id = "<client-id>"
client_secret = "<client-secret>"
This enables us to create a WindTurbineClient
directly
pygen = WindTurbineClient.from_toml("config.toml")
The client has now been instantiated and is ready to go, listing filtering and retrieving.
pygen
with the following APIs available
.blade
.data_sheet
.gearbox
.generating_unit
.generator
.high_speed_shaft
.main_shaft
.metmast
.nacelle
.power_inverter
.rotor
.sensor_position
.sensor_time_series
.solar_panel
.wind_turbine
and with the methods:
.upsert - Create or update any instance.
.delete - Delete instances.