Orientation · Lesson 01 of 05

Install Gramlot and create Hello world

Install and run Gramlot with Python and Uvicorn, create a welcome page, then see the Node.js and serverless alternatives.

4:26 · English10 sectionsPrerequisites: Python 3.11 or newer, a terminal, a text editor and a browser.
Course contents
WATCH THE LESSON4:26 · English
Download MP4 ↓English captions ↓

Recorded with released Gramlot 0.3.8. Commands and actual output share a scrolling terminal history, with separate Python, Node and build sessions. Uvicorn runs with --reload: saving restarts the application automatically, then the browser is refreshed explicitly. Learning goals give way to the actual browser; animated transitions mark opening and reload. AI-generated English narration; captions and runnable examples included.

Read the transcript / on-screen steps

00:00:00 In this lesson, we will install Gramlot with Python, create a Hello world page, and

00:00:05 run it with Uvicorn.

00:00:07 We will see exactly when saving the source, automatic server reload and refreshing

00:00:12 the browser change the result.

00:00:14 Then we will try the same welcome page with Node, and open a standalone HTML file

00:00:20 directly in the browser.

00:00:22 The learning goals are on the right.

00:00:24 When we open our page, the browser will take their place.

00:00:29 Start in a new project folder.

00:00:31 Type python three dash m venv dot venv, then press Enter to create the virtual

00:00:36 environment.

00:00:37 Activate that environment with the source command.

00:00:41 Now install Gramlot and its Uvicorn adapter with pip.

00:00:44 We are using the published versions shown in the command.

00:00:48 Installation makes the packages available; it does not open a web page.

00:00:52 The learning goals stay on the right until we are ready to open the browser.

00:00:58 Create the project with gramlot uvicorn new hello.

00:01:01 Enter the hello folder.

00:01:03 Open pages slash index dot py in the editor and replace the sample with this small

00:01:09 Page.

00:01:09 We import Page as BasePage and define our own Page class.

00:01:14 Its main method receives root, and root dot h one declares the Hello world heading.

00:01:19 Click Save file to write the source to disk.

00:01:22 We have saved the Page, but have not started its server or opened it in the browser.

00:01:28 Run Uvicorn with app colon application and dash dash reload.

00:01:33 Wait for the terminal to confirm that the server is running.

00:01:36 Now enter its local address in the browser address field and press Open.

00:01:41 Only now does Hello world appear.

00:01:43 The sequence matters: save the Page, start the server, then ask the browser to open

00:01:49 the address.

00:01:49 The two panels show the command and its actual result.

00:01:55 Change the heading in the editor to Welcome to Gramlot.

00:01:58 The browser still shows Hello world: editing text has not changed the running page.

00:02:03 Click Save file.

00:02:05 The browser still shows the previous result.

00:02:07 In the terminal, Uvicorn detects the saved file and restarts the application

00:02:12 automatically.

00:02:13 Wait for application startup to complete, then click Reload in the browser.

00:02:18 The heading now says Welcome to Gramlot.

00:02:20 The reload option watches the source files; after saving, we only need to refresh

00:02:25 the browser.

00:02:28 Now let's run the welcome page with Node.

00:02:31 In a separate folder, use the official create command to generate a page project.

00:02:36 Enter that project and run npm install.

00:02:42 The editor shows the JavaScript Page: it still declares the heading with root dot h

00:02:47 one.

00:02:48 Save this source before starting the server.

00:02:50 Run npm start and wait for the local address printed in the terminal.

00:02:55 Enter that address in the browser and press Open.

00:02:58 The welcome page is now served by Node.

00:03:01 Notice that the previous result was not replaced until we opened the new address.

00:03:16 Open a second terminal tab in the JavaScript project, leaving the Node server

00:03:21 running.

00:03:22 Run npm run build in the JavaScript project.

00:03:25 The terminal reports the generated index dot html file.

00:03:30 Stop the Node server: we will open the file itself.

00:03:33 Put the file address ending in index dot html into the browser address field.

00:03:38 Click Open HTML file.

00:03:40 The address now starts with file, instead of http, and the welcome page appears from

00:03:46 that local file.

00:03:47 Reload it with the browser offline: it still works.

00:03:50 This simple standalone build needs no running Python or Node server.

00:04:01 We installed Gramlot, wrote and saved a Page, started Uvicorn and opened the result

00:04:06 in the browser.

00:04:08 We changed the heading and saved the source, watched Uvicorn reload automatically,

00:04:13 and refreshed the browser.

00:04:14 Finally, we ran the JavaScript Page with Node and opened its generated HTML file

00:04:20 directly, offline.

