> 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/sdks/datasets.md).

# Datasets

Create datasets from folders or assets and manage Unpublished changes.

### The product state this call creates

![New Dataset source-selection dialog](https://292810646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGjVLUz4wthGkGlRKM6rM%2Fuploads%2F878wtKnyECkRNbmyCKhY%2Fdataset-create-modal.png?alt=media\&token=d09720b0-5aa9-4019-a940-d702f6a40e88)

*The SDK creates the same named reusable membership exposed by Data Space › Datasets › New Dataset: name, description, and reviewed Folder or Asset sources.*

{% hint style="info" %}
**Outcome:** Create datasets from folders or assets and manage Unpublished changes.
{% endhint %}

```python
dataset = client.datasets.create(
    "Training set",
    description="Approved July cohort",
    folder_ids=["FOLDER_ID"],
)

dataset.add_sources(asset_ids=["ASSET_ID"])
dataset.remove_assets(["OTHER_ASSET_ID"])
print(dataset.unpublished_changes())
print(dataset.list_items())
```

Creation accepts optional folder and asset IDs. `add_sources()` changes the draft membership. A dataset is version-first: project automation should attach a published snapshot rather than assuming current draft membership.

`remove_assets()` takes the IDs of draft items (`DatasetItem.id`) and removes those files from the draft only; the files themselves and published versions are unchanged. It returns `removed`, `skipped` (IDs that are not in the draft) and `unpublished_changes`, and raises `ValidationError` when no valid ID is given or the dataset is a project's own dataset or a read-only snapshot.

Each `DatasetItem` carries two names: `file_name` is the stored name, the one releases of an attached version use, and `uploaded_name` is the name shown in the web app. They are the same for a file uploaded to Assets and differ for a file uploaded to a project, whose stored name is generated. `in_trash` is `True` on an item of a published version whose file was moved to library Trash; attaching that version leaves the file out. It is always `False` in a draft, which does not list such files.

### Operating contract

| Concern           | Required behavior                                                                |
| ----------------- | -------------------------------------------------------------------------------- |
| Execution surface | Pinned `unitlab==3.1.6` application environment on Python 3.10+.                 |
| Identity          | Least-privilege API key supplied through approved configuration.                 |
| Target resolution | Stable resource IDs and an explicitly bounded target set.                        |
| Success evidence  | Typed return fields, server-side state, and downstream acceptance of the result. |

### Failure and recovery boundary

| Condition                                       | Response                                                                                                     |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| Authentication or authorization fails           | Stop, correct the service identity or access model, rotate exposed credentials, and rerun a read-only check. |
| Validation or entitlement rejects the operation | Correct the input or entitlement; do not retry an unchanged request.                                         |
| A request times out                             | Inspect remote state before repeating a mutation because the server may have accepted it.                    |
| Asynchronous processing exceeds its deadline    | Preserve the Batch Queue or release ID, continue bounded monitoring, and inspect item-level failures.        |
| Only part of a batch succeeds                   | Keep successful identifiers, isolate failed rows, and retry only the corrected subset.                       |

{% hint style="warning" %}
Pin and test the production SDK version. Use stable IDs, keep secrets out of logs and command history, and record the correlation ID, target IDs, counts, final state, and redacted error details for material state changes.
{% endhint %}

***

> **Continue with Unitlab:** [training-data curation workflows](https://unitlab.ai/en/data-curation)
