Slice the data of a directory by a given query.


Slices the data based on the given query.

The query is based on our Dataset Explorer feature, so any query that's working on our dataset explorer, should also work on the slice() method.


dataset = project.dataset.get('my dataset')
# Get only the images with more than 3 cars and at least one pedestrian
sliced_dataset = dataset.slice(' > 3 and labels.pedestrian >= 1')

Query Syntax

Query Syntax Reference

Getting Started

After calling slice() you have a dataset object.

You can then call list_files() on that dataset.


  • query (str): the string of the query to slice the dataset.


A SlicedDirectory object. This object inherits from Directory classs, so all functionality and methods available in directory, are also available on SlicedDirectory objects.


You can try the explorer and query engine here: Coco Demo