> For the complete documentation index, see [llms.txt](https://docs.labii.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.labii.com/api/sdk/examples.md).

# Examples

## Create a record

### Create a entry

```python
# init the labii sdk
from labii_sdk.sdk import LabiiObject
labii = LabiiObject(api_key="xxx", organization__sid="xxx")

# 1. get entry table
et = labii.Table.list(query="name_singular=entry", serializer="name")["results"][0]

# 2. get the project
project = labii.Project.list(query="name=Sample Project", serializer="name")["results"][0]

# 3. create the entry
et1 = labii.Record.create({
    "name": "Demo template",
    "projects": [{"sid": project["sid"], "name": "Sample Project"}],
    "is_template": True
}, query=f"table__sid={et['sid']}")
```

### Create a sample

```python
# init the labii sdk
from labii_sdk.sdk import LabiiObject
labii = LabiiObject(api_key="xxx", organization__sid="xxx")

# 1. get sample table
sp = labii.Table.list(query="name_singular=sample", serializer="name")["results"][0]

# 2. get the project
project = labii.Project.list(query="name=Sample Project", serializer="name")["results"][0]

# 3. get the columns
columns = labii.get_columns(f"table__sid={sg['sid']}&name__in=volume,concentration,storage")

# 4. get the storage information
sg3 = labii.Record.list(query=f"table__name_singular=storage&uid=SG3", serializer="name")["results"][0]

# 5. create the sample
sp1 = labii.Record.create({
    "name": "Demo sample",
    "projects": [{"sid": project["sid"], "name": "Sample Project"}],
    columns["volume"]: 100,
    columns["concentration"]: 10,
    columns["storage"]: {"sid": sg3["sid"], "name": sg3["name"]},
}, query=f"table__sid={sp['sid']}")
```

## Create a section

```python
# init the labii sdk
from labii_sdk.sdk import LabiiObject
labii = LabiiObject(api_key="xxx", organization__sid="xxx")

# 1. get record
ep1 = labii.Record.list(query=f"table__name_singular=experiment&uid=EP1", serializer="name")["results"][0]

# 2. add a Procedure section with CKEditor Classic widget
labii.Section.create({
	"data": {
		"html": "<h4>Procedure</h4><ol><li>Prepare the PCR solution based on the protocol: {protocol}</li><li>Based on the below table, the PCR cycle is used</li></ol><figure class=\"table\"><table><tbody><tr><td>#</td><td>Plant</td><td>Anneal Temp (°C)</td><td>Extension Time</td></tr><tr><td>1</td><td>xrn2-1</td><td>58</td><td>60s</td></tr><tr><td>2</td><td>xrn2-2</td><td>58</td><td>60s</td></tr></tbody></table></figure><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
	},
	"name": "Procedure",
	"widget": {"sid": "0cfi0a40x3abglqvAFK", "name": "CKEditor Classic"}
}, query=f"row__sid={et1['sid']}")
```

## Import RT-PCR CT Range

```python
# init the labii sdk
from labii_sdk.sdk import LabiiObject
labii = LabiiObject(api_key="xxx", organization__sid="xxx")

# prepare data
table = labii.Table.list(query="name_singular=qPCR CT Range", serializer="name")["results"][0]
project = labii.Project.list(query="name=Sample Project", serializer="name")["results"][0]
columns = labii.get_columns(f"table__sid={table['sid']}&name__in=CT_low_start,CT_low_end,CT_medium_start,CT_medium_end,CT_high,recommended_treatment,antibiotic_resistance")
# import file
with open("qPCR_CT_Range.tsv", 'r') as file:
	for line in file:
		if not "CT_low_start" in line: # skip the first line
			data = line.split("\t")
			print(f"Importing {data[0]}...")
			labii.Record.create({
				"name": data[0].strip(),
				"projects": [{"sid": project["sid"], "name": "Sample Project"}],
				columns["CT_low_start"]: data[1].strip(),
				columns["CT_low_end"]: data[2].strip(),
				columns["CT_medium_start"]: data[3].strip(),
				columns["CT_medium_end"]: data[4].strip(),
				columns["CT_high"]: data[5].strip(),
				columns["recommended_treatment"]: data[6].strip(),
				columns["antibiotic_resistance"]: data[7].strip()
			}, query=f"table__sid={table['sid']}")
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.labii.com/api/sdk/examples.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
