Reflex — Full-Stack Web Apps in Pure Python
Build reactive web apps without JavaScript. Frontend and backend in one Python codebase. Deploys anywhere. 28K+ GitHub stars.
What it is
Reflex is an open-source Python framework that lets you build full-stack web applications without writing any JavaScript. You define your UI with Python components, handle state with Python classes, and Reflex compiles everything to a React frontend with a FastAPI backend. The framework handles the full stack: routing, state management, database ORM, and deployment.
It targets Python developers who want to build interactive web apps without learning JavaScript, React, or managing separate frontend and backend codebases.
How it saves time or tokens
Reflex eliminates the context-switching between Python and JavaScript that slows down development. AI developers can build dashboards, admin panels, and user-facing apps for their ML models using the same language they use for data science and model training. The component-based architecture means you compose UIs from reusable Python functions, and hot reload shows changes instantly during development.
How to use
- Install and create a project:
pip install reflex
reflex init
reflex run
- Define a component:
import reflex as rx
def index():
return rx.box(
rx.heading('My AI App', size='lg'),
rx.text('Built with Reflex'),
rx.button('Click me', on_click=rx.window_alert('Hello'))
)
app = rx.App()
app.add_page(index)
- Add state management:
class State(rx.State):
count: int = 0
def increment(self):
self.count += 1
def counter():
return rx.box(
rx.text(f'Count: {State.count}'),
rx.button('Add', on_click=State.increment)
)
Example
import reflex as rx
import openai
class ChatState(rx.State):
messages: list[dict] = []
input_text: str = ''
async def send_message(self):
client = openai.OpenAI()
self.messages.append({'role': 'user', 'content': self.input_text})
response = client.chat.completions.create(
model='gpt-4o',
messages=self.messages
)
answer = response.choices[0].message.content
self.messages.append({'role': 'assistant', 'content': answer})
self.input_text = ''
def chat_page():
return rx.box(
rx.foreach(ChatState.messages, lambda m: rx.text(m['content'])),
rx.input(value=ChatState.input_text, on_change=ChatState.set_input_text),
rx.button('Send', on_click=ChatState.send_message)
)
Related on TokRepo
- AI tools for coding -- Developer tools with AI integration
- Featured workflows -- Discover curated developer tools
Common pitfalls
- Reflex compiles to React under the hood. Complex custom components may require understanding React concepts even though you write Python.
- Performance for highly interactive UIs may lag compared to native React because state updates round-trip through the Python backend.
- The ecosystem of third-party components is growing but smaller than React's. Check if the UI components you need are available before starting a large project.
Frequently Asked Questions
No. Reflex is designed so you write everything in Python. The framework compiles your Python component definitions to React and handles the frontend build process automatically. For advanced customization, you can wrap custom React components, but this is optional.
Yes. Reflex provides a built-in deploy command (reflex deploy) that handles hosting. You can also export the app as a static site or deploy the full-stack version to any server that runs Python. Docker deployment is supported for containerized environments.
Reflex includes a built-in ORM based on SQLAlchemy. You define models as Python classes and Reflex handles migrations and queries. It supports SQLite for development and PostgreSQL for production. You can also connect to external databases using any Python database library.
Yes. Reflex is popular among data scientists and ML engineers who want to build model dashboards, experiment tracking UIs, and internal tools. Since you write Python, you can directly import and use ML libraries (scikit-learn, PyTorch, pandas) in your app logic.
Streamlit is simpler for quick data apps and dashboards with a script-based approach. Reflex provides a full web framework with routing, component composition, and production deployment. Choose Streamlit for rapid prototypes and Reflex for production applications that need custom UIs and multi-page navigation.
Citations (3)
- Reflex GitHub Repository— Reflex is an open-source Python framework for full-stack web apps
- Reflex Documentation— Reflex compiles Python to React frontend with FastAPI backend
- Reflex Blog— Python-based web frameworks reduce context switching for data scientists
Related on TokRepo
Source & Thanks
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.