Skip to main content

Radiant Runtime Bridge

Project description

Radiant: Unified Python and Brython Runtime

Build web apps in 100% pure Python. No JavaScript. Single-file execution.

GitHub top language PyPI - License PyPI PyPI - Status PyPI - Python Version GitHub last commit CodeFactor Grade

Overview

Radiant is a single-file runtime bridge that blurs the line between server and browser. It encapsulates your entire stack into a single Python script, allowing you to write frontend logic with Brython as if it were running natively in the browser, while maintaining a transparent connection to the backend.

Features

  • Write both frontend and backend code in Python
  • Simple API for DOM manipulation
  • Built-in HTTP server for development
  • Support for RESTful API endpoints (GET, POST)
  • View routing for multi-page applications
  • JSON response helpers
  • IPv4 and IPv6 support

Installation

pip install radiant-runtime-bridge

Quick Start

Minimal Example

Create a simple web application with just a few lines of code:

# Base class that binds the Python server with the Brython frontend
from radiant import BrythonServer


class App(BrythonServer):
    # Application entry point.
    # Inherits the Radiant runtime that exposes HTML primitives and the browser document.

    def __init__(self):
        # This code runs in the browser via Brython, 
        # but is defined in the same script as your server logic.
        self.document <= self.html.H1("Radiant · Python Runtime Bridge")
        self.document <= self.html.P(
            "This application connects a Python backend with a Brython-powered frontend "
            "through a unified runtime."
        )

        
if __name__ == "__main__":
    # Start the embedded HTTP server with default address and port
    App.serve()

    # Alternative explicit binding
    # App.serve(ip="127.0.0.1", port=8080)

Run the application:

python main.py

Then open your browser to http://localhost:5050 (default port).

API Examples

Creating API Endpoints

from radiant import BrythonServer, json_response


class App(BrythonServer):

    @BrythonServer.get("/api/get")
    def get_api(**kwargs):
        """Python rendered function"""
        data = {
            "on_get": "ok",
            **kwargs,
        }
        return json_response(data)

    @BrythonServer.post("/api/post")
    def post_api(**kwargs):
        """Python rendered function"""
        data = {
            "on_post": "ok",
            **kwargs,
        }
        return json_response(data)


if __name__ == "__main__":
    App.serve()

Creating Multiple Views

# Core Radiant runtime and optional JSON utilities
from radiant import BrythonServer, json_response


class App(BrythonServer):
    # Example application demonstrating classic browser navigation
    # with server-rendered views using Radiant.

    def __init__(self):
        # Executed on each page load
        print("Application request received")

        # Main page content
        self.document <= self.html.H1("Radiant · Server-Rendered Views")
        self.document <= self.html.P(
            "This example demonstrates browser-controlled navigation "
            "with full page reloads, where each route renders a new view "
            "handled by the Radiant server."
        )

        # Navigation links triggering full page reloads
        self.document <= self.html.A("Open View 1", href="/page1")
        self.document <= self.html.BR()
        self.document <= self.html.A("Open View 2", href="/page2")
        self.document <= self.html.BR()
        self.document <= self.html.A("Open View 3", href="/page3")

    @BrythonServer.view("/page1")
    def page1(self):
        # View rendered after a full page reload
        self.document <= self.html.H1("View 1")
        self.document <= self.html.P(
            "This page was rendered after a full browser reload "
            "and handled by the Radiant server."
        )
        self.document <= self.html.A("Back to Home", href="/")


if __name__ == "__main__":
    # Start the application using default server settings
    App.serve()

Brython Enhancement

select

The select method enables batch operations on multiple DOM elements. Functions can be applied to all selected elements at once:

selection = self.select('.my-class')
selection.bind('mouseover', lambda evt: print(evt))
selection.style.color = 'cyan'
selection.style = {'background-color': 'red'}

html

The html module offers a Pythonic way to create and manipulate HTML elements:

# Create elements with CSS classes
title = self.html.H1('My Title', Class='header')

# Dynamic class management
title.classes.append('active')
title.classes.extend(['large', 'visible'])

# Python-style CSS properties
title.styles.background_color = 'blue'
title.styles.font_size = '16px'

# Context-based nesting
with self.html.DIV().context as container:
    with self.html.UL().context as list:
        with self.html.LI().context:
            self.html.SPAN("List item")

A complete working example of context managers can be found in examples/html_context_manager/main.py.

styles

The styles object provides a cleaner syntax for managing CSS properties:

selection = self.select('.my-class')
selection.styles.background_color = 'red'
selection.styles.color = 'white'

Important Notes

  • Radiant is designed for development, testing, and prototyping
  • Not recommended for production use without additional security measures
  • No built-in authentication or authorization

License

This project is licensed under the BSD-2-Clause License. See the LICENSE.md file for details.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

radiant_runtime_bridge-0.4.2.tar.gz (6.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

radiant_runtime_bridge-0.4.2-py3-none-any.whl (6.1 MB view details)

Uploaded Python 3

File details

Details for the file radiant_runtime_bridge-0.4.2.tar.gz.

File metadata

  • Download URL: radiant_runtime_bridge-0.4.2.tar.gz
  • Upload date:
  • Size: 6.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for radiant_runtime_bridge-0.4.2.tar.gz
Algorithm Hash digest
SHA256 241c253b6e01b65a967a9c4a0514081e56c13f239a58837b4ad12b991bd82b02
MD5 6b71f826e930468a929a25078df81233
BLAKE2b-256 7d38b08e2a37c9a1fb68c4dd6df3ea60ef69a61547a9b1218974c380561dd11e

See more details on using hashes here.

Provenance

The following attestation bundles were made for radiant_runtime_bridge-0.4.2.tar.gz:

Publisher: python-publish.yml on dunderlab/radiant-runtime-bridge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file radiant_runtime_bridge-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for radiant_runtime_bridge-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 86b6938f4170b361336f346f0af5e92f6902725776ed173cc7c8273166f49a57
MD5 49e5dea664f9214e1efa0b55a2dee629
BLAKE2b-256 18e9d815da9a59cc8520e59ed54263824085943893379fcfed356f7323657cae

See more details on using hashes here.

Provenance

The following attestation bundles were made for radiant_runtime_bridge-0.4.2-py3-none-any.whl:

Publisher: python-publish.yml on dunderlab/radiant-runtime-bridge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page