ClusterContext#
- class polars_nanook.ClusterContext(
- uri: str,
- *,
- domain_name: str | None = None,
- extra_headers: Mapping[str, str] | None = None,
- tls_options: TLSOptions | None = None,
- observatory: ClientOptions | None = None,
Cluster context in which queries are executed.
The cluster context is an abstraction of some remote cluster that is routable from the client. This will bypass any calls to the Polars Nanook control plane and talk to the cluster’s scheduler directly. Will attempt to establish an gRPC connection on __init__.
- Parameters:
- uri
URI of the scheduler reachable from the client, e.g.
https://[HOSTNAME|IP]:5051. If no port is specified, defaults to5051.- domain_name
Used as authority, host header (inc port) and for TLS verification. Make sure to use an [IP] in the uri when using this option. https://developer.mozilla.org/en-US/docs/Glossary/Domain_name
- extra_headers
Additional HTTP headers to include with each request to the cluster. The following headers are forbidden and will raise an error if provided:
host,content-length,transfer-encoding.- tls_options
TLS options for the connection, including custom CA certificates and insecure mode. If not set, uses system defaults.
- observatory
Custom client options for the observatory. If not set, observatory is automatically configured from
uriusing the default port3001. When specified, none of the other options will be copied by default.
Examples
>>> import polars as pl >>> import polars_nanook as pn
>>> lf = pl.LazyFrame({"x": list(range(100))})
>>> # Simple config, observatory will be automatically configured. >>> ctx = pn.ClusterContext(uri="https://[HOSTNAME|IP]") >>> lf.remote(ctx).execute()
>>> # Config with custom CA, will be used for both scheduler and observatory. >>> with open("certificate.pem", "rb") as cert: ... custom_ca = cert.read() >>> ctx = pn.ClusterContext( ... uri="https://[HOSTNAME|IP]", ... tls_options=TLSOptions( ... ca_cert=custom_ca, # Will also be used for the observatory. ... ), ... ) >>> lf.remote(ctx).execute()
>>> # Custom config for observatory. Observatory will use default tls_options. >>> ctx = pn.ClusterContext( ... uri="https://[IP]:5051", ... domain_name="pola.rs", ... tls_options=TLSOptions( ... insecure=True, # Will NOT be used for the observatory. ... ), ... observatory=ClientOptions(uri="https://[IP]:3001", authority="obs.pola.rs"), ... ) >>> lf.remote(ctx).execute()
Methods:
cluster_infoGet static information about the cluster.
show_versionsPrint the versions of the compute plane components.
- cluster_info() ClusterInfo
Get static information about the cluster.
The information is fetched from the cluster’s scheduler once and cached until the connection to the cluster is reset, e.g. by stopping the compute context.
- Raises:
- RuntimeError
If the compute context is not accessible or not in direct connection mode.
Examples
>>> ctx = pc.ClusterContext(uri="http://localhost") >>> ctx.cluster_info().anonymous_result_location 's3://bucket/query_outputs/'
- show_versions() None
Print the versions of the compute plane components.
- Raises:
- RuntimeError
If the compute context is not accessible or not in direct connection mode.
Examples
>>> ctx = pn.ClusterContext(uri="http://localhost") >>> ctx.show_versions() Compute Plane Version: 0.1.0 Polars Python Version: 1.38.1 Polars Rust Revision: c1764bcd298d3d2cfab4629eb0a5c36be412786e