---
title: "vuer.rtc.store"
section: "Python API"
order: 19
description: "Python API reference for vuer.rtc.store"
---

# vuer.rtc.store

GraphStore - High-level API for managing CRDT-based scene graph state.

This module provides the main interface for working with the data store,
matching the TypeScript createGraph() API.

Usage:
    from vuer.rtc import create_graph

    store = create_graph(
        session_id="my-session",
        on_send=lambda msg: websocket.send(msg.to_dict()),
    )

    # Edit operations (buffered)
    store.edit(Operation(key="cube", otype="vector3.add", path="position", value=[1, 0, 0]))

    # Commit edits as a message
    msg = store.commit()

    # Receive remote messages
    store.receive(incoming_message)

    # Undo/redo
    store.undo()
    store.redo()

    # Get current state
    state = store.get_state()
    graph = state.graph

## GraphStore

```python
class GraphStore
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L66)

Main store for managing CRDT-based scene graph state.

This class provides the high-level API for working with the data store:
- edit(): Add uncommitted operations
- commit(): Commit edits as a message
- receive(): Process received messages from server
- ack(): Mark message as acknowledged
- undo()/redo(): Undo/redo operations
- compact(): Create snapshot from acknowledged entries
- get_state(): Get current state
- subscribe(): Subscribe to state changes

## GraphStore.__init__

```python
def __init__(self, session_id: str, on_send: Optional[SendCallback]=None, on_state_change: Optional[StateChangeCallback]=None, initial_snapshot: Optional[Snapshot]=None)
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L81)

Create a new GraphStore.

Args:
    session_id: Unique identifier for this session
    on_send: Callback invoked when a message should be sent to server
    on_state_change: Callback invoked when state changes
    initial_snapshot: Optional snapshot to restore from

## GraphStore.get_state

```python
def get_state(self) -> ClientState
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L107)

Get the current client state.

## GraphStore.graph

```python
def graph(self) -> SceneGraph
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L112)

Get the current scene graph.

## GraphStore.session_id

```python
def session_id(self) -> str
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L117)

Get the session ID.

## GraphStore.subscribe

```python
def subscribe(self, callback: StateChangeCallback) -> Callable[[], None]
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L121)

Subscribe to state changes.

Args:
    callback: Function called with new state on each change

Returns:
    Unsubscribe function

## GraphStore.edit

```python
def edit(self, op: Operation) -> None
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L148)

Add an uncommitted operation to the edit buffer.

Operations are buffered and not immediately applied. Call commit()
to apply them and create a message.

Args:
    op: The operation to add

## GraphStore.edit_batch

```python
def edit_batch(self, ops: List[Operation]) -> None
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L174)

Add multiple uncommitted operations to the edit buffer.

Args:
    ops: List of operations to add

## GraphStore.cancel_edits

```python
def cancel_edits(self) -> None
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L184)

Cancel all uncommitted edits and revert to the starting state.

## GraphStore.has_pending_edits

```python
def has_pending_edits(self) -> bool
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L193)

Check if there are uncommitted edits.

## GraphStore.commit

```python
def commit(self, description: Optional[str]=None) -> Optional[CRDTMessage]
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L201)

Commit current edits as a CRDT message.

Args:
    description: Optional description for the commit

Returns:
    The committed message, or None if no edits to commit

## GraphStore.receive

```python
def receive(self, msg: CRDTMessage) -> None
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L251)

Process a message received from the server or another client.

Args:
    msg: The received message

## GraphStore.ack

```python
def ack(self, msg_id: str) -> None
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L314)

Mark a message as acknowledged by the server.

Args:
    msg_id: ID of the message to acknowledge

## GraphStore.get_unacked_messages

```python
def get_unacked_messages(self) -> List[CRDTMessage]
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L327)

Get all unacknowledged messages (for resending on reconnect).

## GraphStore.has_pending_messages

```python
def has_pending_messages(self) -> bool
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L335)

Check if there are unacknowledged messages.

## GraphStore.get_pending_count

```python
def get_pending_count(self) -> int
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L339)

Get count of unacknowledged messages.

