
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Alfort is simple and plain ELM-like interactive applicaiton framework for Python. Alfort is motivated to provide declaretive UI framework independent from any backends.
Alfort is developping now. So there will be breaking changes.
$ pip install alfort
Code
from typing import Callable
from enum import Enum, auto
from click import prompt
from alfort import Alfort, Dispatch, Effect
from alfort.vdom import Node, Patch, PatchText, Props, VDOM
handlers: dict[str, Callable[[], None]] = {}
class Msg(Enum):
Up = auto()
Down = auto()
class TextNode(Node):
def __init__(self, text: str) -> None:
print(text)
def apply(self, patch: Patch) -> None:
match patch:
case PatchText(new_text):
print(new_text)
case _:
raise ValueError(f"Invalid patch: {patch}")
class AlfortSimpleCounter(Alfort[int, Msg, TextNode]):
def create_text(
self,
text: str,
dispatch: Dispatch[Msg],
) -> TextNode:
handlers["u"] = lambda: dispatch(Msg.Up)
handlers["d"] = lambda: dispatch(Msg.Down)
return TextNode(text)
def create_element(
self,
tag: str,
props: Props,
children: list[TextNode],
dispatch: Dispatch[Msg],
) -> TextNode:
raise ValueError("create_element should not be called")
def main(
self,
) -> None:
self._main()
while True:
c = prompt("press u or d")
if handle := handlers.get(c):
handle()
def main() -> None:
def view(state: int) -> VDOM:
return f"Count: {state}"
def init() -> tuple[int, list[Effect[Msg]]]:
return (0, [])
def update(msg: Msg, state: int) -> tuple[int, list[Effect[Msg]]]:
match msg:
case Msg.Up:
return (state + 1, [])
case Msg.Down:
return (state - 1, [])
app = AlfortSimpleCounter(init=init, view=view, update=update)
app.main()
if __name__ == "__main__":
main()
Output
Count: 0
press u or d: u
Count: 1
press u or d: u
Count: 2
press u or d: u
Count: 3
press u or d: d
Count: 2
press u or d: d
Count: 1
If you need more exmplaes, please check the examples.
Alfort is inspired by TEA(The Elm Architecture). So Alfort makes you create an interactive application with View
, Model
and Update
. If you need more specification about TEA, please see this documentation.
Therefore, Alfort doesn't support Command. So Alfort uses functions whose type is Callable[[Callable[[Msg], None]], Coroutine[None, None, Any]]
to achieve side effect.
You can run some tasks which have side effects in this function. And, if you need, you can pass the result of side effect as Message to dicpatch
which is given as an argument.
This idea is inspired by hyperapp.
For now, Alfort doesn't support the following features.
Alfort doesn't provide Real DOM or other Widgets manupulation.
But there is an iterface between your concrete target and Alfort's Virtual DOM.
It is Patche
. So you have to implement some codes to handle some patches.
alfort-dom is an implementation for manupulation DOM.
$ poetry self add "poethepoet[poetry_plugin]"
$ poetry poe test
$ poetry poe check
FAQs
Elm-like interactive application framework for Python
We found that alfort demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.