Skip to content

Python reference

Import the SDK once at the beginning of a Python processing script:

import flasktrack as ft

Read inputs

ft.input_table(name)

Reads an Arrow table input and returns a pyarrow.Table.

rows = ft.input_table("rows")

ft.input_json(name, *, max_bytes=67108864)

Reads and decodes a JSON input. The optional size limit protects the process from accidentally loading an unexpectedly large JSON document.

config = ft.input_json("config")
threshold = float(config["threshold"])

ft.input_file(name)

Returns the read-only local path for a declared file input.

from pathlib import Path

document_path = Path(ft.input_file("document"))

Additional file readers

text = ft.input_text("notes")
payload = ft.input_bytes("payload")
table = ft.input_csv("csv_file")
table = ft.input_parquet("parquet_file", columns=["sample_id", "value"])

input_csv and input_parquet require a file input and return a pyarrow.Table.

Publish outputs

ft.output_table(name, value)

Publishes an Arrow table. value may be a PyArrow table, PyArrow record batch, pandas dataframe, or a Polars-compatible object with to_arrow().

ft.output_table("result", result)

ft.output_json(name, value, *, pretty=False, default=None)

Publishes standards-compliant JSON. NaN and infinity are rejected because they are not valid JSON values.

ft.output_json(
    "summary",
    {"accepted": accepted_count, "rejected": rejected_count},
)

ft.output_file(name, source_path, content_type=None)

Copies an existing file into the declared output and publishes it.

report_path = create_report()
ft.output_file("report", report_path, "application/pdf")

Additional file writers

These helpers publish file ports:

ft.output_parquet("dataset", table, compression="snappy")
ft.output_csv("export", table)
ft.output_text("readme", text, extension="txt")
ft.output_bytes("image", png_bytes, extension="png", content_type="image/png")

Do not use a file writer for an Arrow table or JSON output port.

Execution logs

ft.log("Starting normalization")
ft.log(f"Published {result.num_rows} rows", "info")
ft.log("No matching rows were found", "warn")

Supported levels are debug, info, warn, and error. Logs are useful for counts and processing decisions, but should not contain secrets or entire datasets.

Diagnostics

ft.sdk_info() returns the SDK version and non-secret runtime settings. It is primarily useful when troubleshooting with an administrator.