7. Interact with KTypes through the SDK#

7.1. Setting up#

Before you run this tutorial: make sure to have access to a DSMS-instance of your interest, alongwith with installation of this package and have establised access to the DSMS through DSMS-SDK (refer to Connecting to DSMS)

Import the needed classes and functions.

[1]:
from dsms import DSMS, KType

Now source the environmental variables from an .env file and start the DSMS-session.

[2]:
dsms = DSMS(env=".env")

7.2. Create KTypes#

New KTypes can be created by a simple class inititation.

[3]:
ktype = KType(
        id='batch',
        name='Batch'
)

ktype
[3]:
ktype:
  id: batch
  name: Batch
  webform: null
  json_schema: null
  created_at: null
  updated_at: null

The commit method should be executed to synchronize the changes with the DSMS SDK.

[4]:
dsms.add(ktype)
dsms.commit()

The type object will automatically get updated with after the commit.

[5]:
ktype
[5]:
ktype:
  id: batch
  name: Batch
  webform: null
  json_schema: null
  created_at: '2025-04-09T10:50:13.094447'
  updated_at: '2025-04-09T10:50:13.094447'

7.3. Update KTypes#

The ktype object can be fetched using its id.

[6]:
ktype = dsms.ktypes.Batch
ktype
[6]:
ktype:
  id: batch
  name: Batch
  webform: null
  json_schema: null
  created_at: '2025-04-09T10:50:13.094447'
  updated_at: '2025-04-09T10:50:13.094447'

We can change e.g. the name of the ktype

