stencil is a lightweight CLI tool that generates UI code for various backends from a single YAML or JSON configuration file. Describe your UI once and let stencil generate the boilerplate for web, desktop, or terminal applications.
- Multi-Backend Support: Generate UIs for HTML, React (web), Flutter (mobile), ImGui (desktop), and Curses (terminal).
- Simple Configuration: Define your UI with a straightforward YAML or JSON file.
- Extensible: Designed to be easily adaptable to new UI toolkits and frameworks.
- Hot-Reload: Automatically regenerate your UI when the configuration file changes.
- Zero Setup: Install and run. It's that simple.
pip install stencil-uiRequires Python 3.9+
Create a default stencil.yaml in your current directory:
stencil initThis will give you a well-commented starting point for your UI configuration.
Use the stencil command to create your UI from the stencil.yaml file.
stencilBy default, stencil generates an HTML file. You can specify a different backend using the --backend or -b flag:
# Generate an HTML file
stencil -b html
# Generate a React application
stencil -b react
# Generate a Flutter application
stencil -b flutter
# Generate an ImGui desktop application
stencil -b imgui
# Generate a Curses terminal application
stencil -b cursesFor rapid development, you can use the --watch flag to automatically regenerate the UI whenever you save changes to your stencil.yaml:
stencil --watchThis is especially useful with a live-reload server for web development.
stencil looks for a stencil.yaml or stencil.json file in the current directory. Here's a simple example:
# stencil.yaml
app:
- title: "My App"
- text: "Welcome to Stencil!"
- separator
- input:
label: "Your Name"
placeholder: "Enter your name"
- button:
label: "Submit"
callback: "submit_name"| Element | YAML Example | HTML Output | React Output | Flutter Output | ImGui Output | Curses Output |
|---|---|---|---|---|---|---|
title |
- title: "My App" |
<h1> & <title> |
<h1> |
Text (headline) |
Window Title | Centered bold text |
text |
- text: "Hello!" |
<p> |
<p> |
Text |
imgui.text |
Centered text |
button |
- button: {label: "Click", callback: "on_click"} |
<button> |
<button> |
ElevatedButton |
imgui.button |
[ Click ] |
separator |
- separator |
<hr> |
<hr> |
Divider |
imgui.separator |
────────── |
input |
- input: {label: "Name", placeholder: "Your name"} |
<input type="text"> |
<input type="text"> |
TextField |
imgui.input_text |
Name: [ ] |
Based on the configuration example above, here's what stencil will generate for each backend:
- HTML (
-b html): Creates anindex.htmlandstyle.cssinoutput/html/. - React (
-b react): Generates a set of React components and anApp.tsxfile inoutput/react/src. To use this, you need a React project. - Flutter (
-b flutter): Creates a new Flutter project inoutput/flutter_app/and generates themain.dartfile. Runflutter runinoutput/flutter_appto launch the mobile app. - ImGui (
-b imgui): Creates aui.pyfile inoutput/imgui/. Runpython output/imgui/ui.pyto launch a native desktop window. - Curses (
-b curses): Creates atui.pyfile inoutput/curses/. Runpython output/curses/tui.pyin your terminal to launch a text-based UI.
Clone the repository and install it in editable mode:
git clone https://github.com/your-username/stencil.git
cd stencil
pip install -e .This project is licensed under the MIT License.