vuer#

class vuer.Vuer[source]#

Bases: PrefixProto, Server

Vuer Server

This is the server for the Vuer client.

Usage:

app = Vuer()

@app.spawn
async def main(session: VuerSession):
     session.set @ Scene(children=[...])

app.run()
bind(fn=None, start=False)[source]#

Bind an asynchronous generator function for use in socket connection handler. The function should be a generator that yields Page objects.

Parameters:

fn – The function to bind.

Returns:

None

spawn(fn: Callable[[VuerProxy], Coroutine] = None, start=False)[source]#

Note: this is really a misnomer.

Parameters:
  • fn (Callable[[VuerProxy], Coroutine]) – The function to spawn.

  • start – Start server after binding

Returns:

None

async relay(request)[source]#

This is the relay object for sending events to the server.

Todo: add API for specifying the websocket ID. Or just broadcast to all. Todo: add type hint

Interface:

<uri>/relay?sid=<websocket_id>

Returns:

  • Status 200

  • Status 400

async bound_fn(session_proxy: VuerSession)[source]#

This is the default generator function in the socket connection handler

Parameters:

session_proxy (VuerSession) –

spawn_task(task)[source]#
get_url()[source]#

Get the URL for the Tassa. :return: The URL for the Tassa.

async send(ws_id, event: ServerEvent | None = None, event_bytes=None)[source]#
Parameters:

event (ServerEvent | None) –

async rpc(ws_id, event: ServerRPC, ttl=2.0) ClientEvent[source]#

RPC only takes a single response. For multi-response streaming, we need to build a new one

Question is whether we want to make this RPC an awaitable funciton.

Parameters:
  • ttl – The time to live for the handler. If the handler is not called within the time it gets removed from the handler list.

  • event (ServerRPC) –

Return type:

ClientEvent

async rpc_stream(ws_id, event: ServerEvent | None = None, event_bytes=None)[source]#

This RPC offers multiple responses.

Parameters:

event (ServerEvent | None) –

async close_ws(ws_id)[source]#
Parameters:

proxy (VuerSession) –

The websocket handler for receiving messages from the client.

Parameters:
  • ws (aiohttp.web_ws.WebSocketResponse) – The websocket.

  • request (aiohttp.web_request.Request) – The request (unused).

Returns:

None

add_handler(event_type: str, fn: Callable[[ClientEvent, VuerProxy], None] = None, once: bool = False) Callable[[], None][source]#

Adding event handlers to the vuer server.

Parameters:
  • event_type (str) – The event type to handle.

  • fn (Callable[[ClientEvent, VuerProxy], None]) – The function to handle the event.

  • once (bool) – Whether to remove the handler after the first call. This is useful for RPC, which cleans up after itself. The issue is for RPC, the key also needs to match. So we hack it here to use a call specific event_type to enforce the cleanup.

Return type:

Callable[[], None]

# Usage:

As a decorator:

app = Vuer()
@app.add_handler("CAMERA_MOVE")
def on_camera(event: ClientEvent, session: VuerSession):
    print("camera event", event.etype, event.value)

As a function:

app = Vuer()
def on_camera(event: ClientEvent, session: VuerSession):
    print("camera event", event.etype, event.value)

app.add_handler("CAMERA_MOVE", on_camera)
app.run()
_ttl_handler(ttl, cleanup)[source]#
run(kill=None, *args, **kwargs)[source]#
name = 'vuer'#
domain = 'https://vuer.ai'#
port = 8012#
free_port = True#
static_root = '.'#
queue_len = 100#
cors = 'https://vuer.ai,https://dash.ml,http://localhost:8000,http://127.0.0.1:8000,*'#
queries = {}#
cert = None#
key = None#
ca_cert = None#
client_root = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/vuer-py/checkouts/v0.0.29-rc9/vuer/client_build')#
device = 'cuda'#
WEBSOCKET_MAX_SIZE = 268435456#
host = 'localhost'#
class vuer.VuerSession[source]#

Bases: object

property socket#

Getter for the websocket object.

this is useful for closing the socket session from the client side.

Example Usage:

@app.spawn(start=True):
async def main(session: VuerSession):
    print("doing something...")
    await sleep(1.0)

    print("I am done! closing the socket.")
    session.socket.close()
async grab_render(ttl=2.0, **kwargs) ClientEvent[source]#

Grab a render from the client.

Parameters:
  • quality – The quality of the render. 0.0 - 1.0

  • subsample – The subsample of the render.

  • ttl – The time to live for the handler. If the handler is not called within the time it gets removed from the handler list.

Return type:

ClientEvent

property set: At#

Used exclusively to set the scene.

the @SET operator is responsible for setting the root node of the scene.

Examples:

proxy @ Set(Scene(children=[…]))

or

app.set @ Scene(children=[…])

property update: At#

Used to update existing elements. NOOP if an element does not exist.

Supports passing in a list of elements. (Thank God I implemented this… so handy! - Ge)

Example Usage:

app.update @ [element1, element2, ...]
property add: At#

Used to add elements to a specific parent.

Requires a parentKey, or treats the Scene root node as the default parent.

Example Usage:

app.add(element1, element2, ..., to=parentKey.)

or using the Scene root node as the default parent:

app.add @ element1
property upsert: At#

Upsert elements to a specific parent.

Requires a parentKey, or treats the Scene root node as the default parent.

Example Usage:

app.upsert(element1, element2, ..., to=parentKey.)

or using the Scene root node as the default parent:

app.upsert @ element1
property remove: At#

Remove elements by keys.

Example Usage:

app.remove @ ["key1", "key2", ...]

or a single key:

app.remove @ "key1"
popleft()[source]#
pop()[source]#
clear()[source]#

clears all client messages

stream()[source]#