> 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/pattern-assets-to-a-release.md).

# 模式：从资产到发布

用 Unitlab Python SDK 完成从资产到发布的全流程：把机器人录制数据上传到资产库，发布数据集版本，关联到项目并导出 COCO 发布。

当同一批文件需要供多个项目使用，或每个发布都必须能追溯到确切的数据集版本时，请采用这种模式。

```python
from unitlab import UnitlabClient

client = UnitlabClient()
try:
    # 1. Store the files once in the library.
    uploaded = client.assets.upload("./cell-04", folder="Robot cell 04", tags=["2026-11"])
    if uploaded.failed:
        raise SystemExit(f"{len(uploaded.failed)} files failed to upload")

    # 2. Freeze a curated selection.
    dataset = client.datasets.create("Bin picking - training", folder_ids=[uploaded.folder_id])
    version = dataset.publish_version("v1: cell 04")

    # 3. Label it in a project.
    project = client.projects.get("PROJECT_ID")
    result = project.attach(dataset_versions=[{"dataset_id": dataset.id, "version_number": version.version_number}])
    project.batch_queue(result.batch_queue_id).wait()

    # ...annotate and review in the app...

    # 4. Export reviewed work.
    release = client.releases.create(project, export_type="COCO", completed_only=True)
    print(release.download(dest="./export"))
finally:
    client.close()
```

## 为什么按这个顺序 <a href="#why-this-order" id="why-this-order"></a>

| 步骤                  | 带来的好处                           |
| ------------------- | ------------------------------- |
| 上传到资产库              | 每个文件只存一份，可在多个项目中复用              |
| 发布版本                | 一份固定的文件清单，可在模型卡片（model card）中引用 |
| 按版本号关联              | 即使数据集之后发生变化，项目拿到的仍是这份确切的清单      |
| `completed_only` 发布 | 只有审核完成的条目进入训练                   |

请把数据集 ID、版本号和发布 ID 与训练任务一起记录下来。

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

[数据集](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/datasets.md) · [关联与取消关联资产库数据](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/attach-and-detach-project-sources.md) · [创建与下载发布](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/create-and-download-releases.md)
