WebRust: Python-Inspired Rust for Interactive Web Applications
Links: Documentation | Examples | Crates.io
Abstract
WebRust bridges Python’s ergonomics with Rust’s performance to build interactive, browser‑based apps without writing HTML/CSS/JS. Write expressive, Python‑like Rust that compiles to a single native binary; WebRust launches a local server and streams rich UI (text, tables, charts, turtle graphics, LaTeX) to your browser.
Version 1.9.0 adds customizable browser background colors via #[gui(... !bg)], restores radar chart tooltips, and ships comprehensive optimizations across the proc‑macro pipeline and GUI runtime. The framework unifies data manipulation, visualization, and interactivity in a single, type‑safe environment.
Table of Contents
- Introduction
- What's New in 1.9.0
- Motivation
- Architecture
- Installation
- Core Features
- Usage Examples
- Performance
- Contributing
- License
Introduction
Overview
WebRust lets you write Python‑like Rust that runs natively with full type safety, while automatically generating a rich web UI. No frontend stack, no deployment boilerplate — just Rust.
Key Characteristics
- 🐍 Python-Inspired Syntax: ranges (
.to()), filters (.when()), transforms (.then()) - 🎨 Rich Text Rendering: inline colors, borders, layout helpers, and LaTeX
- 📊 Interactive Visualizations: 12+ chart types powered by ECharts with full tooltip support
- 🗄️ High-Performance SQL (optional): DuckDB integration with streaming results
- 🐢 Turtle Graphics: object-oriented drawing with animation and easing
- 🎯 Zero Configuration: automatic browser UI; no HTML/CSS/JS required
- ⚡ Native Performance: Rust compile-time safety and speed
- 🎭 Full Theme Control: viewport background theming via
#[gui(... !bg)]
Design Philosophy
- Ergonomics First — write naturally
- Type Safety Always — lean on Rust guarantees
- Visual by Default — UI is automatic
- Performance Matters — zero-copy and SIMD where it counts
What's New in 1.9.0
🎨 Major Visual Enhancements
1) Browser Background Color Support
The #[gui] attribute now supports full browser viewport background customization via the !color token.
// Dark theme, full window background
Supported formats: named colors (!navy), hex !#fff/!#1a1a2e, rgb(...)/rgba(...).
Applied consistently to <body>, the main container, and chart areas (transparent by default). Zero runtime overhead.
2) Radar Chart Tooltips
ECharts radar charts now show tooltips on hover (single or multi‑series). Values are formatted and color‑coded.
⚡ Optimizations & Polish
- Proc‑macro engine uses SIMD scanning (
memchr/memmem) and SmallVec for fewer allocations parking_lot+RwLock(default feature) for fast concurrent reads- Layout spacing tightened for pie/doughnut/radar/gauge headings
- Minor fixes in table pagination/merge
Motivation
The Problem
Modern visualization pipelines juggle many tools:
SQL → Python (pandas) → Plotly → Flask → Deploy
↓ ↓ ↓
type safety lost frontend code infra cost
The WebRust Solution
Rust (WebRust) → Browser (automatic)
type safety + performance + zero frontend
One language, one binary, instant UI.
Architecture
System Overview
User Rust code → Proc-macros (SIMD scanning) → Optimized Rust → Native binary
│ │
└───────────── WebRust runtime ───────────────┘
│ │
tiny_http Browser
/api/* main.js + modules (table.js, turtle.js)
Theme Injection (v1.9.0)
#[gui(Font Size TextColor !Background)]
│
StyleConfig { bg, color, font, size }
│
Injected to browser (body + container)
Installation
Base
[]
= "1.9.0"
With SQL (DuckDB)
= { = "1.9.0", = ["sql"] }
With Compact Strings
= { = "1.9.0", = ["compact"] }
Locking
rwlock (using parking_lot) is enabled by default. To revert to Mutex:
= { = "1.9.0", = false }
Core Features
- Python‑like ranges and comprehensions
- Inline rich text + LaTeX with
$(...) - Interactive tables (sort/filter/paginate/merge/pivot)
- Charts (bar/line/pie/doughnut/scatter/radar/gauge/funnel/...)
- Turtle graphics with easing
- Optional SQL via DuckDB
- Auto‑launched browser UI
Usage Examples
Note:
chart.rsno longer provides.title(...). Use text elements for headings.
1) Interactive Table
use *;
2) Radar Chart (with Tooltips, No .title())
use *;
3) Custom Theme (Viewport Background)
use *;
4) Multi-Panel Layout with Charts (No .title())
use *;
Performance
Compilation (v1.9.0)
| Configuration | First Build | Incremental | Size |
|---|---|---|---|
| Default | ~28s | <4s | ~2MB |
| With SQL | ~2m50s | <9s | ~15MB |
| With compact feature | ~30s | <4s | ~2.1MB |
Runtime
- SIMD f‑string/LaTeX scanning (
memchr/memmem) - Number formatting via
itoa/ryu - Fewer allocations with
SmallVecand pre‑sized buffers parking_lot::RwLock(default) for concurrent reads
Contributing
- Issues: https://github.com/gerarddubard/webrust/issues
- Discussions: https://github.com/gerarddubard/webrust/discussions
PRs welcome: examples, docs, optimizations, features.
License
MIT — see LICENSE.