Skip to main content

PythonReact

Did you ever think: "We need a JS library turned into a python module used for console output in stead of rendering a webpage."? No? Well I did. So here it is.

Installation

This package is on pypi.
Installing can be done via pip

Windows:

pip install pythonreact

Mac/ Linux:

pip3 install pythonreact

Usage

If you are familliar with the JS library react this should be very easy.

Component

Everything is a component.
To create a new component, make a class that inherits from PythonReact.Component

import PythonReact


class MyComponent(PythonReact.Component):
    pass

Hello python react

To show something in the console we will add a render function. This render function should return a list of printable items or other Components.

import PythonReact


class MyComponent(PythonReact.Component):
    def render(self) -> list:
        return [
            "Hello",
            "Python React"
        ]

Let's make an object of that type:

# snip
my_comp = MyComponent()

It will automatically start printing now. And it will render your function.

State

If you have used React you know about state.

To create a state add it to the __init__ of your component. And then simply call the variables in your render function.

import PythonReact


class MyComponent(PythonReact.Component):
    def __init__(self):
        self.state = {
            "name": "Donkere",
        }

        super().__init__()

    def render(self) -> list:
        return [
            f"Hello {self.state['name']}!",
        ]


my_comp = MyComponent()

>>>
Hello Donkere!

Set state

Just as in React there is a set state function.

import PythonReact


class MyComponent(PythonReact.Component):
    def __init__(self):
        self.state = {
            "name": "Donkere",
        }

        super().__init__()

    def render(self) -> list:
        return [
            f"Hello {self.state['name']}!",
        ]


my_comp = MyComponent()
my_comp.set_state({"name": "New Name"})

>>>
Hello Donkere!
# Screen get's cleared
Hello New Name!

Release files for pythonreact 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pythonreact 0.2
File Size Uploaded
pythonreact-0.2.tar.gz 14.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pythonreact 0.2
File Interpreter ABI Platform
pythonreact-0.2-py3-none-any.whl Python 3 none any Details

Total release size: 30.0 kB

Release files / pythonreact-0.2.tar.gz

Download URL pythonreact-0.2.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c013e79de30039c4df3a3d44e3c12cd0b2637693fd6c676714b1025efedba253
BLAKE2b-256 checksum
How to use checksums
6d43763b8b72482b311613f50aef50c877247e1aacd26c2c08a246ba447a2dcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.6

Release files / pythonreact-0.2-py3-none-any.whl

Download URL pythonreact-0.2-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7806b7eaa7d7111bb2073635b6071f1bd2faf5e0179dd01619e333a942bbdf38
BLAKE2b-256 checksum
How to use checksums
4ac452020f7043f3c4bea5981497adbd066357353d732a89309ce05291bce83e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.6

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page