Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/docs/source/src/python/polars-cloud/quickstart.py
8336 views
1
"""
2
# --8<-- [start:general]
3
import polars_cloud as pc
4
import polars as pl
5
6
# First, we need to define the hardware the cluster will run on.
7
# This can be done by specifying the minimum CPU and memory or
8
# by specifying the exact instance type in AWS.
9
10
ctx = pc.ComputeContext(memory=8, cpus=2, cluster_size=1)
11
12
# Then we write a regular lazy Polars query. In this example
13
# we compute the maximum of column.
14
15
lf = pl.LazyFrame(
16
{
17
"a": [1, 2, 3],
18
"b": [4, 4, 5],
19
}
20
).with_columns(
21
pl.col("a").max().over("b").alias("c"),
22
)
23
24
# At this point, the query has not been executed yet.
25
# We need to call `.remote()` to signal that we want to run
26
# on Polars Cloud and then `.execute()` send the query and execute it.
27
28
(
29
lf.remote(context=ctx).execute().await_result()
30
)
31
32
# We can then wait for the result with `await_result()`.
33
# The query and compute used will also show up in the
34
# portal at https://cloud.pola.rs/portal/
35
36
# --8<-- [end:general]
37
"""
38
39