Building Internal Dashboards in Pure Python with Reflex
Reflex lets Python developers build full-stack web apps without writing JavaScript. This walkthrough covers its state-event model, a 30-line todo example, and the trade-offs of going Python-only for UI.
26 May 2026, 06:24 UTC

The Problem with Context Switching
You're a Python developer asked to build an internal dashboard. Option A: spin up a React project, hunt for tutorials, and maintain two codebases. Option B: reach for a Python wrapper that either forces JavaScript under the hood or feels like a constrained canvas. Neither feels like staying in your lane.
Reflex changes the equation by compiling a pure-Python component tree into a React-style frontend and running a Python backend, so one language covers UI, state, and server logic. Its signature feature--the state-event model--tracks mutations server-side and pushes updates over websockets, eliminating the need to write JavaScript yourself.
The State-and-Event Model
Reflex's core is rx.State. You subclass it, declare typed class variables, and the only place you mutate them is inside event-handler methods. The framework intercepts those mutations, sends the new values over a persistent websocket to the browser, and re-renders only the components that depend on the changed variable. No useState, no setTimeout plumbing--just Python methods that look like regular functions.
Computed Variables and Derived Display
Computed variables, declared with @rx.computed, derive display values from state. They execute server-side whenever any tracked variable changes, so you can keep UI logic declarative without manually syncing values. Treat them as cheap derivations; if the work is expensive, push it into a background event handler instead.
Python Control Flow Doesn't Auto-Run
A surprise for beginners: Python if and for statements run when the app definition executes, not on every render. To conditionally show or repeat UI, you must use rx.cond and rx.foreach. Once you internalize that the framework--not Python's runtime--handles rendering loops, the model clicks into place.
Worked Example: a 30-Line Todo App
Here's a minimal, runnable snippet that demonstrates state, events, and re-render in one flow. Install the pinned version first:
pip install reflex==0.1.0 # pin to the version you verified againstThen scaffold and run:
reflex init my_todo_app # creates a basic project structure
cd my_todo_app
reflex run # starts the dev server at http://localhost:3000Define the state and handler:
import reflex as rx
class State(rx.State):
items: list[str] = []
new_item: str = ''
def add_item(self):
self.items.append(self.new_item)
self.new_item = ''
app = rx.App(state=State)
app.add_page(rx.box(
rx.input(value=State.new_item, on_change=State.new_item.set),
rx.button('Add', on_click=State.add_item),
rx.foreach(State.items, lambda item: rx.text(item)),
), state=State)In the browser, typing into the input and clicking Add appends the text to the list below. Open your browser's developer tools and you'll see a single websocket message carrying the new items list--no manual fetch or setState calls required.
When Reflex Works--and when it doesn't
Reflex is a strong fit for internal tools, admin panels, and data-driven dashboards where a Python-first team wants to ship without hiring frontend specialists. The state sync is per-session, so keeping state lean matters: large lists or high-frequency updates add latency and memory overhead. Bulk data should live in a database; only the UI-relevant snapshot should reside in rx.State.
You'll hit a wall if you need pixel-perfect design control, niche React libraries, or SEO-heavy public pages. The framework's abstraction layer can make custom CSS or third-party JS components awkward, and the websocket model isn't ideal for real-time broadcast to many concurrent users without additional architecture.
After running the todo example, open Chrome DevTools Network WS (websockets). You should see one message per state mutation, carrying the minimal changed data. If you append a 1000-item list and notice a perceptible delay before the UI updates, that's the per-session sync cost in action--keep the state variable focused on what the UI actually displays.
Deployment and Ship It This Week
Reflex apps run locally via the CLI reflex run. For production, you can self-host the generated static frontend alongside your Python backend, or push to managed hosting platforms that support Python runtimes. The framework's reflex build command outputs a Next.js-compatible static bundle and a Python server archive, so you're not locked into a single host.
If you're starting today, the fastest path is: install the pinned version, run reflex init, edit the state and pages to match your use case, and hit reflex run. You'll have a working internal tool by the end of the day, and a deployment path that doesn't require re-learning an entirely new stack.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.