vuer.rtc - Python CRDT Data Store
A Python implementation of the @vuer-ai/vuer-rtc TypeScript package, providing CRDT-based real-time collaborative data structures for Vuer applications.
Overview
vuer.rtc enables consistent state management across Python and JavaScript clients by implementing:
- CRDT-based conflict resolution: Last-Write-Wins (LWW) for absolute values, additive operations for deltas
- Journal with snapshots: Enables undo/redo, fast replay, and state recovery
- Vector clocks: Causal ordering of concurrent operations
- TypeScript API compatibility: Same operator format as
@vuer-ai/vuer-rtc
Installation
The vuer.rtc module is included in the vuer package:
Quick Start
Core Concepts
1. Scene Graph
The scene graph is a hierarchical structure of nodes:
2. Operations
Operations modify the scene graph. Each operation has:
key: Target node keyotype: Operation type (e.g., "vector3.add", "node.insert")path: Property path (e.g., "transform.position")value: Operation-specific value
3. Messages
Messages batch operations and include CRDT metadata:
4. Journal and Snapshots
The journal tracks all committed messages, enabling:
- Undo/Redo: Mark messages as deleted/undeleted
- State recovery: Replay from snapshot + journal
- Synchronization: Track acknowledgments
Operation Types
Number Operations
| Type | Behavior | Example |
|---|---|---|
number.set | Last-Write-Wins | value=10 |
number.add | Additive | value=5 adds 5 |
number.multiply | Multiplicative | value=2 doubles |
number.min | Take minimum | value=5 caps at 5 |
number.max | Take maximum | value=5 floors at 5 |
Vector3 Operations
| Type | Behavior |
|---|---|
vector3.set | LWW, value=[x, y, z] |
vector3.add | Component-wise addition |
vector3.multiply | Component-wise multiplication |
vector3.applyEuler | Rotate by Euler angles |
vector3.applyQuaternion | Rotate by quaternion |
Boolean Operations
| Type | Behavior |
|---|---|
boolean.set | Last-Write-Wins |
boolean.or | Logical OR (enable wins) |
boolean.and | Logical AND (disable wins) |
Array Operations
| Type | Behavior |
|---|---|
array.set | Replace entire array |
array.push | Append item |
array.union | Set union (no duplicates) |
array.remove | Remove by value |
Scene Graph Operations
| Type | Description |
|---|---|
node.insert | Create new node as child of parent |
node.remove | Soft delete (tombstone) |
Meta Operations
| Type | Description |
|---|---|
meta.undo | Mark message as undone |
meta.redo | Restore undone message |
State Management
GraphStore API
Serialization
All types support serialization for network transport:
Integration with Vuer Server
Conflict Resolution
The CRDT implementation ensures eventual consistency:
- LWW Operations (
*.set): Higher Lamport timestamp wins - Additive Operations (
*.add,*.multiply): Order-independent merge - Boolean Operations:
orenables (any true),anddisables (all must be true)
SceneStore - Reactive Scene Management
For a simpler API focused on scene graph management with multi-session synchronization, see SceneStore.
SceneStore provides:
- Reactive updates to all subscribed sessions
- Async context manager for safe subscription cleanup
- Familiar
@operator pattern matching VuerSession - Snapshot access for state recovery