ReactPy is the React for Python

For building rich user interfaces we use React, in this article, we will discuss a new Python library ReactPy to build the user interfaces.

The ReactJS library allows developers to create reusable UI components and manage the state of these components efficiently. Similarly, ReactPy is a library for building user interfaces in Python without Javascript. ReactPy interfaces are made using components. So we can easily build web GUI with ReactPy.

To install ReactPy run the following command :

pip install "reactpy[starlette]"

Here starlette is used as the backend. Le’s try a simple example.

from reactpy import component, html, run

def HelloWorld():
    return html.h1("Hello, World!")


Save the above content to file and run it using the below command :


Open the URL in the browser. We can see the “hello world” message.

ReactPy hello world output

So what is a component in ReactPy?

As per the ReactPy documentation, components are normal Python functions and it returns HTML. In order to make a component just add @component decorator to the top of the function. See the below example :

def Title():
    return html.h1("Nolowiz")

The above function title is a ReactPy component.

We can use multiple components to create a complex one see the below code.

from reactpy import component, html, run

def Title(title):
    return html.h1(title)
def Photo():
    return html.img(
            "src": "",
            "style": {"width": "30%"},
def PhotographerName(caption):
    return html.h4(caption)
def PhotoViewer():
    return html.section(
        Title("Photo of the day"),
        PhotographerName("Steven Spassov")


The output of the above code is shown below

ReactPy complex component

ReactPy backends

ReactPy supports the following backend implementations.

To install ReactPy with fastapi backend run the following command.

pip install "reactpy[fastapi]"


In conclusion, ReactPy enables us to easily create better user interfaces in Python. You can read about the new programming language Mojo .