What
Pixy refers to both code written in the Pixy language, an extension of Python that supports component syntax embedded in Python.
It also refers to the transpiler that transpiles Pixy language code into regular Python.
Examples
Example Pixy Code
todo_page = (
<div class_name="TodoList">
<todo_list>
<todo_item status={Status.Completed}>"Remember the milk"</todo_item>
<todo_item status={Status.Todo}>"Buy a dozen eggs"</todo_item>
</todo_list>
</div>
)
Reusuable custom component function
def todo_list(tagName, props, children=[]):
todos = props['todos']
return (<ul class_="todo-list">
{
[<todo_item todo={todo}/> for todo in todos]}
</ul>)
Who
Pixy is for anyone who wants to author components in HTML within the comforts of python. Since it transpiles to regular python it can be used with Flask, Django etc..
It could be used to make static sites like this one but with the benefit of writing it all in python.
Or it could be used alongside HTMX to build a dynamic website following HATEOAS principles. A complete such example implementing TODOMVC can be found here.
Why
The current state-of-the art way to generate HTML content is jinja2. Unfortunately components are not first class in it and there is a distinct DSL you need to learn to work with it. Logic programming and loops have their own constructs. Pixy allows you to stick with traditional python programming idioms making it a pleasure to work with
With type hints now gaining popularity Pixy can also bring proper typed components to UX development.
How
Pixy is designed to stand on the shoulder of giants. It reuses the entire python compiler toolchain by extending the PEG grammar that Python is built on. Thereby it does Minimum Necessary Changes to make components first class citizens in Python language.