Apply containers
- async AsyncCogniteClient.data_modeling.containers.apply(
- container: ContainerApply | Sequence[ContainerApply],
Add or update (upsert) containers.
- Parameters:
container (ContainerApply | Sequence[ContainerApply]) – Container(s) to create or update.
- Returns:
Created container(s)
- Return type:
Examples
Create a new container:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes.data_modeling import ( ... ContainerApply, ... ContainerPropertyApply, ... Text, ... Float64, ... ) >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> container = ( ... ContainerApply( ... space="mySpace", ... external_id="myContainer", ... properties={ ... "name": ContainerPropertyApply(type=Text, name="name"), ... "numbers": ContainerPropertyApply( ... type=Float64(is_list=True, max_list_size=200), ... description="very important numbers", ... ), ... }, ... ), ... ) >>> res = client.data_modeling.containers.apply(container)
Create new container with unit-aware properties:
>>> from cognite.client.data_classes.data_modeling import Float64 >>> from cognite.client.data_classes.data_modeling.data_types import UnitReference >>> container = ContainerApply( ... space="mySpace", ... external_id="myContainer", ... properties={ ... "maxPressure": ContainerPropertyApply( ... nullable=True, ... description="Maximum Pump Pressure", ... name="maxPressure", ... type=Float64( ... unit=UnitReference(external_id="pressure:bar", source_unit="BAR") ... ), ... ), ... "rotationConfigurations": ContainerPropertyApply( ... nullable=True, ... description="Rotation Configurations", ... name="rotationConfigurations", ... type=Float64( ... is_list=True, ... unit=UnitReference(external_id="angular_velocity:rev-per-min"), ... ), ... ), ... }, ... ) >>> res = client.data_modeling.containers.apply(container)
Example container with all available properties (for illustration purposes). Note that
ContainerPropertyApplyhas several options not shown here, likename,description,nullable,auto_increment,default_valueandimmutablethat may be specified, depending on the choice of property type (e.g.auto_incrementonly works with integer types).>>> from cognite.client.data_classes.data_modeling.data_types import ( ... UnitReference, ... EnumValue, ... ) >>> from cognite.client.data_classes.data_modeling.data_types import ( ... Boolean, ... Date, ... DirectRelation, ... Enum, ... FileReference, ... Float32, ... Float64, ... Int32, ... Int64, ... Json, ... SequenceReference, ... Text, ... TimeSeriesReference, ... Timestamp, ... ) >>> container_properties = { ... "prop01": ContainerPropertyApply(Boolean), ... "prop02": ContainerPropertyApply(Boolean(is_list=True)), ... "prop03": ContainerPropertyApply(Date), ... "prop04": ContainerPropertyApply(Date(is_list=True)), ... "prop05": ContainerPropertyApply(Timestamp), ... "prop06": ContainerPropertyApply(Timestamp(is_list=True)), ... "prop07": ContainerPropertyApply(Text), ... "prop08": ContainerPropertyApply(Text(is_list=True)), ... # Note: DirectRelation(list) support `container`: The (optional) required type for the node ... # the direct relation points to. ... "prop09": ContainerPropertyApply(DirectRelation), ... "prop10": ContainerPropertyApply(DirectRelation(is_list=True)), ... # Note: Enum also support `unknown_value`: The value to use when the enum value is unknown. ... "prop11": ContainerPropertyApply( ... Enum( ... { ... "Closed": EnumValue("Valve is closed"), ... "Opened": EnumValue("Valve is opened"), ... } ... ) ... ), ... # Note: Floats support unit references, e.g. `unit=UnitReference("pressure:bar")`: ... "prop12": ContainerPropertyApply(Float32), ... "prop13": ContainerPropertyApply(Float32(is_list=True)), ... "prop14": ContainerPropertyApply(Float64), ... "prop15": ContainerPropertyApply(Float64(is_list=True)), ... "prop16": ContainerPropertyApply(Int32), ... "prop17": ContainerPropertyApply(Int32(is_list=True)), ... "prop18": ContainerPropertyApply(Int64), ... "prop19": ContainerPropertyApply(Int64(is_list=True)), ... "prop20": ContainerPropertyApply(Json), ... "prop21": ContainerPropertyApply(Json(is_list=True)), ... "prop22": ContainerPropertyApply(SequenceReference), ... "prop23": ContainerPropertyApply(SequenceReference(is_list=True)), ... # Note: It is adviced to represent files and time series directly as nodes ... # instead of referencing existing: ... "prop24": ContainerPropertyApply(FileReference), ... "prop25": ContainerPropertyApply(FileReference(is_list=True)), ... "prop26": ContainerPropertyApply(TimeSeriesReference), ... "prop27": ContainerPropertyApply(TimeSeriesReference(is_list=True)), ... } >>> container = ContainerApply( ... space="my-space", ... external_id="my-everything-container", ... properties=container_properties, ... )