ReactPy: Build ReactJS Interfaces in Pure Python

ReactPy Django is a library for building user interfaces in Python without Javascript. ReactPy interfaces are made from components which look and behave similar to those found in ReactJS.

Using our Django Template Tag, you can insert dynamically rendered Python components into your Django templates. Just like ReactJS, you use events and hooks to perform a variety of event-driven re-renders without ever reloading the page.

At a Glance

my_app/components.py

You will need a file to define your ReactPy components. We recommend creating a components.py file within your chosen Django app to start out. Within this file, we will create a simple hello_world component.

from reactpy import component, html

@component
def hello_world(recipient: str):
    return html.h1(f"Hello {recipient}!")

my_app/templates/my-template.html

In your Django app’s HTML template, you can now embed your ReactPy component using the component template tag. Within this tag, you will need to type in your dotted path to the component function as the first argument.

Additionally, you can pass in args and kwargs into your component function. For example, after reading the code below, pay attention to how the function definition for hello_world (in the previous example) accepts a recipient argument.

{% load reactpy %}
<!DOCTYPE html>
<html>
  <body>
    {% component "example_project.my_app.components.hello_world" recipient="World" %}
  </body>
</html>
1 Like

Hi there,

The package looks neat. But do you guys have a live example of this package ( the site mentioned in the docs seems broken )

The live examples in ReactPy core have been broken for a few days as a consequence of our rename from idom to reactpy.