## GraphStore.undo

```python
def undo(self) -> Optional[CRDTMessage]
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L347)

Undo the last operation from this session.

Returns:
    The undo message to send, or None if nothing to undo

## GraphStore.redo

```python
def redo(self) -> Optional[CRDTMessage]
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L412)

Redo the last undone operation from this session.

Returns:
    The redo message to send, or None if nothing to redo

## GraphStore.compact

```python
def compact(self) -> Snapshot
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L491)

Create a snapshot from all acknowledged entries.

This compacts the journal by baking acknowledged entries into
the snapshot, reducing memory usage and speeding up replay.

Returns:
    The new snapshot

## GraphStore.get_snapshot

```python
def get_snapshot(self) -> Snapshot
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L540)

Get the current snapshot.

## GraphStore.init_from_server

```python
def init_from_server(self, snapshot: Snapshot, journal: List[CRDTMessage]) -> None
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L548)

Initialize state from server-provided snapshot and journal.

Args:
    snapshot: The server's snapshot
    journal: Journal entries to replay (as messages)

## create_graph

```python
def create_graph(session_id: Optional[str]=None, on_send: Optional[SendCallback]=None, on_state_change: Optional[StateChangeCallback]=None, initial_snapshot: Optional[Snapshot]=None) -> GraphStore
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/docs/latest/src/vuer/rtc/store.py#L586)

Factory function to create a GraphStore.

This matches the TypeScript createGraph() API.

Args:
    session_id: Unique session identifier (auto-generated if not provided)
    on_send: Callback when message should be sent to server
    on_state_change: Callback when state changes
    initial_snapshot: Optional snapshot to restore from

Returns:
    A new GraphStore instance

## Public imports

These symbols are available from this module. Their definitions are documented in the linked modules.

- [`ClientState`](/python-api/rtc/types#clientstate) — `vuer.rtc.types.ClientState`
- [`CRDTMessage`](/python-api/rtc/types#crdtmessage) — `vuer.rtc.types.CRDTMessage`
- [`EditBuffer`](/python-api/rtc/types#editbuffer) — `vuer.rtc.types.EditBuffer`
- [`JournalEntry`](/python-api/rtc/types#journalentry) — `vuer.rtc.types.JournalEntry`
- [`Operation`](/python-api/rtc/types#operation) — `vuer.rtc.types.Operation`
- [`SceneGraph`](/python-api/rtc/types#scenegraph) — `vuer.rtc.types.SceneGraph`
- [`Snapshot`](/python-api/rtc/types#snapshot) — `vuer.rtc.types.Snapshot`
- [`OType`](/python-api/rtc/types#otype) — `vuer.rtc.types.OType`
- [`create_empty_graph`](/python-api/rtc/types#create_empty_graph) — `vuer.rtc.types.create_empty_graph`
- [`create_initial_snapshot`](/python-api/rtc/types#create_initial_snapshot) — `vuer.rtc.types.create_initial_snapshot`
- [`create_initial_state`](/python-api/rtc/types#create_initial_state) — `vuer.rtc.types.create_initial_state`
- [`generate_message_id`](/python-api/rtc/types#generate_message_id) — `vuer.rtc.types.generate_message_id`
- [`increment_clock`](/python-api/rtc/types#increment_clock) — `vuer.rtc.types.increment_clock`
- [`merge_clocks`](/python-api/rtc/types#merge_clocks) — `vuer.rtc.types.merge_clocks`
- [`apply_message_mut`](/python-api/rtc/operations/dispatcher#apply_message_mut) — `vuer.rtc.operations.dispatcher.apply_message_mut`
- [`apply_operation`](/python-api/rtc/operations/dispatcher#apply_operation) — `vuer.rtc.operations.dispatcher.apply_operation`
- [`OperationMeta`](/python-api/rtc/operations/dispatcher#operationmeta) — `vuer.rtc.operations.dispatcher.OperationMeta`
- [`rebuild_graph`](/python-api/rtc/operations/dispatcher#rebuild_graph) — `vuer.rtc.operations.dispatcher.rebuild_graph`
