https://github.com/un-gcpds/radiant-framework
A Brython/PyScript Framework for Web Apps development.
https://github.com/un-gcpds/radiant-framework
brython pyscript python tornado
Last synced: 9 months ago
JSON representation
A Brython/PyScript Framework for Web Apps development.
- Host: GitHub
- URL: https://github.com/un-gcpds/radiant-framework
- Owner: UN-GCPDS
- License: bsd-2-clause
- Created: 2020-12-29T22:58:37.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-18T14:40:03.000Z (about 3 years ago)
- Last Synced: 2025-04-23T22:55:42.292Z (11 months ago)
- Topics: brython, pyscript, python, tornado
- Language: JavaScript
- Homepage: https://radiant-framework.readthedocs.io/en/latest/
- Size: 72.1 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Radiant Framework
A Brython/PyScript Framework for Web Apps development.







[](https://radiant-framework.readthedocs.io/en/latest/?badge=latest)
Radiant is a [Brython](https://brython.info/) and [PyScript](https://pyscript.net/) framework for the quick development of web apps using _Python_ syntax, so there is no need to care about (if you don’t want) HTML, CSS, or JavaScript. This is basically a set of scripts that allows the same file run from _Python_ and _Brython_/_PyScript_, when is running under _Python_ a [Tornado](https://www.tornadoweb.org/) server is created and configure the local path for serving static files, at the same time a custom HTML template is configured at runtime to import the same script, this time under _Brython_/_PyScript_.
## Instalation
```python
pip install radiant
```
## Brython: bare minimum
```python
#!bryhton
from radiant.server import RadiantAPI
from browser import document, html
class BareMinimum(RadiantAPI):
def __init__(self, *args, **kwargs):
""""""
super().__init__(*args, **kwargs)
document.select_one('body') <= html.H1('Radiant-Framework')
if __name__ == '__main__':
BareMinimum()
```
## PyScript: bare minimum
This example use a ```requirements.txt``` file to install dependencies.
```python
#requirements.txt
numpy
matplotlib
```
```python
#!pyscript
import numpy as np
from matplotlib import pyplot as plt
from radiant.server import RadiantAPI
import js
class BareMinimum(RadiantAPI):
def __init__(self):
print('Radiant-Framework')
self.plot()
def plot(self):
""""""
fig = plt.figure()
ax = fig.add_subplot(111)
x = np.linspace(0, 10, 1000)
y = np.sin(x)
ax.plot(x, y)
js.document.body.prepend(self.fig2img(fig))
if __name__ == '__main__':
BareMinimum()
```
## Brython + PyScript
```python
#!brython
from radiant.server import RadiantAPI, pyscript
from browser import document, html
class BareMinimum(RadiantAPI):
def __init__(self, *args, **kwargs):
""""""
super().__init__(*args, **kwargs)
document.select_one('body') <= html.H1('Radiant-Framework')
document.select_one('body') <= html.DIV(id='mpl')
self.plot_sin(f=5) # will render on #mpl every time
document.select_one('body') <= self.plot_sinc(f=1)
# will render on #mpl every time
@pyscript(output='mpl')
def plot_sin(self, f=10):
""""""
import numpy as np
from matplotlib import pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x = np.linspace(0, 1, 1000)
y = np.sin(2 * np.pi * f * x)
ax.plot(x, y)
return fig
# will return the image object
@pyscript()
def plot_sinc(self, f):
""""""
import numpy as np
from matplotlib import pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
x = np.linspace(0, 10, 1000)
y = np.sin(2 * np.pi * f * x)
ax.plot(x, y, color='C1')
return fig
if __name__ == '__main__':
BareMinimum()
```