State management

Manage secrets, variables, and user-defined objects in your notebook's global state

State Management in Livedocs

In Livedocs, your notebook maintains a global state that you can browse and manage directly from the Variables section in the left sidebar of the editor. This state is available across all cells, making it easy to reuse data, functions, secrets, and variables without redefining them.

The sidebar is divided into three main sections:


1. Secrets

Secrets are stored securely for safe access.

  • Setup: Configure secrets in the Workspace Settings under the Secrets section.
  • Example:
    # Without default value
    livedocs.secrets("MY_API_KEY")
    
    # With a default value for safe failure
    livedocs.secrets("MY_API_KEY", "NO-KEY-AVAILABLE")
  • Use case: Avoid hardcoding sensitive credentials like API keys or configurations directly into your notebook.

2. Variables

Variables are simple key-value pairs (string values only) that you can set, update, and unset programmatically. They persist until explicitly removed.

  • Set a variable:
    livedocs.set_var("name", "arsalan")
  • Get a variable:
    livedocs.get_var("name")  # returns "arsalan"
  • Unset a variable:
    livedocs.unset_var("name")

Built-in Variables

These are automatically set by Livedocs for context:

  • context – “logic” if run manually, or “scheduled” if triggered by a schedule.
  • last_scheduled_run – ISO timestamp of the last scheduled run (undefined if never run).

Built-in variables cannot be unset, but can be read just like any other variable.


3. User-defined Variables

All Python variables, functions, dataframes, and objects created in your notebook’s kernel are available globally until the kernel is restarted.

  • Example:
    my_df = pd.read_csv("data.csv")
    result = process_data(my_df)
    my_df and result are now available for use in other cells.

Tip: Use the sidebar to quickly inspect what’s currently in your notebook’s state, making it easier to debug, reuse, and manage your workspace.