CLI tool to generate HTML or ImGui UIs from a simple config file
Project description
📘 Stencil
stencil is a lightweight CLI tool that generates UI across various backends (like HTML and ImGui) directly from a simple YAML or JSON configuration. It's designed to be easily adaptable to new UI toolkits and frameworks.
No need to manually write boilerplate code — just describe your UI in a config file, and stencil handles the rest.
✨ Features
- 📝 Define UI elements (title, text, button, input, separator) in YAML or JSON.
- ⚡ Generates a ready-to-use
index.htmlwith clean CSS styling. - 🖥️ Generates standalone Python ImGui applications.
- 🧩 Features an extensible architecture for easy adaptation to new UI toolkits.
- 🖱️ Automatic JavaScript stubs for button callbacks, including interactive input handling.
- 🔎 Auto-detects config file (
stencil.yamlorstencil.json) in your project root. - ⏱️ Hot-reload support: automatically regenerate HTML when the config file changes (
stencil generate --watch). - 🎯 Zero setup — just install and run.
📦 Installation
pip install stencil-ui
Requires Python 3.8+
🚀 Usage
1. Initialize your project
Create a default stencil.yaml in your current directory:
stencil init
This will create a stencil.yaml file with a commented example:
# Stencil Configuration File
# ---
# ... (full commented default config) ...
#
# app:
# - title: "My Awesome App"
# - text: |
# Welcome to Stencil!
# - button:
# label: "Click Me!"
# callback: "onButtonClick"
# - separator
# - input:
# label: "Your Name"
# placeholder: "Enter your name here"
# - button:
# label: "Submit"
# callback: "onSubmitName"
# - text: "© 2025 Your Company"
(For the actual content, run stencil init in an empty directory)
2. Generate UI
Generate index.html (default) or ui.py based on your stencil.yaml config:
# Generate HTML (default backend)
stencil generate
# Or specify a backend, e.g., for an ImGui desktop app
stencil generate --backend imgui
index.htmlorui.pywill be generated in your project root.
3. Optional: Hot Reload
Regenerate UI automatically when you edit your config file:
stencil generate --watch
- Monitors
stencil.yamlorstencil.json - Automatically updates
index.htmlorui.pywhenever the file changes - Optional: use a browser live-reload extension to see HTML changes immediately
🖼 Example Output
Stencil's generated UIs are designed to be functional and clean. Here's what you can expect with a configuration that includes a title, text, an input field, and an interactive "Submit" button:
- HTML Backend (
stencil generate): Produces a styledindex.html. Typing into the input and clicking "Submit" will trigger a JavaScriptalert()showing your input. - ImGui Backend (
stencil generate --backend imgui): Produces aui.pyscript. Runningpython ui.pywill open a desktop window. Typing into the input and clicking "Submit" will print your input to the console.
⚙️ Configuration
Stencil looks for either:
stencil.yamlstencil.json
Supported elements:
| Element | Example | Output (HTML/ImGui) |
|---|---|---|
title |
- title: "My Page" |
<title>+<h1> / Window Title + imgui.text_ansi |
text |
- text: "Hello World!" |
<p> / imgui.text |
button |
- button: {label: "Click", cb: "my"} |
<button> / imgui.button |
separator |
- separator |
<hr> / imgui.separator |
input |
- input: {label: "Name", ph: "Enter"} |
<input type="text"> / imgui.input_text |
📂 Project Structure Example
my-project/
│
├── stencil.yaml
├── index.html # generated
└── css/
└── style.css
🛠 Development
Clone and install locally:
git clone https://github.com/your-username/stencil-ui.git
cd stencil-ui
pip install -e .
Run CLI from source:
python -m stencil --watch
📜 License
This project is licensed under the MIT License.
💡 Inspiration
Stencil was built to simplify rapid prototyping of UI pages from configs. Its extensible backend architecture makes it perfect for:
- Mockups & quick demos across different UI frameworks.
- Teaching UI basics with abstract component definitions.
- Auto-generating interfaces for various applications with ease.
- Rapidly adding support for new UI toolkits or frameworks.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stencil_ui-0.2.1.tar.gz.
File metadata
- Download URL: stencil_ui-0.2.1.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62a9b7a22dc737c4b01d78efe846793e703b60f9b0cd690e8959fa09e9921b1c
|
|
| MD5 |
25fe5f3d758767ca5e2c21624c3df31a
|
|
| BLAKE2b-256 |
0f94793463a25e32e4888a2122d9ed6aa0aa1c65bebc6524ca3811c1890cfa99
|
File details
Details for the file stencil_ui-0.2.1-py3-none-any.whl.
File metadata
- Download URL: stencil_ui-0.2.1-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1418a68eeed573bbba3d4d37e9f4fe8899e3662f3b1ba1c516634e2c6e17288
|
|
| MD5 |
75bed27e8f56aef2d38525414bda1a84
|
|
| BLAKE2b-256 |
888710690c4f7e3280a1fa59ed2735d7423cee33ef2d3e51e931f82453f268ae
|