Sign in Get started

Batch

Move, copy, delete or update up to 10,000 images in one call, or copy them into another dataset. Images that fail are listed in the result, never raised.

View as Markdown
On this page

Each call takes a dataset and up to 10,000 image ids, and lists the images that failed instead of raising. Needs a member key; delete(permanent=True) needs admin. The CLI’s images move, copy, set-status, archive and restore also select images for you and split more than 10,000 into several calls.

move

Move images to another directory of the dataset. A filename the directory already has is renamed (photo.png to photo-1.png) and counted in renamed.

Source: Batch.move

Arg Type Default Notes
dataset str required Dataset name or id
images Sequence[str] required Image ids (1 to 10,000)
directory str "/" Destination directory (/ is the root)
result = client.batch.move(
    dataset="my-dataset",
    images=["a1b2c3d4-5e6f-4708-9a1b-2c3d4e5f6a7b"],
    directory="/sorted/cars",
)
print(result.processed, result.renamed, result.failed)
pictograph images move my-dataset --to /sorted/cars --images a1b2c3d4-5e6f-4708-9a1b-2c3d4e5f6a7b
curl -s -X POST "https://api.pictograph.io/api/v1/developer/batch/images/move" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dataset": "my-dataset", "images": ["a1b2c3d4-5e6f-4708-9a1b-2c3d4e5f6a7b"], "directory": "/sorted/cars"}'

Returns BatchResult

BatchResult · 6 fields
class BatchResult(BaseModel):
    """Outcome of a batch operation."""
    success: bool
    processed: int
    failed: list[BatchFailure] = []
    affected_directories: list[str] = []
    renamed: int = 0
    operation: str | None = None

copy

Copy images to another directory of the dataset, instantly (nothing is re-uploaded).

Source: Batch.copy

Arg Type Default Notes
dataset str required Dataset name or id
images Sequence[str] required Image ids (1 to 10,000)
directory str "/" Destination directory (/ is the root)
duplicate_handling DuplicateHandling "rename" For a taken name: rename adds a suffix, skip lists the image as failed, overwrite replaces the existing image
copy_annotations bool False Also copy annotations and stage
result = client.batch.copy(
    dataset="my-dataset",
    images=["a1b2c3d4-5e6f-4708-9a1b-2c3d4e5f6a7b"],
    directory="/cars-copy",
    duplicate_handling="rename",
    copy_annotations=True,
)
print(result.processed, result.failed)
pictograph images copy my-dataset --to /backup --directory /sorted/cars --with-annotations
curl -s -X POST "https://api.pictograph.io/api/v1/developer/batch/images/copy" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dataset": "my-dataset", "images": ["a1b2c3d4-5e6f-4708-9a1b-2c3d4e5f6a7b"], "directory": "/cars-copy", "duplicate_handling": "rename", "copy_annotations": true}'

Returns BatchResult

BatchResult · 6 fields
class BatchResult(BaseModel):
    """Outcome of a batch operation."""
    success: bool
    processed: int
    failed: list[BatchFailure] = []
    affected_directories: list[str] = []
    renamed: int = 0
    operation: str | None = None

copy_to_dataset

Copy images into another existing dataset, keeping annotations, tags, split and stage. Copies share stored files, so they don’t count toward your quota again; taken names are renamed (renamed) and missing classes added (classes_added).

Source: Batch.copy_to_dataset

Arg Type Default Notes
dataset str required Source dataset name or id
images Sequence[str] required Image ids (1 to 10,000)
into str required Target dataset name or id
directory str "/" Directory in the target dataset; created if missing
result = client.batch.copy_to_dataset(
    dataset="my-dataset",
    images=["a1b2c3d4-5e6f-4708-9a1b-2c3d4e5f6a7b"],
    into="signs-night",
    directory="/from-road-signs",
)
print(result.processed, result.renamed, result.classes_added, result.failed)
pictograph images copy my-dataset --to-dataset signs-night --to /from-road-signs --directory /night
curl -s -X POST "https://api.pictograph.io/api/v1/developer/batch/images/copy-to-dataset" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dataset": "my-dataset", "images": ["a1b2c3d4-5e6f-4708-9a1b-2c3d4e5f6a7b"], "into": "signs-night", "directory": "/from-road-signs"}'

Returns CopyToDatasetResult

CopyToDatasetResult · 8 fields
class CopyToDatasetResult(BaseModel):
    """Outcome of pictograph.resources.batch.Batch.copy_to_dataset."""
    success: bool
    processed: int
    failed: list[BatchFailure] = []
    affected_directories: list[str] = []
    renamed: int = 0
    operation: str | None = None
    target_dataset: str
    classes_added: list[str] = []

delete

Archive images (update(is_archived=False) restores them); permanent=True deletes them for good and needs an admin key. result.operation is "archived" or "deleted".

Source: Batch.delete

Arg Type Default Notes
dataset str required Dataset name or id
images Sequence[str] required Image ids (1 to 10,000)
permanent bool False Delete permanently instead of archiving
result = client.batch.delete(
    dataset="my-dataset",
    images=["a1b2c3d4-5e6f-4708-9a1b-2c3d4e5f6a7b"],
    permanent=False,
)
print(result.operation, result.processed, result.failed)
pictograph images archive my-dataset --images a1b2c3d4-5e6f-4708-9a1b-2c3d4e5f6a7b --yes
curl -s -X POST "https://api.pictograph.io/api/v1/developer/batch/images/delete" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dataset": "my-dataset", "images": ["a1b2c3d4-5e6f-4708-9a1b-2c3d4e5f6a7b"], "permanent": false}'

Returns BatchResult

BatchResult · 6 fields
class BatchResult(BaseModel):
    """Outcome of a batch operation."""
    success: bool
    processed: int
    failed: list[BatchFailure] = []
    affected_directories: list[str] = []
    renamed: int = 0
    operation: str | None = None

update

Change fields on many images; only the fields you pass are sent (none raises ValueError).

Source: Batch.update

Arg Type Default Notes
dataset str required Dataset name or id
images Sequence[str] required Image ids (1 to 10,000)
status str | None None New stage: new, annotate, review or complete
display_name str | None None Name shown in the app; the filename doesn’t change
is_archived bool | None None True archives, False restores
split ImageSplit | None None New split: train, val or test
clear_split bool False Remove the split; can’t combine with split
result = client.batch.update(
    dataset="my-dataset",
    images=["a1b2c3d4-5e6f-4708-9a1b-2c3d4e5f6a7b"],
    status="complete",
    is_archived=False,
)
print(result.processed, result.failed)
pictograph images set-status my-dataset --to complete --directory /val
pictograph images restore my-dataset --all          # is_archived=False
pictograph images set-split my-dataset --to val --directory /val
curl -s -X PATCH "https://api.pictograph.io/api/v1/developer/batch/images/update" \
  -H "X-API-Key: $PICTOGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"dataset": "my-dataset", "images": ["a1b2c3d4-5e6f-4708-9a1b-2c3d4e5f6a7b"], "updates": {"status": "complete", "is_archived": false}}'

Returns BatchResult

BatchResult · 6 fields
class BatchResult(BaseModel):
    """Outcome of a batch operation."""
    success: bool
    processed: int
    failed: list[BatchFailure] = []
    affected_directories: list[str] = []
    renamed: int = 0
    operation: str | None = None

Common errors

Status Exception Cause
400 / 422 ValidationError An invalid field value, or an update with no fields
403 ForbiddenError A key below member, or below admin for permanent=True
404 NotFoundError The dataset (or either dataset, for copy_to_dataset) doesn’t exist
Copied to clipboard