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 aDataFrame,Series, or JSON-serializable values such aslist[dict].- The following names are injected into scope and require no
import:DataFrame,Series,pl,query,fetch,args,print. - The
plnamespace providespl.col()/pl.lit()and dtype constants, as well aspl.when()for conditional expressions andpl.cov()/pl.corr()for statistics.
Built-in Functions
- Built-in Functions —
query,fetch,args,print, and theplnamespace
Built-in Types
- DataFrame — 2D columnar table structure
- Series — 1D, single-typed column
- Expr Expressions — Lazy column expressions (with
.str/.dtnamespaces)
Examples
- Examples — Common patterns: querying, parameters, HTTP, group-by aggregation, and more
Data Types
The pl namespace provides the following logical data type constants:
| Constant | Description |
|---|---|
pl.Int / pl.Int32 / pl.Int64 | Integer (physically Int64, repr is Int) |
pl.Float / pl.Float32 / pl.Float64 | Float (physically Float64, repr is Float) |
pl.Boolean | Boolean |
pl.String | String |
pl.Datetime | Datetime |
pl.Date | Date |
note
Precision is not distinguished on the user side: pl.Int32 == pl.Int64 and pl.Float32 == pl.Float64 both hold.