# Label configuration

## Create a Label Configuration

Before you can start setting up your label configuration you need to start by initializing a label\_config object.

```python
from datagym import LabelConfig
label_config = LabelConfig()
```

In DATAGYM there are two types of entries; classifications and geometries. See the chapter on label configuration to learn more.

{% content-ref url="/pages/-M9SXpFVJ0RUMga2-7xQ" %}
[Label configuration](/documentation/python-api/label-configuration.md)
{% endcontent-ref %}

### Geometries

Geometries can be added directly to the label config with just an entry key and entry value. The entry key will be the name for the label export while the entry value is shown inside of the DATAGYM workspace. Optionally you can also pass a shortcut \[0-9] and a color for the geometry.&#x20;

```python
# Adding a polygon
label_config.add_polygon(
    entry_key="polygon1",
    entry_value="polygon1"
)

# Adding a bounding box
label_config.add_rectangle(
    entry_key="rectangle1",
    entry_value="rectangle1"
)

# Adding a line
label_config.add_line(
    entry_key="line1",
    entry_value="line1"
)

# Adding a point
label_config.add_point(
    entry_key="point1",
    entry_value="point1"
)
```

### Classification

Classifications can either refer directly to the image (global classification) or also to another classification or geometry (nested classification). Besides the entry key and entry value the options dict is required for both the checklist and the select configuration entries.&#x20;

```python
## Global classifications
# Adding a free text tag
label_config.add_freetext(
    entry_key="caption",
    entry_value="caption"
)

# Adding a checklist tag with options
label_config.add_checklist(
    entry_key="caption",
    entry_value="caption",
    options_dict={"option1": "option1", "option2": "option2"}
)

# Adding a select tag with options
label_config.add_select(
    entry_key="caption",
    entry_value="caption",
    options_dict={"option1": "option1", "option2": "option2"}
)
```

For nested classifications you can just add the classification of your choice to any existing entry inside your label config.

```python
## Global classifications
# Adding a free text tag to an existing polygon
polygon = label_config.add_polygon(
    entry_key="polygon1",
    entry_value="polygon1"
)

polygon.add_freetext(
    entry_key="caption",
    entry_value="caption"
)

# Adding a checklist tag with options to an existing select tag
select = label_config.add_select(
    entry_key="caption",
    entry_value="caption",
    options_dict={"option1": "option1", "option2": "option2"}
)
select.add_checklist(
    entry_key="caption",
    entry_value="caption",
    options_dict={"option1": "option1", "option2": "option2"}
)
```

## Uploading your finished label configuration

{% hint style="warning" %}
Careful with using the upload-label-config method. This deletes your existing label configuration and **all** of your existing labels in this project.&#x20;
{% endhint %}

Uploading your label configuration is easily done with just one line of code. However be careful as this is not something that you want to do with a project with important labels in it.

```python
project = client.get_project_by_name(project_name="<Your project name>"")

client.upload_label_config(project.label_config_id, label_config.toJson())
```


---

# Agent Instructions: 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:

```
GET https://docs.datagym.ai/documentation/python-api/label-configuration.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
