Reflex Architecture
How It Works
You write: Pure Python
|
+-- Frontend (auto-compiled to React/Next.js)
| 60+ UI components
| Real-time state sync via WebSocket
|
+-- Backend (FastAPI under the hood)
State management
Database ORM
API endpoints60+ Built-in Components
import reflex as rx
def dashboard():
return rx.vstack(
rx.heading("AI Dashboard"),
rx.input(placeholder="Search...", on_change=State.set_query),
rx.data_table(data=State.results, columns=["Name", "Score"]),
rx.recharts.line_chart(
rx.recharts.line(data_key="score"),
data=State.chart_data,
),
rx.button("Export CSV", on_click=State.export),
)Components include: tables, charts, forms, modals, tabs, accordions, menus, drawers, tooltips, progress bars, and more.
State Management
class ChatState(rx.State):
messages: list[dict] = []
input_text: str = ""
loading: bool = False
async def send_message(self):
self.loading = True
yield # Update UI immediately
response = await call_openai(self.input_text)
self.messages.append({"role": "assistant", "content": response})
self.input_text = ""
self.loading = FalseDatabase Integration
class User(rx.Model, table=True):
name: str
email: str
created_at: datetime = datetime.now()
# CRUD operations
with rx.session() as session:
session.add(User(name="Alice", email="alice@example.com"))
session.commit()
users = session.exec(select(User)).all()One-Command Deploy
reflex deploy
# Deploys to Reflex Cloud (or export for self-hosting)
# Self-host export
reflex export
# Generates a Docker-ready production buildFAQ
Q: What is Reflex? A: Reflex is a full-stack Python web framework with 28,200+ GitHub stars. Write frontend and backend in pure Python — it compiles to React/Next.js automatically. 60+ UI components, real-time state sync, and one-command deployment.
Q: How is Reflex different from Streamlit or Gradio? A: Streamlit/Gradio are for quick demos. Reflex is for production web apps — it compiles to real React, supports custom components, database ORM, authentication, multi-page routing, and production deployment. Think "Next.js but in Python."
Q: Is Reflex free? A: Yes, open-source under Apache-2.0. Self-hosting is free. Reflex Cloud (managed hosting) has a free tier.