Functions and Operations

Pixeltable's built-in functions offer a rich toolkit for manipulating and transforming your data, making it easier to build complex AI workflows without resorting to custom scripts or external libraries. Whether you're working with text, images, embeddings, or other data types, Pixeltable provides functions to streamline your development process.

Table Operations

FunctionDescriptionExample
pxt.create_tableCreate a new table with a defined schema (column names and types).t = pxt.create_table('my_table', {'col1': pxt.IntType(), 'col2': pxt.StringType()})
pxt.create_viewCreate a filtered or transformed view of an existing table.t = pxt.create_view('my_view', base_tbl, filter=base_tbl.col > 10)
pxt.drop_tableDelete a table.pxt.drop_table('my_table')
pxt.get_tableGet a handle to an existing table (table, view, or snapshot).table = pxt.get_table('video_data')
pxt.list_tablesList all tables within a directory.pxt.list_tables()
pxt.moveMove a schema object to a new directory and/or rename it.pxt.move('video_data', 'experiments.video_data')
t.insert()Insert rows into a table.t.insert([{'col1': 'green', ...}, {'col1': 'red', ...}])
t.update()Update values in specific rows of a table.t.update({'int_col': 1}, where=tbl.int_col == 0)
t.delete()Delete rows from a table based on a condition.tbl.delete(tbl.a > 5)
t.revert()Revert the table to the previous version.t.revert()

Directory Operations

FunctionDescriptionExample
pxt.create_dirCreate a new directory to organize your tables.pxt.create_dir('experiments')
pxt.list_dirsList the directories within a specified path.pxt.list_dirs('project_x')
pxt.rm_dirRemove an empty directory.pxt.rm_dir('experiments')

Frame Extraction

FunctionDescriptionExample
FrameIteratorIterate over video frames within a table view, extracting frames at a specified FPS (frames per second).f = pxt.create_view('frames', t, iterator=FrameIterator.create(videos=t, fps=0))

Column Manipulation

FunctionDescriptionExample
t.add_column()Add a new column with a specified type or computed value.t.add_column(new_col=pxt.IntType()) or t['new_col'] = pxt.IntType()
t.rename_column()Rename an existing column.t.rename_column('old_col', 'new_col')
t.drop_column()Remove an existing column.t.drop_column('old_col')
t.select()Select specific columns and apply transformations using Python-like syntax.t.select(t.col2, t.col3 + 5).where(t.col1 == 'green').show()

Image Transformations

Available attributes on ImageType columns: mode, height, width
Available methods on ImageType columns: convert, crop, resize, rotate, transform, transpose (and others)

Example

t.select(t.frame.resize((224, 224)).rotate(90)).collect()

Remember, these are just the built-in functions and operations currently listed in the API Cheat Sheet.

Pixeltable is designed to be extensible, so you can also define your own functions: User-Defined Functions (UDFs) using the @pxt.udf decorator for advanced customization.