polars.RemoteEngine#

class polars.RemoteEngine(
context: pc.ClientContext | None = None,
*,
scaling_mode: ScalingMode = 'auto',
engine: EngineTypeName = 'auto',
plan_type: PlanTypePreference = 'dot',
n_retries: int = 0,
labels: list[str] | str | None = None,
**kwargs: Any,
)[source]#

Execute queries remotely on Polars Cloud.

Use this engine with LazyFrame.collect(), LazyFrame.execute(), a LazyFrame.sink_* method, or as the default through Config.set_engine_affinity().

Requires the polars_cloud package.

LazyFrame.collect() and LazyFrame.collect_batches() stream the result back to this machine, which Polars Cloud only supports on a cluster context.

Warning

This functionality is considered unstable. It may be changed at any point without it being considered a breaking change.

Parameters:
context

Compute context. Defaults to the current polars_cloud session.

scaling_mode{‘auto’, ‘single-node’, ‘distributed’}

Whether to run the query on a single node or distributed over the cluster. If 'auto', a query runs distributed if the cluster has more than one node.

engine{‘auto’, ‘in-memory’, ‘streaming’, ‘gpu’}

Preferred worker engine. This is a hint and also controls plan rendering.

plan_type{‘dot’, ‘plain’}

Query-plan rendering format.

n_retries

Number of retries per failed stage.

labels

Labels attached to the query. Missing labels are created automatically.

**kwargs

Additional options forwarded to the distributed planner, such as max_workers, min_workers, shuffle_format or partitions_per_worker. Passing any of these is incompatible with scaling_mode='single-node'.

Examples

>>> import polars_cloud as pc  
>>> engine = pl.RemoteEngine(  
...     pc.ComputeContext(cpus=16, memory=64),
...     scaling_mode="distributed",
...     max_workers=8,
... )
>>> lf.sink_parquet("s3://my-destination/", engine=engine)  

Make it the default for every query in a scope:

>>> with pl.Config(engine_affinity=engine):  
...     lf.sink_parquet("s3://my-destination/")
__init__(
context: pc.ClientContext | None = None,
*,
scaling_mode: ScalingMode = 'auto',
engine: EngineTypeName = 'auto',
plan_type: PlanTypePreference = 'dot',
n_retries: int = 0,
labels: list[str] | str | None = None,
**kwargs: Any,
) → None[source]#

Methods

__init__([context, scaling_mode, engine, ...])

collect(lf, *, optimizations[, background, ...])

Collect lf remotely, streaming the result back to this machine.

collect_all(lfs, *, optimizations)

Execute several queries, potentially in parallel.

collect_all_async(lfs, *, optimizations[, ...])

Execute several queries asynchronously.

collect_async(lf, *, optimizations[, gevent])

Execute lf asynchronously.

collect_batches(lf, *, optimizations[, ...])

See polars.LazyFrame.collect_batches().

execute(lf, *, optimizations)

See polars.LazyFrame.execute().

sink_batches(lf, function, *, chunk_size, ...)

See polars.LazyFrame.sink_batches().

sink_csv(lf, path, *, include_bom, ...)

See polars.LazyFrame.sink_csv().

sink_ipc(lf, path, *, compression, ...)

See polars.LazyFrame.sink_ipc().

sink_ndjson(lf, path, *, compression, ...)

See polars.LazyFrame.sink_ndjson().

sink_parquet(lf, path, *, compression, ...)

See polars.LazyFrame.sink_parquet().

Attributes

name

Engine identifier.

plan_engine

Preferred worker engine used to render query plans.

context

Compute context in which queries are executed.

scaling_mode

Whether the query runs on a single node or distributed over the cluster.

engine

Engine the workers are asked to prefer.

plan_type

How query plans are rendered.

n_retries

How often a stage should be retried on failure.

labels

Labels attached to the query.

config

Additional options forwarded to the distributed planner.