> For the complete documentation index, see [llms.txt](https://docs.unitlab.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/ontology-resources.md).

# 本体资源

使用 Unitlab Python SDK 列出、读取、创建和更新工作区本体（ontology），了解筛选条件、字段含义及所需权限。

工作区本体可以复用。使用本体创建项目时，项目会获得一份独立副本，因此之后编辑工作区本体不会影响已有项目。

```python
ontology = client.ontologies.create(
    "Robot cell QA",
    description="Grippers and parts on the inspection line",
    structure=structure,
)

for item in client.ontologies.list(title_like="Robot"):
    print(item.id, item.title, item.last_edited_at)

ontology = client.ontologies.get("ONTOLOGY_ID")
ontology.description = "Adds the Fixture class"
ontology.structure.add_object("Fixture", Shape.BOUNDING_BOX)
ontology.save()
```

`create()` 创建后本体立即可用，没有发布步骤。`save()` 会写入 `title`、`description` 和 `structure`，并记录一个新修订版本。

## 列表筛选条件 <a href="#list-filters" id="list-filters"></a>

| 筛选条件                              | 匹配方式            |
| --------------------------------- | --------------- |
| `title_eq`, `title_like`          | 精确标题，或标题的一部分    |
| `desc_eq`, `desc_like`            | 精确描述，或描述的一部分    |
| `created_before`, `created_after` | ISO 8601 日期或时间戳 |
| `edited_before`, `edited_after`   | ISO 8601 日期或时间戳 |

已归档的本体不会列出。

## 字段 <a href="#fields" id="fields"></a>

| 字段                                  | 含义                                              |
| ----------------------------------- | ----------------------------------------------- |
| `id`                                | 本体 ID；作为 `ontology_hash` 传给 `projects.create()` |
| `title`, `description`, `structure` | 内容                                              |
| `data_type`                         | 兼容的数据类型，默认为 `image`                             |
| `created_at`, `last_edited_at`      | 时间                                              |
| `project_id`                        | 本体属于某个项目时设置                                     |

密钥需要 **View ontology** 权限才能读取，需要 **Manage ontologies** 权限才能创建和保存。

## 相关内容 <a href="#related" id="related"></a>

[用 Python 构建本体](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/build-ontologies-in-python.md) · [CLI：本体与云存储](https://docs.unitlab.ai/api-sdk-cli/zh/clis/cli-ontologies-and-cloud-storage.md)
