Radiant Framework

Brython

Brython (Browser Python) represents a pioneering approach, aimed at supplanting JavaScript with Python as the primary scripting language for web development. Uniquely crafted as a Python 3 implementation, Brython is meticulously tailored to harmonize with the HTML5 framework. This adaptation ensures seamless integration with the Document Object Model (DOM), enabling interaction with web page elements and responsiveness to user-triggered events, thus offering a robust and intuitive environment for modern web applications.

Radiant, a versatile web framework, extends its functionality by integrating Brython. This integration allows developers to write Python code that runs directly in the browser, bypassing the traditional need for JavaScript. This feature simplifies the process of creating interactive web applications by leveraging the familiarity and power of Python.

Radiant

Radiant emerges as an innovative framework uniquely designed for Brython, distinguished by its remarkable capability to be executed directly from Python. This exceptional feature empowers you to write Python code, save it as a file, and then seamlessly execute and interact with it in a web browser. At its core, Radiant embraces an object-oriented paradigm, necessitating the use of classes. Crucially, it mandates the inheritance from RadiantAPI, a cornerstone class that provides the foundational structure and functionalities essential for leveraging the full potential of the Radiant framework in Brython-based web applications.

[ ]:
from radiant.framework.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()
Radiant server running on port 5000

RadiantServer Options

The RadiantServer class plays a pivotal role in the Radiant framework, functioning as the engine for processing additional configuration options. This class allows for a higher level of customization and control over the behavior of Brython applications. By extending RadiantServer, developers can fine-tune aspects such as server settings, resource management, and response handling, thus enhancing the overall functionality and efficiency of their web applications.

[ ]:
from radiant.framework.server import RadiantAPI, RadiantServer
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.H2('Options')


if __name__ == '__main__':
    RadiantServer(
        'BareMinimum',
        host='localhost',
        port=5000,
        brython_version='3.11.2',
        debug_level=0,
    )

The configuration options for Brython in Radiant include fundamental parameters like: - host='localhost': Specifies the server address, with ‘localhost’ indicating that the server runs on the local machine. - port=5000: Determines the port number for the server, where 5000 is a common default for web applications. - brython_version='3.11.2': Sets the version of Brython to be used, ensuring compatibility and feature support. - debug_level=0: Adjusts the level of debugging information displayed, with 0 typically representing minimal output.

Multipage Support

One of the most useful features of the Radiant framework is the ability to create multi-page web applications. This feature allows developers to organize content and functionality across different pages, enhancing user experience and navigation. Implementing multipage support in Radiant is straightforward and offers a scalable way to structure complex web applications.

[ ]:
from radiant.framework.server import RadiantAPI, RadiantServer
from browser import document, html


class BareMinimum(RadiantAPI):

    # ----------------------------------------------------------------------
    def __init__(self, *args, **kwargs):
        """"""
        super().__init__(*args, **kwargs)
        document.select_one('body') <= html.H1('Hello World')
        document.select_one('body') <= html.H2('Multipage support')
        document.select_one('body') <= html.A('second page', href='/multipage')


if __name__ == '__main__':
    RadiantServer(
        'BareMinimum',
        pages=([r'^/multipage$', '_second_page.Second'],),
    )