---
title: "vuer.rtc.scene_store"
section: "RTC"
order: 2000
description: "Python API reference for vuer.rtc.scene_store"
---

# vuer.rtc.scene_store

SceneStore - A reactive scene graph store that maintains state and broadcasts.

Mirrors the VuerSession API (set, add, upsert, update, remove) but also
maintains internal state and broadcasts to all subscribed sessions.

Usage:
    from vuer import Vuer, VuerSession
    from vuer.rtc import SceneStore
    from vuer.schemas import Box, Scene

    app = Vuer()
    store = SceneStore()

    @app.spawn(start=True)
    async def main(sess: VuerSession):
        async with store.subscribe(sess):
            store.set @ Scene(Box(key="box"))
            store.upsert @ Box(key="box2", position=[1, 0, 0])

            # Query state
            print(store.scene)  # Returns hydrated Scene object
            print(store.get("box"))  # Get element by key
            print(store.history)  # Complete operation history

## SceneGraph

```python
class SceneGraph
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L49)

Scene state model that manages the scene graph as a nested dict structure.

Provides methods for manipulating the scene: set, add, update, upsert, remove.
Can hydrate back to a Scene object via to_scene().

## SceneGraph.__init__

```python
def __init__(self)
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L57)

## SceneGraph.data

```python
def data(self) -> Optional[Dict[str, Any]]
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L61)

Get raw scene data as dict.

## SceneGraph.set_scene

```python
def set_scene(self, scene_data: Dict[str, Any]) -> None
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L65)

Set the entire scene.

## SceneGraph.get

```python
def get(self, key: str) -> Optional[Dict[str, Any]]
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L69)

Get element by key (recursive search).

## SceneGraph.add

```python
def add(self, node: Dict[str, Any], to: Optional[str]=None) -> None
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L75)

Add a node to the scene.

## SceneGraph.update

```python
def update(self, node: Dict[str, Any]) -> None
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L87)

Update an existing node by key.

## SceneGraph.upsert

```python
def upsert(self, node: Dict[str, Any], to: Optional[str]=None) -> None
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L97)

Update if exists, otherwise add.

## SceneGraph.remove

```python
def remove(self, key: str) -> None
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L104)

Remove a node by key.

## SceneGraph.to_scene

```python
def to_scene(self) -> Optional[Scene]
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L111)

Hydrate the scene data back to a Scene object.

## SubscriptionContext

```python
class SubscriptionContext
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L192)

Context manager for session subscription.

## SubscriptionContext.__init__

```python
def __init__(self, store: 'SceneStore', session: 'VuerSession')
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L195)

## SceneStore

```python
class SceneStore(SceneOps)
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L208)

A reactive store that maintains scene state and broadcasts to subscribers.

Inherits from SceneOps which provides: set, add, upsert, update, remove.
Uses SceneGraph internally for state management.

Example:
    store = SceneStore()

    @app.spawn(start=True)
    async def main(sess: VuerSession):
        async with store.subscribe(sess):
            store.set @ Scene(Box(key="box"))
            store.upsert @ Sphere(key="sphere", position=[1, 0, 0])

            # Query state
            print(store.get("box"))
            print(store.scene)  # Returns Scene object
            print(store.history)

## SceneStore.__init__

```python
def __init__(self)
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L230)

## SceneStore.history

```python
def history(self) -> List[Dict[str, Any]]
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L236)

Get complete history of all operations.

## SceneStore.scene

```python
def scene(self) -> Optional[Scene]
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L241)

Get current scene as a hydrated Scene object.

## SceneStore.scene_data

```python
def scene_data(self) -> Optional[Dict[str, Any]]
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L246)

Get current scene state as raw dict.

## SceneStore.get

```python
def get(self, key: str) -> Optional[Dict[str, Any]]
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L250)

Get element by key.

## SceneStore.subscribe

```python
def subscribe(self, session: 'VuerSession') -> SubscriptionContext
```

[Source](https://github.com/vuer-ai/vuer-docs/blob/main/src/vuer/rtc/scene_store.py#L254)

Subscribe a session to receive broadcasts.

### Inherited members

- `set` — from [`vuer.server.SceneOps`](/python-api/server#sceneops)
- `update` — from [`vuer.server.SceneOps`](/python-api/server#sceneops)
- `add` — from [`vuer.server.SceneOps`](/python-api/server#sceneops)
- `upsert` — from [`vuer.server.SceneOps`](/python-api/server#sceneops)
- `remove` — from [`vuer.server.SceneOps`](/python-api/server#sceneops)

## Public imports

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

- [`Add`](/python-api/events#add) — `vuer.events.Add`
- [`Remove`](/python-api/events#remove) — `vuer.events.Remove`
- [`Set`](/python-api/events#set) — `vuer.events.Set`
- [`Update`](/python-api/events#update) — `vuer.events.Update`
- [`Upsert`](/python-api/events#upsert) — `vuer.events.Upsert`
- [`Scene`](/python-api/schemas/scene_components#scene) — `vuer.schemas.scene_components.Scene`
- [`SceneOps`](/python-api/server#sceneops) — `vuer.server.SceneOps`
