Storage

Save named values for the current macro to use in later runs. All flows in the same run share Storage; ordinary variables are shared only by sequential PYTHON_CODE actions in one flow, including GROUP actions. Parallel flows have separate variables. Storage is not a messaging channel between processes.

Syntax

Storage

This class cannot be constructed directly.

Returns

—

Example

# Persist values across separate macro runs
run_count = Storage.get("run_count", 0)
run_count = run_count + 1
Storage.set("run_count", run_count)
Storage.set("last_point", Point(500, 900))
MacroPanel.notify("Run #" + str(run_count))

Methods

8 methods

Storage.get

Read one persisted value by key and optionally fall back to a default when the key is missing.

Syntax

Storage.get(key, default=None)

Parameters

NameDescription
keyAny
Key to look up.
Required · Positional or named
No default
defaultAny?
Fallback value returned when the key is missing.
Optional · Positional or named
Default: None

Returns

Any? — The stored value for that key, or the provided default.

Example

# Restore a persisted counter with a fallback default
run_count = Storage.get("run_count", 0)

Storage.set

Save a value under a key, replacing any previous value. Supported types include Number, String, Boolean, Point, Region, list, tuple, dict, set, and None; collections may contain other collections.

Syntax

Storage.set(key, value)

Parameters

NameDescription
keyAny
Key to write.
Required · Positional or named
No default
valueAny?
Value to persist for that key.
Required · Positional or named
No default

Returns

None — No return value. Other Storage reads see the change immediately. Changes are saved to the device after 2 seconds without a new write and again when the macro and all background flows finish.

Example

# Persist values for the next macro run
Storage.set("run_count", 3)
Storage.set("last_point", Point(500, 900))

Storage.remove

Remove one persisted entry and return the old value.

Syntax

Storage.remove(key)

Parameters

NameDescription
keyAny
Key to remove.
Required · Positional or named
No default

Returns

Any? — The removed value, or None when the key was missing.

Example

# Drop a persisted flag when it is no longer needed
old_flag = Storage.remove("boost_enabled")

Storage.contains

Check whether a persisted key currently exists.

Syntax

Storage.contains(key)

Parameters

NameDescription
keyAny
Key to test.
Required · Positional or named
No default

Returns

Boolean — `True` when the key exists, otherwise `False`.

Example

# Guard logic based on persisted state
if Storage.contains("last_point"):
    MacroPanel.notify("Saved point is ready")

Storage.keys

Get all persisted keys as a list in insertion order.

Syntax

Storage.keys()

Returns

list — A list of persisted keys.

Example

# Inspect which values are persisted for this macro
saved_keys = Storage.keys()

Storage.values

Get all persisted values as a list in insertion order.

Syntax

Storage.values()

Returns

list — A list of persisted values.

Example

# Read all persisted values for quick inspection
saved_values = Storage.values()

Storage.clear

Remove every persisted entry for the current macro.

Syntax

Storage.clear()

Returns

None — No direct return value. The storage becomes empty.

Example

# Reset all persisted Storage values
Storage.clear()

Storage.to_dict

Get the dictionary used by Storage in this run. All flows share it: adding, changing, or deleting its entries changes Storage immediately. These edits are saved after 2 seconds without a new write and again when the macro and all background flows finish.

Syntax

Storage.to_dict()

Returns

dict — The Storage dictionary itself, not a separate copy.

Example

# Read and update the full persisted storage dictionary
state = Storage.to_dict()
state["bonus"] = 5
MacroPanel.notify(str(state))