For AI agents: the complete documentation index is at llms.txt. Remove the trailing slash from a page URL and append .md to read its Markdown version. For the docs home, use index.md.

StateManager

reflex.istate.manager.StateManager

A class to manage many client states.

Methods

create

create()

Create a new state manager.

Returns

The state manager (either disk, memory or redis).

Raises

InvalidStateManagerModeError

If the state manager mode is invalid.

get_state

get_state(token: StateToken[TOKEN_TYPE] | str) -> TOKEN_TYPE

Get the state for a token.

Parameters

token

The token to get the state for.

Returns

The state for the token.

set_state

set_state(
    token: StateToken[TOKEN_TYPE] | str,
    state: TOKEN_TYPE,
    **context: Unpack[StateModificationContext],
)

Set the state for a token.

Parameters

token

The token to set the state for.

state

The state to set.

context

The state modification context.

modify_state

modify_state(
    token: StateToken[TOKEN_TYPE] | str,
    **context: Unpack[StateModificationContext],
) -> AsyncIterator[TOKEN_TYPE]

Modify the state for a token while holding exclusive lock.

Parameters

token

The token to modify the state for.

context

The state modification context.

Yields

The state for the token.

modify_state_with_links(
    token: StateToken[TOKEN_TYPE] | str,
    previous_dirty_vars: Optional[dict[str, set[str]]] = None,
    **context: Unpack[StateModificationContext],
) -> AsyncIterator[TOKEN_TYPE]

Modify the state for a token, including linked substates, while holding exclusive lock.

Parameters

token

The token to modify the state for.

previous_dirty_vars

The previously dirty vars for linked states.

context

The state modification context.

Yields

The state for the token with linked states patched in.

close

close()

Close the state manager.