Orientation · Lesson 05 of 05

Call the server with dataRpc and .remote

Compare a server call that returns data with a server call that builds a fragment of the interface.

4:20 · English6 sectionsPrerequisites: The Python/Uvicorn project and the binding/formula concepts from orientation lessons 01–04.
Course contents
WATCH THE LESSON4:20 · English
Download MP4 ↓English captions ↓

Animated recording with released Gramlot 0.3.8: typed Python declarations, scrolling Uvicorn terminal, synchronized browser refreshes and real Data/Source responses. Learning goals and final recap; AI-generated English narration, captions and exact runnable examples included.

Read the transcript / on-screen steps

00:00:00 In this lesson, we will ask Python for a value and display the returned Data.

00:00:05 Then we will ask Python to build a detail panel and return Source.

00:00:09 We will compare a button click with a reactive selection, watching the real requests

00:00:14 in the terminal.

00:00:17 We start from the downloaded project, with a simple Page and one price field.

00:00:21 The data context is demo, and data Setter initializes dot price to one hundred.

00:00:27 The input uses a reactive pointer to that value, just as in lesson two.

00:00:32 Run Uvicorn with automatic reload enabled.

00:00:35 Now open the local address in the browser.

00:00:38 The price appears, but this page does not call any calculation yet.

00:00:43 Add the endpoint import, the button declaration, a result display, and the Python

00:00:48 method.

00:00:55 The endpoint decorator exposes with tax as a method that returns Data.

00:01:00 For this demonstration it multiplies the supplied price by one point two two and

00:01:05 returns a rounded number.

00:01:07 The button declares data RPC, naming that method and dot gross as the result path.

00:01:13 The equals pointer reads the current price when the call runs, without turning every

00:01:18 input edit into a request.

00:01:20 The heading reads dot gross through a normal reactive pointer.

00:01:24 We initialize that result to Not requested yet, so the waiting state is explicit.

00:01:29 Save the file, wait for automatic server reload, then refresh the browser.

00:01:34 The button and result heading are now present, and no calculation has been

00:01:38 requested.

00:01:41 Keep the terminal visible and click Calculate on the server.

00:01:44 The server receives a request, returns one hundred twenty-two, and the heading

00:01:49 displays the new Data value.

00:01:51 Change the price to two hundred without clicking the button.

00:01:54 The result remains one hundred twenty-two, and no new calculation request appears.

00:02:00 Click Calculate on the server again.

00:02:02 The second response is two hundred forty- four, read from the same Data path.

00:02:07 The Python file has not changed, and we have not reloaded the browser.

00:02:13 Now add a product selector, a details container, and a Python source method.

00:02:33 The selection is stored at dot product, starting with lamp.

00:02:37 The details container calls dot remote with product details as the method name.

00:02:42 Its product parameter uses a caret pointer, so a changed selection can request

00:02:46 another fragment.

00:02:48 The source decorator exposes a method that receives a root for building interface

00:02:53 elements.

00:02:53 The lamp branch creates a heading and a stock paragraph, while the other branch

00:02:58 describes the notebook.

00:02:59 This response is Source for the details container, rather than a number written to a

00:03:04 result path.

00:03:05 Save the file, wait for automatic reload, and refresh the browser.

00:03:10 The initial lamp selection loads the Desk lamp panel from Python.

00:03:16 First click Calculate on the server to restore a visible result of one hundred

00:03:21 twenty-two.

00:03:21 Now select Notebook and watch the request in the terminal.

00:03:25 The server returns new Source, and the details panel shows Notebook with twelve in

00:03:30 stock.

00:03:30 The price, calculation button and returned Data remain in place.

00:03:35 Select Desk lamp again.

00:03:36 The same container now shows the lamp heading and three lamps in stock.

00:03:41 Only the remote fragment changed; the Python file and the rest of the page stayed in

00:03:46 place.

00:03:48 We used data RPC to receive a value and store it at a Data path.

00:03:53 We used dot remote to receive Source and populate an interface container.