00:04:22 Next, we will connect inputs and the page to Data.

What we will learn

Install Gramlot with Python, write a Hello world Page and run it with Uvicorn. Follow the sequence from saving the source to starting the server and opening the browser, then change the greeting and see when the result updates.

Finally, run the JavaScript Page with Node and open its generated HTML file directly in the browser. The learning goals appear on the right while we work in a large terminal on the left. When we open the page, the browser replaces those goals. Animated transitions mark opening and reloading.

Follow the recorded example

The runnable examples download includes the exact Python and JavaScript Pages. Recordings use Gramlot 0.3.8, Python adapter 0.2.12 and JavaScript adapters 0.2.15. The recording editor and browser controls are presentation tools; they are not part of the Page source.

Install and create the Python project

Start in an empty working folder with Python 3.11 or newer, a terminal, a text editor and a browser. Create a virtual environment, activate it, install the packages and generate the project. These commands are for macOS or Linux; Windows uses its own virtual-environment activation command.

The Gramlot CLI creates the project. Uvicorn will start its server after we have saved our Page. Installing packages or creating the project does not open a browser page.

Terminal · Python / Uvicorn
python3 -m venv .venv
source .venv/bin/activate
python -m pip install "gramlot==0.3.8" "gramlot-py-server[uvicorn]==0.2.12"
gramlot uvicorn new hello
cd hello

Write and save Hello world

Open pages/index.py in your text editor and replace its sample with this small Page. Save the file. Keep the generated host files and project configuration.

The main method receives root, the starting point for declaring the interface. A heading is enough for this first lesson; bindings and layouts come next. The browser remains empty because we have not opened the application yet.

pages/index.py
from gramlot import Page as BasePage


class Page(BasePage):
    title = "Welcome to Gramlot"

    def main(self, root):
        root.h1("Hello world")

Start the server, then open the browser

From the hello folder, run the command below. Wait for Uvicorn to report that it is running, then open http://127.0.0.1:8000/ in your browser. Only now should Hello world appear. The --reload option watches your Python files and automatically restarts the application when you save changes.

Terminal · start the application
uvicorn app:application --reload

Change, save and refresh the browser

Change Hello world to Welcome to Gramlot in pages/index.py. The browser still shows the previous result while you edit and after you save.

After saving, watch the terminal: Uvicorn detects the changed file and restarts the application automatically. Wait for application startup to complete, then click Reload in the browser. The heading now changes. Keep Uvicorn running throughout: you do not need to stop it or type its command again. The --reload option restarts the server; it does not automatically refresh the browser.

Try Node.js

In a separate folder, create the JavaScript project and install its dependencies. You need Node.js and npm for this alternative. Open index.js, use the JavaScript Page below and save it before starting the server.

Terminal · create the JavaScript project
npm create --yes @gramlot@0.2.15 -- page welcome
cd welcome
npm install

Save the JavaScript Page and start Node

Save this source in index.js. Run npm start, wait for the local address printed by the server and open http://127.0.0.1:8080/ in the browser. The previous page remains visible until you open the new address.

index.js
import {Page as BasePage} from '@gramlot/gramlot/page';

export class Page extends BasePage {
    static title = 'Welcome to Gramlot';

    main(root) {
        root.h1('Welcome to Gramlot');
    }
}

Build HTML and open the file

Open a second terminal tab in the same JavaScript project and run npm run build. The output identifies the generated index.html. Switch back to the Node terminal and stop the server with Ctrl+C.

Open that index.html file with your browser, for example through its Open File command. The address starts with file:// rather than http://. The recording keeps the terminal visible while entering the file address and clicking Open HTML file.

This simple generated page also reloads offline without a Python or Node server. This does not make server-dependent features or external resources available offline.

Terminal · generate the HTML file
npm run build

What we have learned

We installed Gramlot, created and saved a Page, started Uvicorn and opened its address. We changed the greeting by saving the file, letting Uvicorn reload automatically, and refreshing the browser. We also ran the JavaScript Page with Node and opened its standalone HTML file offline.

Keep the Python project: the next lesson connects inputs and the page to Data.

Your turn

Try it yourself

  1. Create and launch the hello project with Python/Uvicorn.
  2. Show Hello world, then change and save the greeting in the Python file. Wait for automatic server reload and refresh the browser.
  3. Keep the project for lesson 02. Try the Node.js or serverless route if it matches your environment.

Check your understanding

With Uvicorn running with --reload, what do you do after changing the Python greeting?

Show the answer and expected result

Save the file, wait for Uvicorn to finish reloading the application, then refresh the browser. Leave the server running; there is no need to stop and launch it again.

Working examples and reference