GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - doconix/pyreact: Transcrypt (transpiled Python) + ReactJS

This repository was archived by the owner on Oct 5, 2026. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

14 Commits
14 Commits

Folders and files

NameName
Last commit message
Last commit date
dist
dist
 
 
src
src
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
build.py
build.py
 
 
package.json
package.json
 
 
readme.md
readme.md
 
 
screenshot.png
screenshot.png
 
 
scripts
scripts
 
 

Repository files navigation

Inactive

This project was a demo/experiment of using Transcrypt with React. It is not being updated and should not be considered active.

Welcome to PyReact

React is a browser-based, client library that "makes it painless to create interactive UIs".

Using this normally means you're coding in Javascript, but you want to instead code in our favorite language, Python, amirite? Fortunately for you, Transcrypt places Python (transpiled Python) right smack in the browser. But then the other shoe drops:

  • Extending JS classes (React.Component) in Python isn't an obvious thing to do.
  • Using JSX in Python can be maddening because it means transpiling a transpile.
  • Using Python with Transcrypt works pretty well, but it has some gotchas.

This is where PyReact and this demo come in. PyReact = React + Transcrypt

The Finished Product

This demo project makes the following page. The clock upates every 200 ms and is clickable (but not in this png image :).

Screenshot

This demo project shows how to:

  • extend the JS React.Component class
  • use .state from Python
  • create components with createElement() as well as with JSX
  • set event handlers and callback functions
  • send props to child components
  • use various JS things like Date() and a timer
  • use various Python things like list comprehensions and the random module

Installation

Since this is a demo, the goal is as few dependencies as possible:

  • Download/clone the project.
  • pip3 install transcrypt livereload
  • npm init (accept the defaults)
  • npm install jsx-transform
  • cd src
  • python3 dev_server.py
  • Open http://localhost:8000/ in your browser.

PyReact also works well within a full React project (npm, webpack, etc.), but that's beyond the scope of this document.

Structure

The project structure is as follows:

src/
    index.html                      # bootstraps React in the <script> elements
    dev_server.py                   # automatically runs transcrypt when needed (optional)
    scripts/
        index.py                    # Main component of the app
        clock.py                    # Clock components
        pyreact.py                  # PyReact superclasses (extend from these)
    scripts/__javascript__/         # Transcrypt puts the transpiled scripts here
    script-ext/                     # React sources from reactjs.org (required)
    styles/                         # Plain old css

When you create new transcrypt scripts, place them in scripts/.

Where to Start

Start by reading src/scripts/index.py and src/scripts/clock.py. These are the primary files of the project.

Status and Future

PyReact isn't that big - it's just a small superclass for your Python objects, a JSX transformer, and most importantly, an example of how it's done. Transcrypt comes with many examples, but the goal of PyReact is to show one way to set up a full project. It works well.

Future? Who knows. Right now I'm just putting this out there in hopes that it will be useful to others.

Best wishes,

Conan Albrecht https://github.com/doconix/

November, 2017

About

Transcrypt (transpiled Python) + ReactJS

Resources

Readme
Apache-2.0 license
Activity

Stars

50 stars

Watchers

9 watching

Forks

3 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.