4. Deleting KItems with the SDK#
In this tutorial we see how to delete new Kitems and their properties.
4.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, KItem
Now source the environmental variables from an .env file and start the DSMS-session.
[2]:
dsms = DSMS(env=".env")
Then lets see the Kitem we are interested in to remove.
[3]:
item = dsms["ff1316ef-790c-4833-915c-de13c5f3ba91"]
4.2. Deletion of KItems and their properties#
We can also remove properties from the KItem without deleting the KItem itself.
For the list-like properties, we can use the standard list-methods from basic Python again (e.g. pop, remove, etc. or the del-operator).
For the other, non-list-like properties, we can simply use the attribute-assignment again.
When we only want single parts of the properties in the KItem, we can do it like this:
[4]:
item.attachments.pop(0)
item.annotations.pop(0)
item.external_links.pop(0)
item.contacts.pop(0)
[4]:
contact:
name: Specimen preparation
email: specimenpreparation@group.mail
However, we can also reset the entire property by setting it to e.g. an empty list again:
[5]:
item.affiliations = []
Send the changes to the DSMS with the commit-method:
[6]:
dsms.add(item)
dsms.commit()
See the changes:
[7]:
item
[7]:
kitem:
name: Specimen-123
id: ff1316ef-790c-4833-915c-de13c5f3ba91
ktype_id: specimen
slug: specimen123-ff1316ef
annotations: []
attachments:
- name: testfile.txt
linked_kitems: []
affiliations: []
authors:
- user_id: 7f0e5a37-353b-4bbc-b1f1-b6ad575f562d
avatar_exists: false
contacts:
- name: Specimen preparation
email: specimenpreparation@group.mail
created_at: 2025-04-10 10:29:24.395884
updated_at: 2025-04-10 10:30:00.537758
external_links:
- label: specimen-link
url: http://specimens.org
apps: []
user_groups: []
custom_properties:
content:
sections:
- id: id0595fb5f1853a8
name: Untitled Section
entries:
- id: idba92210e193128
type: Number
label: Width
value: 1
measurementUnit:
iri: http://qudt.org/vocab/unit/MilliM
label: Millimetre
symbol: null
namespace: http://qudt.org/vocab/unit
relationMapping: null
required: false
- id: ida08bcc9977e388
type: Slider
label: Length
value:
- 0.1
- 0.2
measurementUnit:
iri: http://qudt.org/vocab/unit/MilliM
label: Millimetre
symbol: null
namespace: http://qudt.org/vocab/unit
relationMapping: null
required: false
rdf_exists: true
However, we can also delete the whole KItem from the DSMS by applying the del-operator to the dsms-object with the individual KItem-object:
[8]:
del dsms[item]
Commit the changes:
[9]:
dsms.commit()
Now to check if the particular kitem was removed, we can do this by using the command: dsms.kitems or by logging into the frontend dsms instance.