00:03:57 The sampled price was read on a button click, while the reactive product selection

00:04:02 triggered a new fragment.

00:04:04 These examples need the running Python server; the exposed endpoint and source

00:04:08 methods are part of that server application.

00:04:11 This completes the five orientation lessons; continue with the full course to

00:04:16 develop these ideas step by step.

What we will learn

Request a value with dataRpc, store the response in Data and display it through a pointer. Then request Source with .remote to populate a detail panel. Compare a button click with a reactive product selection.

The video keeps the animated editor, scrolling terminal and live browser used in the previous lessons. Source changes are typed and saved, followed by automatic Uvicorn reload and an explicit browser refresh. The terminal shows the real requests during browser interactions.

Follow the recorded example

Use the orientation examples download and start from stages/05_initial.py. Run uvicorn app:application --reload and open the local address in your browser. The recording uses released Gramlot 0.3.8 and Python adapter 0.2.12.

The successive stages are 05_initial.py, 05_rpc.py and 05_server.py. They contain the exact declarations executed in the video. The initial Page sets demo.price to 100 and binds a Price input to it.

Receive a value with dataRpc

Import endpoint and expose with_tax with @endpoint. This demonstration method multiplies its price argument by 1.22 and returns a rounded number. It accepts the declared keyword argument and **kwargs for additional declaration arguments.

Attach dataRpc("with_tax", result_path=".gross", price="=.price") to the calculation button. The equals pointer samples the price when the call runs. The response is written to demo.gross, and a heading bound to ^.gross displays it.

Initialize .gross to “Not requested yet” so the initial waiting state is visible. After saving and refreshing, click the button: 100 produces 122. Change Price to 200: the existing result remains 122 and no calculation request is sent. Click again to receive 244. The Python file and browser page are unchanged by these live interactions.

Load interface elements with .remote

Import source, initialize .product to lamp and add a selection bound to ^.product. Create a details section and declare details.remote("product_details", product="^.product").

The @source method receives a root argument for building the fragment. Its lamp branch declares a heading and a stock paragraph; the other branch declares the notebook details. This response is Source for the container, rather than a value written to a result_path.

Save, wait for automatic reload and refresh the browser. The initial lamp selection requests and displays the Desk lamp panel. The refresh also restores the initial Price and waiting result because the Page is built again.

Replace the detail panel, preserve the rest

Click Calculate on the server to show 122 again, then select Notebook. The caret pointer makes the product parameter reactive: a new request loads Notebook and “Twelve notebooks in stock.” Select Desk lamp again to load its heading and “Three lamps in stock.”

The Price input, calculation button and returned Data remain in place while the remote container changes. Neither selection edits the Python file or refreshes the whole browser page.

Change one parameter at a time in this demonstration. The documented request rule permits one request in flight per declaration and one waiting trigger; it is not a guarantee that a later change cancels an earlier response.

What we have learned

Choose dataRpc for a value returned into Data. Choose .remote for Source that populates a container. Sampled arguments are read when a call is triggered; reactive arguments can trigger another call. The explicit declarations determine the trigger and where the response goes.

These Python methods require a running server and do not execute in standalone HTML. They are explicitly exposed methods; application authentication, authorization, errors and request timing are covered in the full course. Continue there after these five orientation lessons.

Your turn

Try it yourself

  1. Start with the Price input, add the endpoint and dataRpc, and verify 100 → 122.
  2. Change Price to 200 without clicking; explain why the result remains 122, then click to obtain 244.
  3. Add the remote product panel and switch between Notebook and Desk lamp while keeping a calculation result visible.
  4. Identify which response enters Data and which supplies Source, then continue with the full course.

Check your understanding

Which operation should you choose for a calculated number, and which for a server-built detail panel?

Show the answer and expected result

Use dataRpc when the server returns a value to put in Data. Use .remote when the server builds Source for a container. Existing bindings can then use the returned value or the declarations in the mounted fragment.

Working examples and reference