LogoPyloid
ApiPyloid js

RPC

For PyloidRPC backend, use this rpc from pyloid-js.

For FastAPI or other HTTP backends, use fetch instead.

Frontend

Calling RPC Functions from JavaScript

import { rpc } from 'pyloid-js';

// Call the 'greet' RPC function to receive a greeting.
rpc
  .call('greet', { name: 'Alice' })
  .then((response) => {
    console.log(response); // Outputs "Hello, Alice!"
  })
  .catch((error) => {
    console.error('Error occurred during RPC call:', error);
  });

Backend

All RPC functions must be defined as asynchronous (async) functions and registered with the method() decorator. Additionally, if you add ctx (RPCContext) as the first argument, you can access the current app and window objects.

from pyloid.rpc import PyloidRPC, RPCContext

server = PyloidRPC()

@server.method()
async def greet(name: str):
    return f"Hello, {name}!"

@server.method()
async def create_window(ctx: RPCContext):
    win = ctx.pyloid.create_window(title="Google Window")
    win.load_url("https://www.google.com")
    win.show_and_focus()

On this page