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
Function | Description | Example |
---|---|---|
pxt.create_table | Create 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_view | Create a filtered or transformed view of an existing table. | t = pxt.create_view('my_view', base_tbl, filter=base_tbl.col > 10) |
pxt.drop_table | Delete a table. | pxt.drop_table('my_table') |
pxt.get_table | Get a handle to an existing table (table, view, or snapshot). | table = pxt.get_table('video_data') |
pxt.list_tables | List all tables within a directory. | pxt.list_tables() |
pxt.move | Move 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
Function | Description | Example |
---|---|---|
pxt.create_dir | Create a new directory to organize your tables. | pxt.create_dir('experiments') |
pxt.list_dirs | List the directories within a specified path. | pxt.list_dirs('project_x') |
pxt.rm_dir | Remove an empty directory. | pxt.rm_dir('experiments') |
Frame Extraction
Function | Description | Example |
---|---|---|
FrameIterator | Iterate 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
Function | Description | Example |
---|---|---|
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.
Updated about 1 month ago