Skip to main content

Python Language Reference

Python query scripts run real Python — interpreted by RustPython compiled to WebAssembly and executed in a sandboxed environment. Scripts are written in full Python syntax and can import frozen standard libraries; the data processing API uses a Polars-style DataFrame / Series / Expr design.

This reference describes the built-in types and functions that are directly available (no import required) in the script scope. For a getting-started guide and overall workflow, see Python Query Scripts.

Script Conventions

  • Scripts must define a main() function as the entry point; its return value is the query result.
  • main() can return a DataFrame, Series, or JSON-serializable values such as list[dict].
  • The following names are injected into scope and require no import: DataFrame, Series, pl, query, fetch, args, print.
  • The pl namespace provides pl.col() / pl.lit() and dtype constants, as well as pl.when() for conditional expressions and pl.cov() / pl.corr() for statistics.

Built-in Functions

Built-in Types

Examples

  • Examples — Common patterns: querying, parameters, HTTP, group-by aggregation, and more

Data Types

The pl namespace provides the following logical data type constants:

ConstantDescription
pl.Int / pl.Int32 / pl.Int64Integer (physically Int64, repr is Int)
pl.Float / pl.Float32 / pl.Float64Float (physically Float64, repr is Float)
pl.BooleanBoolean
pl.StringString
pl.DatetimeDatetime
pl.DateDate
note

Precision is not distinguished on the user side: pl.Int32 == pl.Int64 and pl.Float32 == pl.Float64 both hold.