Giter Club home page Giter Club logo

pyx-react's Introduction

PyX Framework

Introduction

PyX Framework is a framework that enables Python objects to be easily rendered on a web server. This allows Python developers to integrate their backend logic with web interfaces seamlessly.

Features

  • Automatic Rendering: Implement __render__(self, user) in Python objects to display them as web components.
  • Event Handling: Easily handle user interactions with Python methods.
  • Dynamic Updates: Changes in Python object states are automatically reflected in the web interface.

Installation

To install PyX Framework, use pip:

pip install pyx-react

or clone this repository:

git clone https://github.com/cykim8811/pyx-react.git
cd pyx-react
python setup.py install

To install vscode extension, search for pyx-react in vscode extension marketplace.

Usage

Here's a simple example of how to use PyX Framework:

  • Create a .pyx file
from pyx import createElement, App

class Counter:
    def __init__(self):
        self.count = 8

    def increment(self, e):
        if e.button == 0:
            self.count += 1

    def __render__(self, user):
        return (
            <div>
                <div>count: {self.count}</div>
                <button onClick={self.increment}>Increment</button>
            </div>
        )


app = App(Counter())
app.run(host='0.0.0.0', port=8080)
  • Run pyx transpiler
pyx file.pyx
  • Run transpiled .py file
python3 file.x.py

Result

result

Documentation

No documentation is available at the moment. Please refer to the examples for more information.

Contributing

Contributions to PyX Framework are welcome!

License

PyX Framework is licensed under MIT License.

Contact

[email protected]

pyx-react's People

Contributors

cykim8811 avatar

Stargazers

Aviv Azran avatar  avatar Su-Yong avatar  avatar Tofik Denianto avatar

Watchers

 avatar

pyx-react's Issues

Fix function preloading cache detection

In case of function defined inside render, ex)

...
    def __render__(self, user):
        async def ftn(e):
            v = await e.attr
        return <div onEvent={ftn}></div>
...

Cache and use old function on the frontend if the ftn name is equal.

Or, use same preloading attributes for all functions in each render function

Add e.preventDefault(), e.stopPropagation()

Add e.preventDefault(), e.stopPropagation() to function calling.
Add return false; when creating event handler at frontend
and if the e.preventDefault() or e.stopPropagation() has not been called, dispatch event.

Add hot reloading

Add pyx watch script to hot-reload application

  • Fix user connection to new server

Fix failing to hit cache on re-generating function on re-rendering

def __render__(self, user):
    async def onMouseMove(e):
        cx, cy = await e.clientX, await e.clientY
        self.cursors[user.sid].onMove(cx, cy)
        ...

    return createElement('div', {
        'onMouseMove': onMouseMove,
        ...

The above code can't keep cache to render..onMouseMove, since the repr value is always different.

Support JSX-like syntax

    # JSX-like syntax (Not supported yet)
    def __render__(self, user):
        return (
            <div>
                <div>count: {self.count}</div>
                <button onClick={self.increment}>Increment</button>
            </div>
        )

Remove App class

Instead of using App class and onConnect etc, use Hooks

def __render__(self, app):
    # app.users
    # app.req.user
    # app.req.query

Instead of class MyApp(pyx.App): ...,

from pyx import useUser, useEffect, useState
class MyApp:
    def __render__(self, app):
        @useUser
        def onConnect(user):
            print(f"User {user.sid} connected")
            def onDisconnect(user):
                print(f"User {user.sid} disconnected")
            return onDisconnect

        @useEffect(self.state1, self.state2)
        def onStateChange():
            print("State Changed")
            def clenup():
                print("Cleanup")
            return cleanup

        state, setState = useState("Initial Value")

        return <p>Element here</p> 

Optimize argument passing

When calling function from frontend, pass frequently used arguments with the function call.
Add cache to JSObject

Consider changing function for getting attribute from jsobject to sync function (without await)

Add title

class App(pyx.App):
    def __init__(self):
        super(App, self).__init__(title="Pyx Example")

Fix input issue

<input>
<textarea>

does not work as expected, and have lots of delay.

Also solve issues for composable characters(such as Korean ㄱ+ㅏ+ㅁ=감)

Change render implementation

Currently fetching used attributes at calling render
Give control to render

...
    def render(renderable):
        register_getattr()
        renderable.__render__(user)
        handle_getattrs()
...

to

...
    def render(renderable):
        ctx.rendering = renderable
        renderable.__render__(user)
...

KeyError on test_0

Test 0 works, but it raises error at decrementRefCount

...
  File "/root/repos/pyx-react/src/pyx/app.py", line 137, in update
    self.decrementRefCount(child)
  File "/root/repos/pyx-react/src/pyx/app.py", line 93, in decrementRefCount
    self.decrementRefCount(child)
  File "/root/repos/pyx-react/src/pyx/app.py", line 90, in decrementRefCount
    self.resources[resourceId].refCount -= 1
    ~~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: '71Ffwu3434CLsHi75akMlj'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.