[7]:
ktype.name = 'Batches'
dsms.commit()
/app/dsms/core/dsms.py:175: UserWarning: Nothing to commit. No changes have been made to the DSMS instance.If you would like to add&/delete KItems, KTypes or AppConfigs,please use: `dsms.add(my_object)` or dsms.delete(my_object)`before running `dsms.commit()`.
  warnings.warn(

After the committing, we can see the changes of the ktype

[8]:
ktype
[8]:
ktype:
  id: batch
  name: Batches
  webform: null
  json_schema: null
  created_at: '2025-04-09T10:50:13.094447'
  updated_at: '2025-04-09T10:50:13.094447'

7.5. Fetching KTypes#

The existing KTypes can be fetched as follows.

[9]:
for iktype in dsms.ktypes:
    print(iktype)
ktype:
  id: organization
  name: null
  webform: null
  json_schema: null
  created_at: '2025-01-22T09:57:12.620432'
  updated_at: '2025-01-22T09:57:12.620432'

ktype:
  id: expert
  name: null
  webform: null
  json_schema: null
  created_at: '2025-01-22T09:57:12.620432'
  updated_at: '2025-01-22T09:57:12.620432'

ktype:
  id: app
  name: null
  webform: null
  json_schema: null
  created_at: '2025-01-22T09:57:12.620432'
  updated_at: '2025-01-22T09:57:12.620432'

ktype:
  id: dataset
  name: dataset
  webform: null
  json_schema: null
  created_at: '2025-01-22T09:57:12.620432'
  updated_at: '2025-01-22T09:57:12.620432'

ktype:
  id: dataset-catalog
  name: dataset catalog
  webform: null
  json_schema: null
  created_at: '2025-01-22T09:57:12.620432'
  updated_at: '2025-01-22T09:57:12.620432'

ktype:
  id: testing-machine
  name: Testing Machine
  webform:
    semanticsEnabled: true
    sectionsEnabled: false
    classMapping:
    - https://w3id.org/steel/ProcessOntology/TestingMachine
    sections:
    - id: id717506ec647db
      name: ''
      inputs:
      - id: id699fb85c65df4
        label: Producer
        widget: Text
        required: false
        value: null
        hint: null
        hidden: false
        ignore: false
        selectOptions: []
        measurementUnit: null
        relationMapping:
          iri: https://w3id.org/steel/ProcessOntology/hasIdentifier
          type: data_property
          classIri: null
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType: null
        rangeOptions: null
        placeholder: null
      hidden: false
  json_schema:
    iri:
    - https://w3id.org/steel/ProcessOntology/TestingMachine
    suffix: slug
    source: testing-machine[*]
    suffix_from_location: true
    custom_relations:
    - object_location: producer
      relation: https://w3id.org/steel/ProcessOntology/hasIdentifier
      relation_type: data_property
      object_type: string
    - object_location: Name
      relation: http://www.w3.org/2000/01/rdf-schema#label
      relation_type: annotation_property
      object_data_type: string
  created_at: '2025-01-22T10:27:30.326818'
  updated_at: '2025-01-22T10:27:30.326818'

ktype:
  id: characterization-process
  name: Characterization Process
  webform:
    semanticsEnabled: true
    sectionsEnabled: false
    classMapping: []
    sections:
    - id: id854bea39809548
      name: ''
      inputs: []
      hidden: false
  json_schema:
    iri: null
    suffix: slug
    source: characterization-process[*]
    suffix_from_location: true
    custom_relations:
    - object_location: Name
      relation: http://www.w3.org/2000/01/rdf-schema#label
      relation_type: annotation_property
      object_data_type: string
  created_at: '2025-02-13T13:02:43.136894'
  updated_at: '2025-02-13T13:02:43.136894'

ktype:
  id: manufacturing-process
  name: Manufacturing Process
  webform:
    semanticsEnabled: true
    sectionsEnabled: false
    classMapping: []
    sections:
    - id: id0acb90f53cb28
      name: ''
      inputs: []
      hidden: false
  json_schema:
    iri: null
    suffix: slug
    source: manufacturing-process[*]
    suffix_from_location: true
    custom_relations:
    - object_location: Name
      relation: http://www.w3.org/2000/01/rdf-schema#label
      relation_type: annotation_property
      object_data_type: string
  created_at: '2025-02-13T13:03:13.743493'
  updated_at: '2025-02-13T13:03:13.743493'

ktype:
  id: measurement-device
  name: Measurement device
  webform:
    semanticsEnabled: true
    sectionsEnabled: false
    classMapping:
    - https://w3id.org/ORCHESTER/measurement-device/MeasurementDevice
    sections:
    - id: id23f26e1aec6e
      name: Untitled Section
      inputs:
      - id: id4771ba047219e
        label: name
        widget: Text
        required: false
        value: null
        hint: please add the name of the measurement device
        hidden: false
        ignore: false
        selectOptions: []
        measurementUnit: null
        relationMapping:
          iri: https://w3id.org/ORCHESTER/measurement-device/MeasurementDeviceName
          type: data_property
          classIri: https://w3id.org/ORCHESTER/measurement-device/MeasurementDeviceName
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType: null
        rangeOptions: null
        placeholder: null
      - id: id3d095d631a156
        label: manufacturer
        widget: Text
        required: false
        value: null
        hint: please add the name of the manufacturer
        hidden: false
        ignore: false
        selectOptions: []
        measurementUnit: null
        relationMapping:
          iri: https://w3id.org/ORCHESTER/measurement-device/Manufacturer
          type: data_property
          classIri: null
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType: null
        rangeOptions: null
        placeholder: null
      - id: id4584da4ce4bc9
        label: measurement device type
        widget: Text
        required: false
        value: null
        hint: please add the measurement type of the device, e.g. microscope
        hidden: false
        ignore: false
        selectOptions: []
        measurementUnit: null
        relationMapping:
          iri: https://w3id.org/ORCHESTER/measurement-device/MeasurementDeviceType
          type: data_property
          classIri: null
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType: null
        rangeOptions: null
        placeholder: null
      - id: id071732bc59fed
        label: serial number
        widget: Text
        required: false
        value: null
        hint: please add the serial number
        hidden: false
        ignore: false
        selectOptions: []
        measurementUnit: null
        relationMapping:
          iri: https://w3id.org/ORCHESTER/measurement-device/SerialNumber
          type: data_property
          classIri: null
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType: null
        rangeOptions: null
        placeholder: null
      - id: id7550e1c6439dd
        label: responsible organization for the device
        widget: Knowledge item
        required: false
        value: null
        hint: Please add the responsible department of the organisation
        hidden: false
        ignore: false
        selectOptions: []
        measurementUnit: null
        relationMapping:
          iri: https://w3id.org/steel/ProcessOntology/hasLaboratory
          type: data_property
          classIri: null
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType: organization
        rangeOptions: null
        placeholder: null
      - id: id83875811c49ca
        label: measurement device number
        widget: Text
        required: false
        value: null
        hint: 'please add the measurement device number '
        hidden: false
        ignore: false
        selectOptions: []
        measurementUnit: null
        relationMapping:
          iri: https://w3id.org/ORCHESTER/measurement-device/MeasurementDeviceNumber
          type: data_property
          classIri: null
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType: null
        rangeOptions: null
        placeholder: null
      - id: id2095e14118a78
        label: room number
        widget: Text
        required: false
        value: null
        hint: please add the room number of the device
        hidden: false
        ignore: false
        selectOptions: []
        measurementUnit: null
        relationMapping:
          iri: https://w3id.org/ORCHESTER/measurement-device/RoomNumber
          type: data_property
          classIri: null
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType: null
        rangeOptions: null
        placeholder: null
      - id: idcce5f8dfb7778
        label: Inventory number
        widget: Text
        required: false
        value: null
        hint: please add the sigma inventory number
        hidden: false
        ignore: false
        selectOptions: []
        measurementUnit: null
        relationMapping:
          iri: https://w3id.org/ORCHESTER/measurement-device/SigmaInventoryNumber
          type: data_property
          classIri: null
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType: null
        rangeOptions: null
        placeholder: null
      - id: id3998befe78c2c
        label: measurement range
        widget: Textarea
        required: false
        value: null
        hint: Please add relevant information about the measurement range
        hidden: false
        ignore: false
        selectOptions: []
        measurementUnit: null
        relationMapping:
          iri: https://w3id.org/ORCHESTER/measurement-device/MeasurementRange
          type: data_property
          classIri: null
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType: null
        rangeOptions: null
        placeholder: null
      - id: ida5671c778a645
        label: select1
        widget: Select
        required: false
        value: null
        hint: null
        hidden: false
        ignore: false
        selectOptions:
        - key: option1
          label: A
          disabled: false
        - key: option2
          label: B
          disabled: false
        measurementUnit: null
        relationMapping:
          iri: http://www.w3.org/ns/dcat#startDate
          type: data_property
          classIri: null
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType: null
        rangeOptions: null
        placeholder: null
      - id: id650c1d5f69a138
        label: multiselect2
        widget: Multi-select
        required: false
        value: null
        hint: null
        hidden: false
        ignore: false
        selectOptions:
        - key: option1
          label: A
          disabled: false
        - key: option2
          label: B
          disabled: false
        measurementUnit: null
        relationMapping:
          iri: https://w3id.org/emmo#EMMO_b35e92d7_7fa0_4661_aa5a_5cea7c8e6925
          type: data_property
          classIri: null
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType: null
        rangeOptions: null
        placeholder: null
      hidden: false
  json_schema:
    iri:
    - https://w3id.org/ORCHESTER/measurement-device/MeasurementDevice
    suffix: slug
    source: measurement-device[*]
    suffix_from_location: true
    custom_relations:
    - object_location: name
      relation: https://w3id.org/ORCHESTER/measurement-device/MeasurementDeviceName
      relation_type: data_property
      object_type: string
    - object_location: manufacturer
      relation: https://w3id.org/ORCHESTER/measurement-device/Manufacturer
      relation_type: data_property
      object_type: string
    - object_location: measurement-device-type
      relation: https://w3id.org/ORCHESTER/measurement-device/MeasurementDeviceType
      relation_type: data_property
      object_type: string
    - object_location: serial-number
      relation: https://w3id.org/ORCHESTER/measurement-device/SerialNumber
      relation_type: data_property
      object_type: string
    - object_location: responsible-organization-for-the-device
      relation: https://w3id.org/steel/ProcessOntology/hasLaboratory
      relation_type: object_property
      object_type: anyURI
    - object_location: measurement-device-number
      relation: https://w3id.org/ORCHESTER/measurement-device/MeasurementDeviceNumber
      relation_type: data_property
      object_type: string
    - object_location: room-number
      relation: https://w3id.org/ORCHESTER/measurement-device/RoomNumber
      relation_type: data_property
      object_type: string
    - object_location: inventory-number
      relation: https://w3id.org/ORCHESTER/measurement-device/SigmaInventoryNumber
      relation_type: data_property
      object_type: string
    - object_location: measurement-range
      relation: https://w3id.org/ORCHESTER/measurement-device/MeasurementRange
      relation_type: data_property
      object_type: string
    - object_location: select1
      relation: http://www.w3.org/ns/dcat#startDate
      relation_type: data_property
      object_type: string
    - object_location: multiselect2
      relation: https://w3id.org/emmo#EMMO_b35e92d7_7fa0_4661_aa5a_5cea7c8e6925
      relation_type: data_property
      object_type: string
  created_at: '2025-02-17T11:08:43.497604'
  updated_at: '2025-02-25T11:23:11.371136'

ktype:
  id: batch
  name: Batches
  webform: null
  json_schema: null
  created_at: '2025-04-09T10:50:13.094447'
  updated_at: '2025-04-09T10:50:13.094447'

ktype:
  id: specimen
  name: Specimen
  webform:
    semanticsEnabled: true
    sectionsEnabled: false
    classMapping:
    - https://w3id.org/steel/ProcessOntology/TestPiece
    sections:
    - id: id0595fb5f1853a8
      name: Untitled Section
      inputs:
      - id: idba92210e193128
        label: Width
        widget: Number
        required: false
        value: null
        hint: null
        hidden: false
        ignore: false
        selectOptions: []
        measurementUnit:
          label: Millimetre
          iri: http://qudt.org/vocab/unit/MilliM
          symbol: null
          namespace: http://qudt.org/vocab/unit
        relationMapping:
          iri: https://w3id.org/steel/ProcessOntology/hasWidth_Object
          type: object_property
          classIri: https://w3id.org/emmo#EMMO_e4de48b1_dabb_4490_ac2b_040f926c64f0
        relationMappingExtra: null
        multipleSelection: false
        knowledgeType:
        - null
        rangeOptions:
          min: 0
          max: 1
          step: 0.1
          range: false
        placeholder: null
      - id: ida08bcc9977e388
        label: Length
        widget: Slider
        required: false
        value: null
        hint: null
        hidden: false
        ignore: false
        selectOptions: []
        measurementUnit:
          label: Millimetre
          iri: http://qudt.org/vocab/unit/MilliM
          symbol: null
          namespace: http://qudt.org/vocab/unit
        relationMapping:
          iri: https://w3id.org/steel/ProcessOntology/hasTotalLength_Object
          type: object_property
          classIri: https://w3id.org/emmo#EMMO_cd2cd0de_e0cc_4ef1_b27e_2e88db027bac
        relationMappingExtra:
          iri: https://w3id.org/steel/ProcessOntology/hasTotalLength_Object
          type: object_property
          classIri: https://w3id.org/emmo#EMMO_cd2cd0de_e0cc_4ef1_b27e_2e88db027bac
        multipleSelection: false
        knowledgeType: null
        rangeOptions:
          min: 0
          max: 1
          step: 0.1
          range: true
        placeholder: null
      hidden: false
  json_schema:
    iri:
    - https://w3id.org/steel/ProcessOntology/TestPiece
    suffix: slug
    source: specimen[*]
    suffix_from_location: true
    custom_relations:
    - object_location: width
      relation: https://w3id.org/steel/ProcessOntology/hasWidth_Object
      relation_type: object_property
      object_type:
        iri: https://w3id.org/emmo#EMMO_e4de48b1_dabb_4490_ac2b_040f926c64f0
        unit: http://qudt.org/vocab/unit/MilliM
    - object_location: length[0]
      relation: https://w3id.org/steel/ProcessOntology/hasTotalLength_Object
      relation_type: object_property
      object_type:
        suffix: min
        iri: https://w3id.org/emmo#EMMO_cd2cd0de_e0cc_4ef1_b27e_2e88db027bac
        unit: http://qudt.org/vocab/unit/MilliM
    - object_location: length[1]
      relation: https://w3id.org/steel/ProcessOntology/hasTotalLength_Object
      relation_type: object_property
      object_type:
        suffix: max
        iri: https://w3id.org/emmo#EMMO_cd2cd0de_e0cc_4ef1_b27e_2e88db027bac
        unit: http://qudt.org/vocab/unit/MilliM
    - object_location: Name
      relation: http://www.w3.org/2000/01/rdf-schema#label
      relation_type: annotation_property
      object_data_type: string
  created_at: '2025-01-22T10:25:24.336663'
  updated_at: '2025-04-09T09:15:36.822065'

7.4. Delete KTypes#

The fetched ktype can be deleted by applying the del-operator to the dsms object with the individual KType object.

[10]:
del dsms[ktype]

As always, commit the changes.

[11]:
dsms.commit()

The available KTypes in the SDK can be fetched from an enum list.