Skip to content

Get started with serverless

On serverless, Polars Nanook runs the compute for your queries, and it is on by default for every workspace. Before you start, install the client and sign up. Serverless supports only the latest releases of polars and polars-nanook.

Run a test query

A compute context with provider="serverless" describes the compute Polars Nanook starts for a query:

ComputeContext ยท LazyFrameRemote

import polars as pl
import polars_nanook as pn

pn.authenticate()

# Two nodes with 4 CPUs and 16 GiB each, in the region of the public datasets.
ctx = pn.ComputeContext(
    workspace="My workspace",
    provider="serverless",
    region="us-east-2",
    cpus=4,
    memory=16,
    cluster_size=2,
)

lineitem = pl.scan_parquet(
    "s3://polars-cloud-samples-us-east-2-prd/pdsh/sf10/lineitem.parquet"
)

query = lineitem.group_by("l_returnflag", "l_linestatus").agg(
    avg_price=pl.mean("l_extendedprice"),
    count_order=pl.len(),
)

with ctx:
    print(query.remote(ctx).collect())

The cluster starts with the first query in the with block and stops when the block exits. The portal lists the query under Queries, together with its compute and its profile.

Next steps