Understanding Pixeltable types for structured data, media, and ML workflows
Pixeltable provides a rich type system designed for multimodal AI applications. Every column and expression has an associated type that determines what data it can hold and what operations are available.
pxt.Audio, pxt.Video, and pxt.Document return file paths when queried. Pixeltable automatically downloads and caches remote media locally. Use .fileurl to get the original URL.
Use uuid7() to create columns that auto-generate unique identifiers:
Copy
Ask AI
from pixeltable.functions.uuid import uuid7# UUID as primary key - auto-generated for each rowproducts = pxt.create_table('example/products', { 'id': uuid7(), # Auto-generates UUID 'name': pxt.String, 'price': pxt.Float}, primary_key=['id'])# Insert without providing 'id' - it's generated automaticallyproducts.insert([{'name': 'Laptop', 'price': 999.99}])
You can also add UUIDs to existing tables:
Copy
Ask AI
# Add UUID column to existing tableorders.add_computed_column(order_id=uuid7())
By default, stored=True for all computed columns—values compute once and persist. For UUIDs, this ensures stable identifiers. Setting stored=False would regenerate UUIDs on every query (almost never what you want).
See the UUID cookbook for more examples of working with unique identifiers.
# Arrays can be sliced like NumPy arrayst.select( t.embedding[0], # First element t.embedding[5:10], # Slice t.embedding[-3:] # Last 3 elements).collect()
Use astype() to convert string file paths or URLs to media types:
Copy
Ask AI
# String file paths → Media typesmedia = pxt.create_table('media_table', {'path': pxt.String})media.insert([{'path': '/path/to/image.jpg'}])# Convert string path to Imagemedia.select(img=media.path.astype(pxt.Image)).collect()
Primary use case: Converting string columns containing file paths or URLs to media types (Image, Video, Audio, Document).
For other type conversions, use built-in functions from the string, json, or math modules. For example, use string.len() to get string length as an integer, or access JSON fields directly.
Media columns (Image, Video, Audio, Document) have special properties:
Copy
Ask AI
# Local file path (Pixeltable ensures this is on local filesystem)t.select(t.image.localpath).collect()# Original URL where the media residest.select(t.image.fileurl).collect()
Computed columns have errortype and errormsg properties for debugging:
Copy
Ask AI
# Create a computed column that might failt.add_computed_column( result=some_function(t.input), on_error='ignore' # Continue on errors)# Query error information for failed rowst.where(t.result == None).select( t.input, t.result.errortype, # Exception class name t.result.errormsg # Error message).collect()