• Stars
    star
    113
  • Rank 308,421 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A React-inspired declarative library for building DOM-based user interfaces in pure Python.

flybywire is an OS-agnostic, declarative UI library for Python based on Sofi and inspired by Facebook's React framework. The main goal behind this experiment was to build elegant, interactive UIs in pure Python while leveraging web technologies. Eventually, flybywire will use something like Electron rather than a web browser for greater control over what is rendered.

Build Status PyPI version

Overview

The interface is built using a virtual-DOM layer and sent to the browser over WebSockets. All the view logic is written in pure Python. Instead of providing a set of widgets, flybywire allows components to be defined in a declarative manner out of standard HTML tags and CSS using an easy, readable syntax.

As in React, the view is defined as functions of the state. Any changes to the state automatically triggers a redraw of the entire DOM. flybywire uses the virtual-dom library to update only those parts of the DOM that were actually modified.

Example

This is a really simple example to demonstrate the library in action. It shows simple counter whose value can be controlled by two buttons.

from flybywire.ui import Application, Component
from flybywire.dom import h


def CounterView(count):
    """A simple functional stateless component."""
    return h('h1', str(count))

@Application
class CounterApp(Component):
    def __init__(self):
        """Initialize the application."""
        # super(CounterApp, self).__init__()  # Python 2.7
        super().__init__()
        self.set_initial_state(0)

    def render(self):
        """Renders view given application state."""
        return h('div',
                    [CounterView(count=self.state),
                     h('button', '+', onclick = self.increment),
                     h('button', '-', onclick = self.decrement)]
                )

    def increment(self, e):
        """Increments counter."""
        self.set_state(self.state + 1)

    def decrement(self, e):
        """Decrements counter."""
        self.set_state(self.state - 1)


app = CounterApp()
app.start()

flybywire counter demo The example can also be found in examples/counter.py.

Bugs, features and caveats

  • As of now, there is a system in place for some rudimentary DOM event communications. However, slightly more "advanced" features such as doing "event.preventDefault()" for specific events for example, is not available at present. Ideas for exposing this functionality are welcome! I might possibly add back some of the imperative command framework from Sofi that I had originally removed from the code.

  • Some simple functionality such as focusing a textbox or clearing it after pressing enter cannot be done right now. There might be some simple way of solving this, possibly by injecting some javascript at render-time.

  • The server will shut down as soon you close your browser window. This is because there is no option to reset the applicaton state right now without restarting the program.

  • Opening multiple browser windows also results in some weirdness. This is again caused by the application state being shared by the all clients. However, this may not be an issue in the future once we move to an architecture based on Electron. Once that happens, there will only ever be one client connected to the server and the server lifecycle will be be tied to that of the actual application window.

About the author

Thomas Antony's LinkedIn Profile

More Repositories

1

llamacpp-python

Python bindings for llama.cpp
C++
193
star
2

msl-apollo-entry-guidance

A Python implementation of the Apollo Entry Guidance algorithm used by NASA's MSL spacecraft
Jupyter Notebook
44
star
3

sdc-live-trainer

Live training a neural network to drive Udacity's SDC Simulator
Python
42
star
4

simplepipe

A simple functional pipelining library for Python
Python
37
star
5

chatgpt-term

A terminal interface to ChatGPT
Rust
17
star
6

ud810-intro-computer-vision

My solutions for Udacity's "Introduction to Computer Vision" MOOC
Jupyter Notebook
16
star
7

orbiter-rs

A proof-of-concept for building Orbiter spaceflight simulator addons in Rust
Rust
13
star
8

coursera-robotics-flight

Quiz and assignment solutions for Coursera MOOC - Aerial Robotics
MATLAB
13
star
9

CarND-Projects

All the code from my projects for Udacity's Self Driving Car Engineer NanoDegree
C++
9
star
10

codeigniter-azure

A Codeigniter library that wraps over Microsoft's phpAzure library ( + query caching using CI's caching library )
PHP
8
star
11

CarND-P04-Advanced-Lane-Lines

Udacity CarND - Project 04 - Advanced Lane Lines
Jupyter Notebook
7
star
12

surveyor-sim

Web demo at: https://www.thomasantony.com/surveyor/
Rust
3
star
13

beluga

Trajectory optimization framework that uses indirect methods
Python
3
star
14

surveyor

An orbiter addon that demonstrates the Surveyor lunar probe's descent guidance algorithm
Rust
2
star
15

coursera-robotics-perception

Quiz and assignment solutions for Coursera MOOC - Robotics: Perception
MATLAB
2
star
16

vscode-cpp-docker-debug

A project documenting settings for line-by-line debugging of C++ code running in Docker using VS-Code
Dockerfile
2
star
17

thomasantony.github.io-src

Source code for website
HTML
2
star
18

flybywire-tk

A React-inspired library for building native UIs in Python using Tkinter
Python
1
star
19

runaway_robot

My solution to the final project in Udacity's CS373 course - Artificial Intelligence for Robotics
Python
1
star