frontage 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- frontage/__init__.py +29 -0
- frontage/errors.py +18 -0
- frontage/renderer.py +197 -0
- frontage/runtime.py +80 -0
- frontage/version.py +3 -0
- frontage/view.py +120 -0
- frontage-0.0.1.dist-info/METADATA +110 -0
- frontage-0.0.1.dist-info/RECORD +11 -0
- frontage-0.0.1.dist-info/WHEEL +4 -0
- frontage-0.0.1.dist-info/licenses/LICENSE +202 -0
- frontage-0.0.1.dist-info/licenses/NOTICE +10 -0
frontage/__init__.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Frontage: a fine-grained reactive UI framework for Python in the browser.
|
|
2
|
+
|
|
3
|
+
M0 of the rewrite (see DESIGN.md): the runtime bridge, the renderer seam and a static view
|
|
4
|
+
builder. Reactivity, the DOM renderer and templates follow in M1 and M2.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .errors import FrontageError, NotReady, RenderError
|
|
8
|
+
from .renderer import HtmlRenderer, RecordingRenderer, Renderer
|
|
9
|
+
from .runtime import in_browser, platform
|
|
10
|
+
from .version import __version__
|
|
11
|
+
from .view import Element, Text, build, h, render_to_string, text
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"Element",
|
|
15
|
+
"FrontageError",
|
|
16
|
+
"HtmlRenderer",
|
|
17
|
+
"NotReady",
|
|
18
|
+
"RecordingRenderer",
|
|
19
|
+
"RenderError",
|
|
20
|
+
"Renderer",
|
|
21
|
+
"Text",
|
|
22
|
+
"__version__",
|
|
23
|
+
"build",
|
|
24
|
+
"h",
|
|
25
|
+
"in_browser",
|
|
26
|
+
"platform",
|
|
27
|
+
"render_to_string",
|
|
28
|
+
"text",
|
|
29
|
+
]
|
frontage/errors.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Frontage's exception types. Nothing here imports anything of ours."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class FrontageError(Exception):
|
|
5
|
+
"""Base class for every error Frontage raises on purpose."""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class RenderError(FrontageError):
|
|
9
|
+
"""A view could not be built or updated."""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class NotReady(FrontageError):
|
|
13
|
+
"""Raised inside a reactive computation to end it quietly: the value it needs is not
|
|
14
|
+
there yet. A `Loading` boundary above it shows its fallback until the value arrives.
|
|
15
|
+
Not an error to the user, so it never reaches an `Errored` boundary."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
__all__ = ["FrontageError", "NotReady", "RenderError"]
|
frontage/renderer.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"""The seam between the view layer and whatever it draws on.
|
|
2
|
+
|
|
3
|
+
A `Renderer` is the small set of operations the view layer needs from a document: create
|
|
4
|
+
nodes, place them, change their text and properties, walk them. The browser gets a DOM
|
|
5
|
+
renderer (M1); tests and servers get `HtmlRenderer`, whose nodes are plain Python objects
|
|
6
|
+
that serialise to HTML. `RecordingRenderer` wraps another renderer and keeps a log of every
|
|
7
|
+
operation, which is how a test asserts *how little* a change touched.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
_VOID = {
|
|
11
|
+
"area",
|
|
12
|
+
"base",
|
|
13
|
+
"br",
|
|
14
|
+
"col",
|
|
15
|
+
"embed",
|
|
16
|
+
"hr",
|
|
17
|
+
"img",
|
|
18
|
+
"input",
|
|
19
|
+
"link",
|
|
20
|
+
"meta",
|
|
21
|
+
"param",
|
|
22
|
+
"source",
|
|
23
|
+
"track",
|
|
24
|
+
"wbr",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def escape(text, quote=False):
|
|
29
|
+
text = str(text).replace("&", "&").replace("<", "<").replace(">", ">")
|
|
30
|
+
if quote:
|
|
31
|
+
text = text.replace('"', """)
|
|
32
|
+
return text
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Renderer:
|
|
36
|
+
"""The operations a renderer provides. Subclasses implement every method."""
|
|
37
|
+
|
|
38
|
+
def create_element(self, tag):
|
|
39
|
+
raise NotImplementedError
|
|
40
|
+
|
|
41
|
+
def create_text(self, text):
|
|
42
|
+
raise NotImplementedError
|
|
43
|
+
|
|
44
|
+
def replace_text(self, node, text):
|
|
45
|
+
raise NotImplementedError
|
|
46
|
+
|
|
47
|
+
def set_property(self, node, name, value):
|
|
48
|
+
"""Set an attribute or property; `None` removes it, `True`/`False` toggle a boolean."""
|
|
49
|
+
raise NotImplementedError
|
|
50
|
+
|
|
51
|
+
def insert_node(self, parent, node, anchor=None):
|
|
52
|
+
"""Insert `node` under `parent` before `anchor`, or append when `anchor` is None."""
|
|
53
|
+
raise NotImplementedError
|
|
54
|
+
|
|
55
|
+
def remove_node(self, parent, node):
|
|
56
|
+
raise NotImplementedError
|
|
57
|
+
|
|
58
|
+
def is_text(self, node):
|
|
59
|
+
raise NotImplementedError
|
|
60
|
+
|
|
61
|
+
def parent(self, node):
|
|
62
|
+
raise NotImplementedError
|
|
63
|
+
|
|
64
|
+
def first_child(self, node):
|
|
65
|
+
raise NotImplementedError
|
|
66
|
+
|
|
67
|
+
def next_sibling(self, node):
|
|
68
|
+
raise NotImplementedError
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class HtmlNode:
|
|
72
|
+
"""A node of `HtmlRenderer`: an element with a tag, or text with `tag=None`."""
|
|
73
|
+
|
|
74
|
+
def __init__(self, tag, text=None):
|
|
75
|
+
self.tag = tag
|
|
76
|
+
self.text = text
|
|
77
|
+
self.attrs = {}
|
|
78
|
+
self.children = []
|
|
79
|
+
self.parent = None
|
|
80
|
+
|
|
81
|
+
def to_html(self):
|
|
82
|
+
if self.tag is None:
|
|
83
|
+
return escape(self.text)
|
|
84
|
+
out = ["<", self.tag]
|
|
85
|
+
for name, value in self.attrs.items():
|
|
86
|
+
if value is True:
|
|
87
|
+
out.append(f" {name}")
|
|
88
|
+
elif value is False or value is None:
|
|
89
|
+
continue
|
|
90
|
+
else:
|
|
91
|
+
out.append(f' {name}="{escape(value, quote=True)}"')
|
|
92
|
+
out.append(">")
|
|
93
|
+
if self.tag in _VOID:
|
|
94
|
+
return "".join(out)
|
|
95
|
+
for child in self.children:
|
|
96
|
+
out.append(child.to_html())
|
|
97
|
+
out.append(f"</{self.tag}>")
|
|
98
|
+
return "".join(out)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class HtmlRenderer(Renderer):
|
|
102
|
+
"""Renders into plain Python nodes that serialise to HTML. No browser involved."""
|
|
103
|
+
|
|
104
|
+
def create_element(self, tag):
|
|
105
|
+
return HtmlNode(tag)
|
|
106
|
+
|
|
107
|
+
def create_text(self, text):
|
|
108
|
+
return HtmlNode(None, str(text))
|
|
109
|
+
|
|
110
|
+
def replace_text(self, node, text):
|
|
111
|
+
node.text = str(text)
|
|
112
|
+
|
|
113
|
+
def set_property(self, node, name, value):
|
|
114
|
+
if value is None or value is False:
|
|
115
|
+
node.attrs.pop(name, None)
|
|
116
|
+
else:
|
|
117
|
+
node.attrs[name] = value
|
|
118
|
+
|
|
119
|
+
def insert_node(self, parent, node, anchor=None):
|
|
120
|
+
if node.parent is not None:
|
|
121
|
+
node.parent.children.remove(node)
|
|
122
|
+
node.parent = parent
|
|
123
|
+
if anchor is None:
|
|
124
|
+
parent.children.append(node)
|
|
125
|
+
else:
|
|
126
|
+
parent.children.insert(parent.children.index(anchor), node)
|
|
127
|
+
|
|
128
|
+
def remove_node(self, parent, node):
|
|
129
|
+
parent.children.remove(node)
|
|
130
|
+
node.parent = None
|
|
131
|
+
|
|
132
|
+
def is_text(self, node):
|
|
133
|
+
return node.tag is None
|
|
134
|
+
|
|
135
|
+
def parent(self, node):
|
|
136
|
+
return node.parent
|
|
137
|
+
|
|
138
|
+
def first_child(self, node):
|
|
139
|
+
return node.children[0] if node.children else None
|
|
140
|
+
|
|
141
|
+
def next_sibling(self, node):
|
|
142
|
+
siblings = node.parent.children if node.parent else []
|
|
143
|
+
i = siblings.index(node) + 1
|
|
144
|
+
return siblings[i] if i < len(siblings) else None
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class RecordingRenderer(Renderer):
|
|
148
|
+
"""Forwards to another renderer and records `(operation, *args)` for every call."""
|
|
149
|
+
|
|
150
|
+
def __init__(self, inner=None):
|
|
151
|
+
self.inner = inner or HtmlRenderer()
|
|
152
|
+
self.log = []
|
|
153
|
+
|
|
154
|
+
def _record(self, op, *args):
|
|
155
|
+
self.log.append((op,) + args)
|
|
156
|
+
|
|
157
|
+
def create_element(self, tag):
|
|
158
|
+
self._record("create_element", tag)
|
|
159
|
+
return self.inner.create_element(tag)
|
|
160
|
+
|
|
161
|
+
def create_text(self, text):
|
|
162
|
+
self._record("create_text", text)
|
|
163
|
+
return self.inner.create_text(text)
|
|
164
|
+
|
|
165
|
+
def replace_text(self, node, text):
|
|
166
|
+
self._record("replace_text", text)
|
|
167
|
+
return self.inner.replace_text(node, text)
|
|
168
|
+
|
|
169
|
+
def set_property(self, node, name, value):
|
|
170
|
+
self._record("set_property", name, value)
|
|
171
|
+
return self.inner.set_property(node, name, value)
|
|
172
|
+
|
|
173
|
+
def insert_node(self, parent, node, anchor=None):
|
|
174
|
+
self._record("insert_node")
|
|
175
|
+
return self.inner.insert_node(parent, node, anchor)
|
|
176
|
+
|
|
177
|
+
def remove_node(self, parent, node):
|
|
178
|
+
self._record("remove_node")
|
|
179
|
+
return self.inner.remove_node(parent, node)
|
|
180
|
+
|
|
181
|
+
def is_text(self, node):
|
|
182
|
+
return self.inner.is_text(node)
|
|
183
|
+
|
|
184
|
+
def parent(self, node):
|
|
185
|
+
return self.inner.parent(node)
|
|
186
|
+
|
|
187
|
+
def first_child(self, node):
|
|
188
|
+
return self.inner.first_child(node)
|
|
189
|
+
|
|
190
|
+
def next_sibling(self, node):
|
|
191
|
+
return self.inner.next_sibling(node)
|
|
192
|
+
|
|
193
|
+
def count(self, op):
|
|
194
|
+
return sum(1 for entry in self.log if entry[0] == op)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
__all__ = ["HtmlNode", "HtmlRenderer", "RecordingRenderer", "Renderer", "escape"]
|
frontage/runtime.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Which Python is running us, and the bridge to the browser when there is one.
|
|
2
|
+
|
|
3
|
+
Frontage runs in three places: Pyodide and MicroPython in the browser, and plain CPython on
|
|
4
|
+
a server or in the tests. The names exported here are the browser globals and the FFI
|
|
5
|
+
helpers on the two browser runtimes, and stand-ins on the server that say so if touched.
|
|
6
|
+
Nothing else in the package imports `pyscript` or `js` directly.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
# Most of these names exist to be re-exported. Without this list an unused-import
|
|
12
|
+
# autofix deletes them and the package stops importing in the browser.
|
|
13
|
+
__all__ = [
|
|
14
|
+
"CPYTHON",
|
|
15
|
+
"MICROPYTHON",
|
|
16
|
+
"PYODIDE",
|
|
17
|
+
"Unavailable",
|
|
18
|
+
"create_proxy",
|
|
19
|
+
"document",
|
|
20
|
+
"in_browser",
|
|
21
|
+
"platform",
|
|
22
|
+
"to_js",
|
|
23
|
+
"window",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
PYODIDE = "pyodide"
|
|
27
|
+
MICROPYTHON = "micropython"
|
|
28
|
+
CPYTHON = "cpython"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _detect():
|
|
32
|
+
if sys.platform == "emscripten":
|
|
33
|
+
return PYODIDE
|
|
34
|
+
if sys.platform == "webassembly" and sys.implementation.name == "micropython":
|
|
35
|
+
return MICROPYTHON
|
|
36
|
+
return CPYTHON
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
platform = _detect()
|
|
40
|
+
in_browser = platform in (PYODIDE, MICROPYTHON)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Unavailable:
|
|
44
|
+
"""A browser global on the server: falsy, and loud if anything actually uses it.
|
|
45
|
+
|
|
46
|
+
Standing in with an object rather than `None` gives a sentence naming the global at
|
|
47
|
+
the point of use, instead of an `AttributeError` on `None` somewhere downstream.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(self, name):
|
|
51
|
+
object.__setattr__(self, "_name", name)
|
|
52
|
+
|
|
53
|
+
def __bool__(self):
|
|
54
|
+
return False
|
|
55
|
+
|
|
56
|
+
def __getattr__(self, attr):
|
|
57
|
+
raise RuntimeError(f"{self._name}.{attr}: {self._name} is only available in the browser")
|
|
58
|
+
|
|
59
|
+
def __setattr__(self, attr, value):
|
|
60
|
+
raise RuntimeError(f"{self._name}.{attr}: {self._name} is only available in the browser")
|
|
61
|
+
|
|
62
|
+
def __call__(self, *args, **kwargs):
|
|
63
|
+
raise RuntimeError(f"{self._name} is only available in the browser")
|
|
64
|
+
|
|
65
|
+
def __repr__(self):
|
|
66
|
+
return f"<{self._name}: unavailable outside the browser>"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if in_browser:
|
|
70
|
+
from pyscript import document, window
|
|
71
|
+
from pyscript.ffi import create_proxy, to_js
|
|
72
|
+
else:
|
|
73
|
+
document = Unavailable("document")
|
|
74
|
+
window = Unavailable("window")
|
|
75
|
+
|
|
76
|
+
def create_proxy(obj):
|
|
77
|
+
return obj
|
|
78
|
+
|
|
79
|
+
def to_js(obj):
|
|
80
|
+
return obj
|
frontage/version.py
ADDED
frontage/view.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""The view tree and the `h` builder. M0: static structure only; reactivity lands in M1.
|
|
2
|
+
|
|
3
|
+
A view is a tree of `Element` and `Text` nodes that knows nothing about a document. The
|
|
4
|
+
builder makes one in two ways that produce the same tree: the call form,
|
|
5
|
+
`h.div(h.p("hi"), cls="x")`, and the `with` form, where elements created inside a
|
|
6
|
+
`with h.div():` block become its children. `build(view, renderer)` draws the tree through
|
|
7
|
+
a `Renderer`; `render_to_string(view)` is that with `HtmlRenderer`.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from .renderer import HtmlRenderer
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Text:
|
|
14
|
+
def __init__(self, value):
|
|
15
|
+
self.value = value
|
|
16
|
+
|
|
17
|
+
def __repr__(self):
|
|
18
|
+
return f"Text({self.value!r})"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Element:
|
|
22
|
+
def __init__(self, tag, attrs, children):
|
|
23
|
+
self.tag = tag
|
|
24
|
+
self.attrs = attrs
|
|
25
|
+
self.children = children
|
|
26
|
+
|
|
27
|
+
def __repr__(self):
|
|
28
|
+
return f"Element({self.tag!r}, {self.attrs!r}, {self.children!r})"
|
|
29
|
+
|
|
30
|
+
# The `with` form: elements built inside the block are appended to this one.
|
|
31
|
+
def __enter__(self):
|
|
32
|
+
_stack.append(self)
|
|
33
|
+
return self
|
|
34
|
+
|
|
35
|
+
def __exit__(self, exc_type, exc, tb):
|
|
36
|
+
_stack.pop()
|
|
37
|
+
return False
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
_stack = []
|
|
41
|
+
|
|
42
|
+
# Keyword spellings the builder accepts for names Python cannot write as-is.
|
|
43
|
+
_ATTR_ALIASES = {"cls": "class", "class_": "class", "for_": "for"}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _attr_name(name):
|
|
47
|
+
if name in _ATTR_ALIASES:
|
|
48
|
+
return _ATTR_ALIASES[name]
|
|
49
|
+
if name.endswith("_"):
|
|
50
|
+
name = name[:-1]
|
|
51
|
+
return name.replace("_", "-")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _children(items):
|
|
55
|
+
out = []
|
|
56
|
+
for item in items:
|
|
57
|
+
if item is None or item is True or item is False:
|
|
58
|
+
continue
|
|
59
|
+
if isinstance(item, (list, tuple)):
|
|
60
|
+
out.extend(_children(item))
|
|
61
|
+
elif isinstance(item, (Element, Text)):
|
|
62
|
+
out.append(item)
|
|
63
|
+
else:
|
|
64
|
+
out.append(Text(item))
|
|
65
|
+
return out
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class _TagFactory:
|
|
69
|
+
def __init__(self, tag):
|
|
70
|
+
self.tag = tag
|
|
71
|
+
|
|
72
|
+
def __call__(self, *children, **attrs):
|
|
73
|
+
element = Element(self.tag, {_attr_name(k): v for k, v in attrs.items()}, _children(children))
|
|
74
|
+
if _stack:
|
|
75
|
+
_stack[-1].children.append(element)
|
|
76
|
+
return element
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class _Builder:
|
|
80
|
+
def __getattr__(self, tag):
|
|
81
|
+
return _TagFactory(tag.rstrip("_").replace("_", "-"))
|
|
82
|
+
|
|
83
|
+
def __call__(self, tag, *children, **attrs):
|
|
84
|
+
return _TagFactory(tag)(*children, **attrs)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
h = _Builder()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def text(value):
|
|
91
|
+
"""A text node; inside a `with` block it is appended like an element."""
|
|
92
|
+
node = Text(value)
|
|
93
|
+
if _stack:
|
|
94
|
+
_stack[-1].children.append(node)
|
|
95
|
+
return node
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def build(view, renderer, parent=None):
|
|
99
|
+
"""Draw `view` through `renderer`, under `parent` when given. Returns the node."""
|
|
100
|
+
if isinstance(view, Text):
|
|
101
|
+
node = renderer.create_text(view.value)
|
|
102
|
+
elif isinstance(view, Element):
|
|
103
|
+
node = renderer.create_element(view.tag)
|
|
104
|
+
for name, value in view.attrs.items():
|
|
105
|
+
renderer.set_property(node, name, value)
|
|
106
|
+
for child in view.children:
|
|
107
|
+
build(child, renderer, node)
|
|
108
|
+
else:
|
|
109
|
+
node = renderer.create_text(view)
|
|
110
|
+
if parent is not None:
|
|
111
|
+
renderer.insert_node(parent, node)
|
|
112
|
+
return node
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def render_to_string(view):
|
|
116
|
+
"""The view as HTML, with no browser involved."""
|
|
117
|
+
return build(view, HtmlRenderer()).to_html()
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
__all__ = ["Element", "Text", "build", "h", "render_to_string", "text"]
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: frontage
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Fine-grained reactive UI framework for Python in the browser (PyScript, Pyodide, MicroPython)
|
|
5
|
+
Project-URL: Homepage, https://frontage.optersoft.com
|
|
6
|
+
Project-URL: Documentation, https://academy.optersoft.com/tool/frontage
|
|
7
|
+
Project-URL: Repository, https://github.com/optersoft/frontage
|
|
8
|
+
Project-URL: Issues, https://github.com/optersoft/frontage/issues
|
|
9
|
+
Author-email: "Optersoft, S.L." <david@optersoft.com>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
License-File: NOTICE
|
|
13
|
+
Keywords: framework,frontend,micropython,pyodide,pyscript,reactive,spa,webassembly
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Environment :: Web Environment
|
|
16
|
+
Classifier: Environment :: WebAssembly
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Intended Audience :: Education
|
|
19
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Programming Language :: Python :: Implementation :: MicroPython
|
|
24
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
26
|
+
Requires-Python: >=3.12
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# Frontage
|
|
30
|
+
|
|
31
|
+
[frontage.optersoft.com](https://frontage.optersoft.com) · [documentation](https://academy.optersoft.com/tool/frontage) · [PyPI](https://pypi.org/project/frontage/)
|
|
32
|
+
|
|
33
|
+
**A fine-grained reactive UI framework for Python in the browser.** Signals, memos and
|
|
34
|
+
effects; templates that clone once and bind only their holes; a keyed `For`; a nested
|
|
35
|
+
router; running on [PyScript](https://pyscript.net) over WebAssembly, on Pyodide or
|
|
36
|
+
MicroPython. No JavaScript, no Node, no bundler: you write Python and the browser runs it.
|
|
37
|
+
|
|
38
|
+
> **Status: pre-alpha, being rewritten.** `main` holds milestone M0 of the plan in
|
|
39
|
+
> [DESIGN.md](DESIGN.md): the runtime bridge, the renderer seam and a static view builder.
|
|
40
|
+
> Reactivity, the DOM renderer and templates follow. The previous code, a fork of PuePy,
|
|
41
|
+
> lives on the `puepy-reference` branch and still works if you need something today.
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from frontage import Signal, html
|
|
45
|
+
|
|
46
|
+
def counter(initial=0):
|
|
47
|
+
count = Signal(initial)
|
|
48
|
+
return html(t"""
|
|
49
|
+
<div class="counter">
|
|
50
|
+
<button on:click={lambda e: count.update(lambda n: n - 1)}>-</button>
|
|
51
|
+
<span>Value: {count}!</span>
|
|
52
|
+
<button on:click={lambda e: count.update(lambda n: n + 1)}>+</button>
|
|
53
|
+
</div>
|
|
54
|
+
""")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
That is the target syntax (M2). What runs today:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from frontage import h, render_to_string
|
|
61
|
+
|
|
62
|
+
with h.ul(cls="menu") as menu:
|
|
63
|
+
for label in ("Home", "About"):
|
|
64
|
+
h.li(label)
|
|
65
|
+
|
|
66
|
+
print(render_to_string(menu)) # <ul class="menu"><li>Home</li><li>About</li></ul>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Why
|
|
70
|
+
|
|
71
|
+
Python in the browser exists (PyScript, Pyodide, MicroPython) and the frameworks that use it
|
|
72
|
+
either carry a server into the browser (Streamlit's stlite, Shiny's Shinylive: tens of
|
|
73
|
+
seconds to start) or rebuild and diff the page on every change. Frontage is browser-first:
|
|
74
|
+
no session, no transport, no DSL, and a state change touches only the DOM nodes that read
|
|
75
|
+
it. The whole reasoning, with the frameworks it learned from, is in [DESIGN.md](DESIGN.md);
|
|
76
|
+
the behaviours it must have, one line each, are in [SPEC.md](SPEC.md).
|
|
77
|
+
|
|
78
|
+
## Develop
|
|
79
|
+
|
|
80
|
+
The repo uses [uv](https://docs.astral.sh/uv/) and [mkrun](https://github.com/optersoft/make) (`mk`).
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
mk sync # .venv with every dependency group
|
|
84
|
+
mk check # lint, types, unit tests: the gate
|
|
85
|
+
mk pyscript.fetch # PyScript's offline bundle (core + both interpreters) into tools/pyscript/
|
|
86
|
+
mk serve # the examples at http://127.0.0.1:8000/examples/, package read live
|
|
87
|
+
mk test --browser # the examples in Chromium, under MicroPython and Pyodide
|
|
88
|
+
mk site.deploy # publish frontage.optersoft.com (Cloudflare Pages)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Without `mk`: `uv sync --all-groups`, `uv run pytest`, `uv run ruff check`, `uv run ty check`.
|
|
92
|
+
|
|
93
|
+
## Contributing
|
|
94
|
+
|
|
95
|
+
Contributions are welcome and are accepted under the Apache License 2.0, the same terms the
|
|
96
|
+
project is published under. By opening a pull request you agree that your contribution may be
|
|
97
|
+
distributed under that license, including its patent grant (section 3). There is no separate
|
|
98
|
+
contributor agreement. The rewrite is clean-room: code is written from `SPEC.md`, not from
|
|
99
|
+
any reference framework's source, and a pull request says so.
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
Apache License 2.0, copyright Optersoft, S.L. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
104
|
+
|
|
105
|
+
**Frontage** and the Frontage logo are trademarks of Optersoft, S.L. The license grants no
|
|
106
|
+
rights to the name or the logo (Apache License section 6). You may say that your work uses or
|
|
107
|
+
is built with Frontage; a fork or a derivative must ship under another name.
|
|
108
|
+
|
|
109
|
+
Frontage's reactive model follows [Solid](https://www.solidjs.com/) and
|
|
110
|
+
[Leptos](https://leptos.dev/); the project began as a fork of [PuePy](https://github.com/kkinder/puepy).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
frontage/__init__.py,sha256=gJCsG3pNXfkMrdQnf4-iI9hqEOUPPx2VlyKmlcUG2uM,779
|
|
2
|
+
frontage/errors.py,sha256=QbtJSIxOveFrYQH7cE4ows4bzB53l6a_1GPlhTM0Sn0,600
|
|
3
|
+
frontage/renderer.py,sha256=iUQQOeCaMOZt2FcUH-jK3p4Znym5iEseRwxtt0CAe0k,5701
|
|
4
|
+
frontage/runtime.py,sha256=dpf8iuyDTadjfxYxE_45TYoauSYgwUp5WmOZvw_uDj4,2277
|
|
5
|
+
frontage/version.py,sha256=C4oMYPtG3zg_mDakTcV3FLQAJs5ADKV843pq2adae-Y,191
|
|
6
|
+
frontage/view.py,sha256=QaSraCGjUf50UC05e0Sj9x8Pk0Lkf9YENJcPdF6bcqQ,3400
|
|
7
|
+
frontage-0.0.1.dist-info/METADATA,sha256=AFf7RoaSrekdb-w2EOL_OXi4jyzCxN8MTvOUi0rkHVE,5088
|
|
8
|
+
frontage-0.0.1.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
9
|
+
frontage-0.0.1.dist-info/licenses/LICENSE,sha256=cdj3a_OccktKyc4eRBORpfORLjIbSl4S_oJJn9ci1yI,11345
|
|
10
|
+
frontage-0.0.1.dist-info/licenses/NOTICE,sha256=SIJGRP0zgnewyjwHzMQvmvYsiO-TN6favu6ZwQBOF_0,472
|
|
11
|
+
frontage-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Optersoft, S.L.
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Frontage
|
|
2
|
+
Copyright 2026 Optersoft, S.L.
|
|
3
|
+
|
|
4
|
+
"Frontage" is a trademark of Optersoft, S.L. The Apache License grants no
|
|
5
|
+
trademark rights (section 6); a derivative work must use a different name.
|
|
6
|
+
|
|
7
|
+
Frontage's reactive model follows Solid (MIT) and Leptos (MIT); the project
|
|
8
|
+
began on 2026-09-05 as a fork of PuePy (Apache 2.0), which was replaced by a
|
|
9
|
+
clean-room rewrite. None of their code is included; the fork is preserved on
|
|
10
|
+
the `puepy-reference` branch under its own notice.
|