Skip to content

Add items to an existing dataset

dataset_items.batch_create(DatasetItemBatchCreateParams**kwargs) -> DatasetItemBatchCreateResponse
POST/v5/dataset-items/batch

Add one or more items in a single batch to a dataset that already exists.

Use this to append items to an existing dataset; to create a dataset together with its initial items in one call, use POST /v5/datasets instead (this endpoint does not create datasets). Items are only ever added in a batch — there is no single-item create endpoint. The target dataset is identified by the required dataset_id in the request body, and each entry in data (at least one is required) becomes one item, optionally paired with the files entry at the same list index — when files is supplied it must be the same length as data. Each referenced file must exist and be a supported media format, and item keys may not collide with reserved dataset- or evaluation-item field names. The target dataset must not be archived. The batch is applied as a new dataset version snapshot rather than mutating existing versions, and the created items are returned.

ParametersExpand Collapse
data: Iterable[Dict[str, object]]

Items to be added to the dataset

dataset_id: str

Identifier of the target dataset

files: Optional[Iterable[Dict[str, str]]]

Files to be associated to the dataset

ReturnsExpand Collapse
class DatasetItemBatchCreateResponse: …
items: List[DatasetItem]
id: str

The unique identifier of the entity.

content_hash: str
created_at: datetime

The date and time when the entity was created in ISO format.

formatdate-time
created_by: Identity

The identity that created the entity.

id: str
type: Literal["user", "service_account"]
One of the following:
"user"
"service_account"
object: Optional[Literal["identity"]]
data: Dict[str, object]
updated_at: datetime

The date and time when the entity was last updated in ISO format.

formatdate-time
archived_at: Optional[datetime]

The date and time when the entity was archived in ISO format.

formatdate-time
dataset_id: Optional[str]
files: Optional[Dict[str, str]]
object: Optional[Literal["dataset.item"]]
object: Optional[Literal["list"]]

Add items to an existing dataset

import os
from scale_gp_beta import SGPClient

client = SGPClient(
    api_key=os.environ.get("SGP_API_KEY"),  # This is the default and can be omitted
)
response = client.dataset_items.batch_create(
    data=[{
        "foo": "bar"
    }],
    dataset_id="dataset_id",
)
print(response.items)
{
  "items": [
    {
      "id": "id",
      "content_hash": "content_hash",
      "created_at": "2019-12-27T18:11:19.117Z",
      "created_by": {
        "id": "id",
        "type": "user",
        "object": "identity"
      },
      "data": {
        "foo": "bar"
      },
      "updated_at": "2019-12-27T18:11:19.117Z",
      "archived_at": "2019-12-27T18:11:19.117Z",
      "dataset_id": "dataset_id",
      "files": {
        "foo": "string"
      },
      "object": "dataset.item"
    }
  ],
  "object": "list"
}
Returns Examples
{
  "items": [
    {
      "id": "id",
      "content_hash": "content_hash",
      "created_at": "2019-12-27T18:11:19.117Z",
      "created_by": {
        "id": "id",
        "type": "user",
        "object": "identity"
      },
      "data": {
        "foo": "bar"
      },
      "updated_at": "2019-12-27T18:11:19.117Z",
      "archived_at": "2019-12-27T18:11:19.117Z",
      "dataset_id": "dataset_id",
      "files": {
        "foo": "string"
      },
      "object": "dataset.item"
    }
  ],
  "object": "list"
}