Quickstart¶
Installation¶
Rational Web needs Python 3.11 or newer.
$ python -m pip install rational # core
$ python -m pip install "rational[db]" # + SQLAlchemy / aiosqlite
Your first app¶
Create app.py:
from rational import App, Button, Card, Container, Heading, Input, Page, State, Text
app = App(title="Hello")
@app.page("/")
class Home(Page):
name = State("")
def set_name(self, value: str):
self.name = value
def render(self):
return Container(
Card(
Heading("Hello", level=1),
Input("Your name", on_input=self.set_name),
Text(f"Nice to meet you, {self.name or 'stranger'}."),
),
max_width=560,
)
if __name__ == "__main__":
app.run()
Run it in development mode:
$ python app.py --dev
Open http://127.0.0.1:8000. Edit the file and save: the server restarts and the browser reloads by itself. Errors show the failing line of your code with a hint.
What just happened¶
GET /created aHomepage, rendered it to HTML on the server and compiled only the CSS it uses.Because the page has an event handler, the response also carries a small manifest and
runtime.js(≈4 KiB gzipped). Static pages get neither.Typing sends the (debounced) value to
set_nameover HTTP. The value is validated against thestrannotation,namechanges, and only the components that readnameare re-rendered and patched into the page.
Next steps¶
Components, state and events — props, state, identity and events.
Styling and themes —
Style, themes and responsive design.Services, the API and databases — server operations, the JSON API and databases.
Running and deploying — development, production and deployment options.
The
examples/directory:hello,counter,todos(multi-user CRUD) anddashboard(responsive, no custom CSS).