Documentation Index
Fetch the complete documentation index at: https://docs.pixeltable.com/llms.txt
Use this file to discover all available pages before exploring further.
class pixeltable.serving.FastAPIRouter
A FastAPIAPIRouter that exposes Pixeltable table operations as HTTP endpoints.
method add_delete_route()
Signature
t matching the given match column values.
The request body contains the match column values as JSON fields. The endpoint deletes every row
where each match column equals the provided value, and returns the number of rows affected.
Parameters:
t(pxt.Table): The table to delete from.path(str): The URL path for the endpoint.match_columns(list[str] | None): Columns to match on (AND-ed equality). Defaults to the table’s primary key. Must be non-empty.background(bool, default:False): If True, return immediately with{"id": ..., "job_url": ...}and run the operation in a background thread. Polljob_urlfor the result.
method add_insert_route()
Signature
t and returns the resulting row.
The request body contains the input column values as JSON fields (or as
multipart form data when
uploadfile_inputs is used). The response is a JSON object with the output column values,
or a FileResponse
when return_fileresponse=True.
Parameters:
-
t(pxt.Table): The table to insert into. -
path(str): The URL path for the endpoint. -
inputs(list[str] | None): Columns to accept as request fields. Defaults to all non-computed columns. -
uploadfile_inputs(list[str] | None): Columns to accept asUploadFilefields (must be media-typed). These are sent as multipart form data; all other inputs becomeFormfields. -
outputs(list[str] | None): Columns to include in the response. Defaults to all columns (including inputs). -
return_fileresponse(bool, default:False): If True, return the single media-typed output column as aFileResponse. Requires exactly one media-typed output column. -
export_sql(SqlExport | None): If set, export each inserted row into an external RDBMS table after the Pixeltable insert succeeds. SeeSqlExportfor the target specification and supportedmethodvalues. The row written is the response body: same columns asoutputs, with media-typed columns rendered as URL strings (so the corresponding target columns must be string-typed). Schema compatibility against the response columns is validated once at registration time; the target table must already exist or registration fails. Mutually exclusive withreturn_fileresponse. Compatible withbackground=True(the SQL write runs in the worker thread). Note: when paired withmethod='update', a Pixeltable insert triggers a target-side update — this is intentional, supporting the append-only-source / current-state-view pattern. If the external write fails after the Pixeltable insert has already succeeded, the request fails with HTTP 500; no rollback is performed. -
background(bool, default:False): If True, return immediately with{"id": ..., "job_url": ...}and run the insert in a background thread. Polljob_urlfor the result. Mutually exclusive withreturn_fileresponse.
FileResponse:
prompt, result) to public.generations in the target database.
Background processing:
method add_query_route()
Signature
@pxt.query or pxt.retrieval_udf and returns the results.
By default the endpoint accepts POST requests with a JSON
Body and returns {"rows": [{...}, ...]}.
Use method='get' for
Query parameters instead.
Parameters:
path(str): The URL path for the endpoint.query(pxt.Function): The query to execute, created with@pxt.queryorpxt.retrieval_udf().inputs(list[str] | None): Parameters to accept as request fields. Defaults to all query parameters.uploadfile_inputs(list[str] | None): Parameters to accept asUploadFilefields (must be media-typed).one_row(bool, default:False): If True, expect exactly one result row and return it as a plain JSON object (not wrapped in{"rows": [...]}). 0 rows produces a 404, >1 rows a 409.return_fileresponse(bool, default:False): If True, return the single media-typed result column as aFileResponse. Requiresone_rowsemantics (0 rows -> 404, >1 rows -> 409). Mutually exclusive withbackground.background(bool, default:False): If True, return immediately with{"id": ..., "job_url": ...}and run the query in a background thread. Polljob_urlfor the result. Mutually exclusive withreturn_fileresponse.method(Literal['get', 'post'], default:'post'): HTTP method for the endpoint ('get'or'post').
FileResponse:
method add_update_route()
Signature
t and returns the updated row.
The row to update is identified by its primary key, which must be included in the
request body alongside the input column values. The update is performed via a
single-row batch_update() call, using the primary
key columns to identify the row and the columns referenced in inputs as the values
to set.
The request body contains values for the primary key columns plus the input columns
as JSON fields. The response is a JSON object with the output column values, or a
FileResponse
when return_fileresponse=True.
Note: media-typed columns (image, video, audio, document) are excluded from inputs
and from the default input set.
Parameters:
-
t(pxt.Table): The table to update. -
path(str): The URL path for the endpoint. -
inputs(list[str] | None): Columns to accept as request fields, excluding primary key and media-typed columns (which cannot be updated). Defaults to all non-computed, non-primary-key, non-media columns. -
outputs(list[str] | None): Columns to include in the response. Defaults to all columns (including inputs). -
return_fileresponse(bool, default:False): If True, return the single media-typed output column as aFileResponse. Requires exactly one media-typed output column. -
export_sql(SqlExport | None): If set, export each updated row into an external RDBMS table after the Pixeltable update succeeds. SeeSqlExportfor the target specification and supportedmethodvalues. The row written is the response body: same columns asoutputs, with media-typed columns rendered as URL strings (so the corresponding target columns must be string-typed). Schema compatibility is validated once at registration time; the target table must already exist or registration fails. Mutually exclusive withreturn_fileresponse. Compatible withbackground=True. Note: withmethod='insert'(the default), every update appends a new row to the target table — the target acts as an audit log, not a current-state view. Usemethod='update'to keep the target as a current-state view keyed on the target’s primary key. If the external write fails after the Pixeltable update has already succeeded, the request fails with HTTP 500; no rollback is performed. -
background(bool, default:False): If True, return immediately with{"id": ..., "job_url": ...}and run the update in a background thread. Polljob_urlfor the result. Mutually exclusive withreturn_fileresponse.
id):
method insert_route()
Signature
Table.insert() followed by user-defined post-processing.
The request body carries the input column values (JSON, or multipart form data when uploadfile_inputs is
used). After inserting the row, the decorated function is called with the requested output columns as
keyword arguments (parameter names and Pixeltable types must match outputs). Its return value must be a
Pydantic model and is returned as the HTTP response body.
Media-typed outputs (image, video, audio, document) are delivered to the function as /media/ URL
strings — annotate those parameters as str (or str | None if the column is nullable), not as
pxt.Image / pxt.Video / etc.
Parameters:
-
t(pxt.Table): The table to insert into. -
path(str): The URL path for the endpoint. -
inputs(list[str] | None): Columns to accept as request fields. Defaults to all non-computed columns. -
uploadfile_inputs(list[str] | None): Columns to accept asUploadFilefields (must be media-typed). These are sent as multipart form data; all other inputs becomeFormfields. -
outputs(list[str] | None): Columns from the inserted row to pass to the decorated function as keyword arguments. Defaults to all columns. -
export_sql(SqlExport | None): If set, export the decorated function’s return value into an external RDBMS table after the Pixeltable insert succeeds. SeeSqlExportfor the target specification and supportedmethodvalues. The row written is the user function’s pydantic return value (its fields, not the source columns), so the target table schema must match those fields. Media-typed fields are modeled as strings (URL form). Schema compatibility is validated once at registration time; the target table must already exist or registration fails. Compatible withbackground=True(the SQL write runs in the worker thread). If the external write fails after the Pixeltable insert has already succeeded, the request fails with HTTP 500; no rollback is performed. -
background(bool, default:False): If True, return immediately with{"id": ..., "job_url": ...}and run the insert plus post-processing in a background thread. Polljob_urlfor the result; the decorated function’s return value is delivered as the job result.
caption, score (the response model fields) to captions.
method update_route()
Signature
Table.batch_update() followed by
user-defined post-processing.
The request body carries values for the primary key columns (to identify the row) plus the
input column values as JSON fields. After updating the row, the decorated function is called
with the requested output columns as keyword arguments (parameter names and Pixeltable types
must match outputs). Its return value must be a Pydantic model and is returned as the HTTP
response body.
Media-typed outputs (image, video, audio, document) are delivered to the function as /media/ URL
strings — annotate those parameters as str (or str | None if the column is nullable), not as
pxt.Image / pxt.Video / etc.
If the row does not exist, the endpoint returns HTTP 404 without calling the decorated
function.
Note: media-typed columns (image, video, audio, document) and primary key columns cannot be
used as inputs. Primary key columns are always part of the request body for row
identification.
Parameters:
-
t(pxt.Table): The table to update. -
path(str): The URL path for the endpoint. -
inputs(list[str] | None): Columns to accept as update fields. Defaults to all non-computed, non-primary-key, non-media columns. -
outputs(list[str] | None): Columns from the updated row to pass to the decorated function as keyword arguments. Defaults to all columns. -
export_sql(SqlExport | None): If set, export the decorated function’s return value into an external RDBMS table after the Pixeltable update succeeds. SeeSqlExportfor the target specification and supportedmethodvalues. The row written is the user function’s pydantic return value (its fields, not the source columns), so the target table schema must match those fields. Media-typed fields are modeled as strings (URL form). Schema compatibility is validated once at registration time; the target table must already exist or registration fails. Compatible withbackground=True. Note: withmethod='insert'(the default), every update appends a new row to the target table — the target acts as an audit log, not a current-state view. Usemethod='update'to keep the target as a current-state view keyed on the target’s primary key. If the external write fails after the Pixeltable update has already succeeded, the request fails with HTTP 500; no rollback is performed. -
background(bool, default:False): If True, return immediately with{"id": ..., "job_url": ...}and run the update plus post-processing in a background thread. Polljob_urlfor the result; the decorated function’s return value is delivered as the job result.