Config#

Config options#

Config.set_single_node([active])

Enable single node scaling mode independent of cluster state.

Config load, save, state#

Config.load(cfg)

Load (and set) previously saved Config options from a JSON string.

Config.load_from_file(file)

Load (and set) previously saved Config options from file.

Config.save(*[, if_set])

Save the current set of Config options as a JSON string.

Config.save_to_file(file)

Save the current set of Config options as a JSON file.

Config.state(*[, if_set, env_only])

Show the current state of all Config variables in the environment as a dict.

Config.restore_defaults()

Reset all polars Config settings to their default state.

While it is easy to restore all configuration options to their default value using restore_defaults, it can also be useful to reset individual options. This can be done by setting the related value to None, eg:

pl.Config.set_single_node(None)

Use as a context manager#

Note that Config supports setting context-scoped options. These options are valid only during scope lifetime, and are reset to their initial values (whatever they were before entering the new context) on scope exit.

You can take advantage of this by initialising a Config instance and then explicitly calling one or more of the available “set_” methods on it…

with pc.Config() as cfg:
    cfg.set_single_node(True)
    do_various_things()

# on scope exit any modified settings are restored to their previous state

…or, often cleaner, by setting the options in the Config init directly (optionally omitting the “set_” prefix for brevity):

with pc.Config(single_node=True):
    do_various_things()

Use as a decorator#

In the same vein, you can also use a Config instance as a function decorator to temporarily set options for the duration of the function call:

cfg_single_node = pc.Config(single_node=True, apply_on_context_enter=True)

@cfg_single_node
def run_remote_lazyframe(lf: pl.LazyFrame) -> None:
    lf.remote().execute()