1. Connecting with the SDK to DSMS

1. Connecting with the SDK to DSMS#

In this tutorial we see the overview on how to setup and basic use DSMS-SDK

1.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)

Now let us import the needed classes and functions for this tutorial.

[1]:
from dsms import DSMS

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

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

1.2. Introduction to KItems#

We can see which kitems we own as a user:

[3]:
dsms.get_kitems(limit=3)
/app/dsms/knowledge/kitem.py:692: UserWarning: No webform was defined for entry `CKAN Resource`. Cannot check if value is of correct type.
  warnings.warn(
/app/dsms/knowledge/kitem.py:692: UserWarning: No webform was defined for entry `CKAN Download URL`. Cannot check if value is of correct type.
  warnings.warn(
/app/dsms/knowledge/kitem.py:692: UserWarning: No webform was defined for entry `Media Type`. Cannot check if value is of correct type.
  warnings.warn(
[3]:
kitems:
- id: 94f54c99-ddb0-4462-8fe3-06a16aa105ec
  name: Tensile_C_09.lis
  ktype_id: web-ressource
  slug: tensile_c_09lis-94f54c99
  annotations:
  - iri: https://www.iana.org/assignments/media-types/text/csv
    label: csv
    namespace: https://www.iana.org/assignments/media-types/text
  attachments: []
  linked_kitems:
  - is_incoming: false
    label: Has Part
    kitem:
      id: 02ce95a9-50b5-4d79-a68d-49214524aa41
      name: KupferDigital_BAM_Tensile_C_09
      ktype_id: dataset
      slug: kupferdigital_bam_tensile_c_09-02ce95a9
    iri: http://purl.org/dc/terms/hasPart
  affiliations: []
  authors:
  - user_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d
  avatar_exists: true
  contacts: []
  created_at: 2025-07-02 15:49:23.206464
  updated_at: 2025-07-02 15:49:23.206464
  external_links:
  - label: CKAN download URL
    url: https://ckan.kupferdigital.org/dataset/02ce95a9-50b5-4d79-a68d-49214524aa41/resource/94f54c99-ddb0-4462-8fe3-06a16aa105ec/download/tensile_c_09.lis
  - label: CKAN source
    url: https://ckan.kupferdigital.org/dataset/02ce95a9-50b5-4d79-a68d-49214524aa41/resource/94f54c99-ddb0-4462-8fe3-06a16aa105ec
  apps: []
  summary: https://ckan.kupferdigital.org/dataset/02ce95a9-50b5-4d79-a68d-49214524aa41/resource/94f54c99-ddb0-4462-8fe3-06a16aa105ec
  user_groups: []
  custom_properties:
    content:
      sections:
      - id: id17514713629953u7k9z
        name: Misc
        entries:
        - id: id1751471362995mom5gj
          type: Text
          label: CKAN Resource
          value: https://ckan.kupferdigital.org/dataset/02ce95a9-50b5-4d79-a68d-49214524aa41/resource/94f54c99-ddb0-4462-8fe3-06a16aa105ec
          measurementUnit: null
          relationMapping: null
          required: false
        - id: id1751471362995wkglsz
          type: Text
          label: CKAN Download URL
          value: https://ckan.kupferdigital.org/dataset/02ce95a9-50b5-4d79-a68d-49214524aa41/resource/94f54c99-ddb0-4462-8fe3-06a16aa105ec/download/tensile_c_09.lis
          measurementUnit: null
          relationMapping: null
          required: false
  rdf_exists: true
  contexts: []
- id: 049821c7-2fb4-41b6-89f9-eba2c76d580a
  name: KupferDigital_7F21109_ID3243_Pos._b_EDX
  ktype_id: dataset
  slug: kupferdigital_7f21109_id3243_pos_b_edx-049821c7
  annotations: []
  attachments: []
  linked_kitems:
  - is_incoming: false
    label: Has Part
    kitem:
      id: 3d0822c9-c87c-42c8-b390-8f392ffcea3f
      name: KupferDigi
      ktype_id: web-ressource
      slug: kupferdigi-3d0822c9
    iri: http://purl.org/dc/terms/hasPart
  - is_incoming: false
    label: Has Part
    kitem:
      id: f633b4b3-3ca6-447d-9e9b-ed7154611aba
      name: Kupferdigital CKAN Instance
      ktype_id: external-data-source
      slug: kupferdigitalckaninstance-f633b4b3
    iri: http://purl.org/dc/terms/hasPart
  - is_incoming: true
    label: Has Part
    kitem:
      id: 97e4e09b-1c84-428d-a007-f17c9814ad15
      name: KupferDigi
      ktype_id: web-ressource
      slug: kupferdigi-97e4e09b
    iri: http://purl.org/dc/terms/hasPart
  affiliations: []
  authors:
  - user_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d
  avatar_exists: true
  contacts: []
  created_at: 2025-07-02 15:49:37.710531
  updated_at: 2025-07-02 15:49:37.710531
  external_links:
  - label: CKAN source
    url: https://ckan.kupferdigital.org/dataset/049821c7-2fb4-41b6-89f9-eba2c76d580a
  apps: []
  summary: eds measurements on a diffusion specimen
  user_groups: []
  custom_properties:
    content:
      sections:
      - id: id1751471401085iwiex6
        name: Misc
        entries:
        - id: id1751471401085lwpseh
          type: Knowledge item
          label: Resources
          value:
          - id: 3d0822c9-c87c-42c8-b390-8f392ffcea3f
            name: KupferDigi
            ktype_id: web-ressource
            slug: kupferdigi-3d0822c9
          - id: 97e4e09b-1c84-428d-a007-f17c9814ad15
            name: KupferDigi
            ktype_id: web-ressource
            slug: kupferdigi-97e4e09b
          measurementUnit: null
          relationMapping: null
          required: false
        - id: id17514714010858safjx
          type: Knowledge item
          label: Publishing Organisation
          value:
          - id: c6a0740a-3bb2-4661-a5d7-67488fa061a7
            name: fem-organization
            ktype_id: organization
            slug: fem-organization-c6a0740a
          measurementUnit: null
          relationMapping: null
          required: false
  rdf_exists: true
  contexts: []
- id: 3d0822c9-c87c-42c8-b390-8f392ffcea3f
  name: KupferDigi
  ktype_id: web-ressource
  slug: kupferdigi-3d0822c9
  annotations:
  - iri: https://www.iana.org/assignments/media-types/application/vnd.ms-excel
    label: vnd.ms-excel
    namespace: https://www.iana.org/assignments/media-types/application
  attachments: []
  linked_kitems:
  - is_incoming: true
    label: Has Part
    kitem:
      id: 049821c7-2fb4-41b6-89f9-eba2c76d580a
      name: KupferDigital_7F21109_ID3243_Pos._b_EDX
      ktype_id: dataset
      slug: kupferdigital_7f21109_id3243_pos_b_edx-049821c7
    iri: http://purl.org/dc/terms/hasPart
  affiliations: []
  authors:
  - user_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d
  avatar_exists: true
  contacts: []
  created_at: 2025-07-02 15:49:49.501334
  updated_at: 2025-07-02 15:49:49.501334
  external_links:
  - label: CKAN source
    url: https://ckan.kupferdigital.org/dataset/049821c7-2fb4-41b6-89f9-eba2c76d580a/resource/3d0822c9-c87c-42c8-b390-8f392ffcea3f
  - label: CKAN download URL
    url: https://ckan.kupferdigital.org/dataset/049821c7-2fb4-41b6-89f9-eba2c76d580a/resource/3d0822c9-c87c-42c8-b390-8f392ffcea3f/download/kupferdigital_7f21109_id3243_pos._b_edx_rawdata.xlsx
  apps: []
  summary: https://ckan.kupferdigital.org/dataset/049821c7-2fb4-41b6-89f9-eba2c76d580a/resource/3d0822c9-c87c-42c8-b390-8f392ffcea3f
  user_groups: []
  custom_properties:
    content:
      sections:
      - id: id1751471389254oxwoza
        name: Misc
        entries:
        - id: id1751471389254g2ojkx
          type: Text
          label: CKAN Resource
          value: https://ckan.kupferdigital.org/dataset/049821c7-2fb4-41b6-89f9-eba2c76d580a/resource/3d0822c9-c87c-42c8-b390-8f392ffcea3f
          measurementUnit: null
          relationMapping: null
          required: false
        - id: id1751471389254kf8g0k
          type: Text
          label: CKAN Download URL
          value: https://ckan.kupferdigital.org/dataset/049821c7-2fb4-41b6-89f9-eba2c76d580a/resource/3d0822c9-c87c-42c8-b390-8f392ffcea3f/download/kupferdigital_7f21109_id3243_pos._b_edx_rawdata.xlsx
          measurementUnit: null
          relationMapping: null
          required: false
        - id: id1751471389254gdr583
          type: Text
          label: Media Type
          value: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
          measurementUnit: null
          relationMapping: null
          required: false
  rdf_exists: false
  contexts: []
total_count: 356

We can investigate what a KItem needs in order to be created. KItems are entirely based on Pydantic-Models (v2), hence the properties (in Pydantic called Fields) are automatically validated once we set them.

The schema of the KItem itself is a JSON schema which is machine-readable and can be directly incorporated into Swagger-supported APIs like e.g. FastAPI.

We can investigate the KTypes defined in the remote instance:

[4]:
for ktype in dsms.ktypes:
    print(ktype)
ktype:
  id: expert
  created_at: '2025-06-26T13:27:43.597461'
  updated_at: '2025-06-26T13:27:43.597461'

ktype:
  id: dataset
  name: dataset
  created_at: '2025-06-26T13:27:43.597461'
  updated_at: '2025-06-26T13:27:43.597461'

ktype:
  id: dataset-catalog
  name: dataset catalog
  created_at: '2025-06-26T13:27:43.597461'
  updated_at: '2025-06-26T13:27:43.597461'

ktype:
  id: external-data-source
  name: External Data Source
  created_at: '2025-07-02T09:43:27.121927'
  updated_at: '2025-07-02T09:43:27.121927'

ktype:
  id: app
  name: app
  webform_schema_id: a366408f-7949-42ac-8e9b-686f788cbd86
  webform_schema:
    id: a366408f-7949-42ac-8e9b-686f788cbd86
    name: application
    spec:
      semantics_enabled: true
      sections_enabled: false
      class_mapping:
      - https://w3id.org/emmo#EMMO_3b031fa9_8623_4ea5_8b57_bcafb70c5c8b
      sections:
      - id: id11ee168baf44a8
        name: ''
        inputs:
        - id: idf0096545188b98
          label: Application name
          widget: Text
          required: false
          hidden: false
          ignore: false
          select_options: []
          relation_mapping:
            iri: https://w3id.org/steel/ProcessOntology/hasIdentifier
            label: has Identifier
            type: data_property
          multiple_selection: false
        hidden: false
    created_at: '2025-07-15T14:28:48.236596'
    updated_at: '2025-07-15T14:28:48.236596'
  created_at: '2025-06-26T13:27:43.597461'
  updated_at: '2025-07-15T14:29:07.123972'

ktype:
  id: web-ressource
  name: Web Ressource
  webform_schema_id: 6f897085-20ae-4f58-88cb-4ecfaa59e251
  webform_schema:
    id: 6f897085-20ae-4f58-88cb-4ecfaa59e251
    name: Web Ressource
    spec:
      semantics_enabled: true
      sections_enabled: false
      class_mapping:
      - http://www.w3.org/ns/dcat#Resource
      sections:
      - id: id34da047a592c98
        name: Untitled Section
        inputs:
        - id: id053f055e718bf8
          label: Access URL
          widget: Text
          required: false
          hidden: false
          ignore: false
          select_options: []
          relation_mapping:
            iri: http://www.w3.org/ns/dcat#accessURL
            label: access address
            type: property
          multiple_selection: false
        hidden: false
    created_at: '2025-07-15T13:58:53.020266'
    updated_at: '2025-07-16T11:52:10.690939'
  created_at: '2025-07-02T09:42:46.289536'
  updated_at: '2025-07-16T11:51:03.826524'

ktype:
  id: organization
  name: organization
  webform_schema_id: 0575cff0-e6d3-45ca-8474-ac5b402e522d
  webform_schema:
    id: 0575cff0-e6d3-45ca-8474-ac5b402e522d
    name: organization
    spec:
      semantics_enabled: true
      sections_enabled: false
      class_mapping: []
      sections:
      - id: id318659d85714d8
        name: ''
        inputs:
        - id: idba9fb3fd5543a8
          label: address
          widget: Text
          required: false
          hidden: false
          ignore: false
          select_options: []
          relation_mapping:
            iri: https://w3id.org/steel/ProcessOntology/hasLocation
            type: property
          multiple_selection: false
        hidden: false
    created_at: '2025-07-16T14:18:05.866631'
    updated_at: '2025-07-16T14:18:05.866631'
  created_at: '2025-07-16T14:18:05.992083'
  updated_at: '2025-07-16T14:18:06.051750'

ktype:
  id: characterization-process
  name: Characterization Process
  process_schema_id: 4975067f-4804-4218-bf83-e48ff3990281
  process_schema:
    id: 4975067f-4804-4218-bf83-e48ff3990281
    name: Characterization Process
    spec:
    - id: organization
      label: organization
      is_child: false
      mappings:
      - dst_ktype_id: app
        relation_iri: https://w3id.org/emmo#EMMO_17e27c22_37e1_468c_9dd7_95e137f73e7f
        relation_name: hasPart
      children: []
    - id: app
      label: app
      is_child: false
      mappings:
      - dst_ktype_id: web-ressource
        relation_iri: https://w3id.org/emmo#EMMO_c4bace1d_4db0_4cd3_87e9_18122bae2840
        relation_name: hasOutput
      children:
      - id: web-ressource
        label: Web Ressource
        is_child: true
        mappings: []
        children: []
    created_at: 2025-07-16 14:18:06.312271
    updated_at: 2025-07-16 14:18:06.312271
  created_at: '2025-07-16T14:18:06.433199'
  updated_at: '2025-07-16T14:18:06.495714'

ktype:
  id: specimen
  name: Specimen
  webform_schema_id: 21164fb6-cc45-4e08-8f8b-467a749df54b
  webform_schema:
    id: 21164fb6-cc45-4e08-8f8b-467a749df54b
    name: Specimen
    spec:
      semantics_enabled: true
      sections_enabled: false
      class_mapping:
      - https://w3id.org/pmd/co/Specimen
      sections:
      - id: idb424123144cdd8
        name: Untitled Section
        inputs:
        - id: id6c76bbffe7ca78
          label: Width
          widget: Number
          required: false
          hidden: false
          ignore: false
          select_options: []
          measurement_unit:
            label: Millimetre
            iri: http://qudt.org/vocab/unit/MilliM
            namespace: http://qudt.org/vocab/unit
          relation_mapping:
            iri: https://w3id.org/emmo#EMMO_17e27c22_37e1_468c_9dd7_95e137f73e7f
            type: object_property
            class_iri: https://w3id.org/emmo#EMMO_e4de48b1_dabb_4490_ac2b_040f926c64f0
          multiple_selection: false
          knowledge_type:
          - null
          range_options:
            min: 0
            max: 1
            step: 0.1
            range: false
        - id: id717d07130a7618
          label: Length
          widget: Slider
          required: false
          hidden: false
          ignore: false
          select_options: []
          measurement_unit:
            label: Millimetre
            iri: http://qudt.org/vocab/unit/MilliM
            namespace: http://qudt.org/vocab/unit
          relation_mapping:
            iri: https://w3id.org/emmo#EMMO_17e27c22_37e1_468c_9dd7_95e137f73e7f
            type: object_property
            class_iri: https://w3id.org/emmo#EMMO_cd2cd0de_e0cc_4ef1_b27e_2e88db027bac
          relation_mapping_extra:
            iri: https://w3id.org/emmo#EMMO_17e27c22_37e1_468c_9dd7_95e137f73e7f
            type: object_property
            class_iri: https://w3id.org/emmo#EMMO_e4de48b1_dabb_4490_ac2b_040f926c64f0
          multiple_selection: false
          range_options:
            min: 0
            max: 1
            step: 0.1
            range: true
        hidden: false
    created_at: '2025-07-21T09:24:48.597715'
    updated_at: '2025-07-21T13:56:38.225444'
  created_at: '2025-07-21T09:20:12.746430'
  updated_at: '2025-07-21T09:24:58.495720'

ktype:
  id: testingmachine
  name: TestingMachine
  created_at: '2025-07-22T12:41:50.505566'
  updated_at: '2025-07-22T12:41:50.505566'