H2O Wave Documentation

repository·main·Indexed 26 days ago

https://github.com/h2oai/wave

A software stack for building low-latency, realtime, browser-based applications and dashboards using only Python or R, without requiring HTML, CSS, or JavaScript. Includes H2O Lightwave for FastAPI integration and custom HTML embedding, Wavegen for component generation, and a dedicated IntelliJ plugin for enhanced development.

Tokens
128.6K
Snippets
402
Records
654
Agent score
87%

What's inside H2O Wave

  1. Overview of H2O Wave

    main
    H2O Wave is a software stack designed for building beautiful, low-latency, realtime, browser-based applications and dashboards. It allows developers to build and deploy realtime analytics entirely in Python or R, eliminating the need for HTML, JavaScript, or CSS. It is particularly effective at capturing information from multiple sources and broadcasting it live over the web.
  2. Understand the H2O Wave repository structure

    main

    The repository is organized into the following key directories:

    • cmd: Go executables.
    • data: Contains data created by a Wave-app (e.g., file uploads).
    • py: Python package.
    • r: R package.
    • tools/wavegen: TypeScript to Python/R code-generator.
    • ui: TypeScript + React sources (primarily built using Fluent UI).
      • ui/config: Webpack configuration.
      • ui/eslint: Custom ESLint rules for ts and tsx files. (Note: If you change linter.js, you must run npm ci for changes to take effect).
    • website: Documentation sources.
  3. Understand the H2O Wave mental model

    main

    H2O Wave uses a retained-mode graphics model where the Wave server acts as a hub between the browser and your Python applications. To build applications, follow this workflow:

    1. Your instance holds a collection of pages.
    2. To change a page, grab a reference to the page, modify its content using the SDK, and then save it.

    Once q.page.save() is called, changes are broadcasted to all connected clients in real-time without requiring a browser reload.

  4. Use WaveDB for lightweight data storage

    main

    WaveDB is a lightweight, SQLite-based companion database that provides a HTTP interface for Wave applications.

    Key Features:

    • Self-contained: A single, zero-dependency executable.
    • SQLite Bundled: Includes SQLite 3.35.5 with JSON1, RTREE, FTS5, GEOPOLY, STAT4, and SOUNDEX.
    • Async Access: The h2o-wave package includes non-blocking async functions to interact with WaveDB.

    Refer to the WaveDB Guide for installation and the WaveDB API documentation for usage details.

  5. Understand the H2O Wave Architecture

    main

    H2O Wave is a three-tier software stack designed for building low-latency, realtime, browser-based applications entirely in Python. It functions as both a programming framework and a programmable content server.

    The architecture consists of:

    1. Wave Server: A static binary executable (~10MB) that acts as an in-memory realtime database, HTTP web server, and proxy. It stores site content, transmits content changes to browsers, and relays browser events to apps.
    2. Language Driver: The h2o-wave PyPI package used by Python programs to manage content on the server via an idiomatic API.
    3. Browser-based Client: The user interface that renders content and transmits user actions (events) back to the server.

    Key distinction: Unlike typical web frameworks, the Wave server retains content. A Python process (script) can update content and exit, and the server will continue serving that content to new users.

  6. Understand the H2O Wave App Server Protocol

    main

    H2O Wave operates using a three-part architecture: the Browser, the Wave Server, and the App Server.

    • Browser ↔ Wave Server: Communication occurs via WebSockets.
    • Wave Server ↔ App Server: Communication occurs via HTTP requests.

    An App Server is essentially an HTTP server that must implement a single HTTP handler listening for POST requests at the root path (/).

  7. Understand Wave Scripts vs. Wave Apps

    main

    Wave scripts are the simplest way to publish live web content, such as dashboards, visualizations, news tickers, or performance monitoring data.

    Key distinction:

    • Wave Scripts: Used for publishing content only. They are not interactive and cannot handle user interactions.
    • Wave Apps: Designed for interactivity and handling user inputs/interactions.
  8. Use WaveDB for lightweight SQL storage

    main

    WaveDB is a lightweight, self-contained companion database for Wave apps based on SQLite. It acts as a thin HTTP-server wrapper around SQLite, allowing you to access your databases over a network.

    Key features:

    • Based on SQLite 3.35.5.
    • Includes extensions: JSON1, RTREE, FTS5, GEOPOLY, STAT4, and SOUNDEX.
    • Zero-dependency, self-contained executable.
    • Accessible via non-blocking async functions provided in the h2o-wave package.
  9. Update a single page from multiple sources

    main
    Multiple Wave scripts running on different devices can update the same Wave page simultaneously. This allows you to aggregate content from various sources (e.g., different network systems or different stock exchanges) onto a single unified dashboard.
  10. Use Flex Layout for responsive designs

    main

    Wave provides a flex layout system to build responsive user interfaces that adapt to different screen sizes. To use it, attach a layout to your page's meta card using ui.layout().

    A layout requires a breakpoint and a set of zones. Zones can be nested and have a direction (ui.ZoneDirection.ROW or ui.ZoneDirection.COLUMN).

    q.page['meta'] = ui.meta_card(box='', layouts=[
        ui.layout(
            breakpoint='xl',
            width='1200px',
            zones=[
                ui.zone('header'),
                ui.zone('body', direction=ui.ZoneDirection.ROW, zones=[
                    ui.zone('content', size='75%'),
                    ui.zone('sidebar', size='25%'),
                ]),
                ui.zone('footer'),
            ]
        )
    ])
  11. Deploy Wave apps using ASGI servers

    main

    Wave apps are ASGI-compatible. While you can use wave run your_app --no-reload for simple deployments, for production it is highly recommended to run the Wave server (waved) separately from the Wave app. You can run Wave apps using any ASGI server like uvicorn, gunicorn, daphne, or hypercorn.

    To run an app with Uvicorn, append :main to the app filename. For example, if your app is foo.py, use uvicorn foo:main.