Skip to main content

CLI tool to generate UI code for HTML, ImGui, or Curses from a simple config file

Project description

📘 Stencil

PyPI version License: MIT Python Versions

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.


✨ Features

  • Multi-Backend Support: Generate UIs for HTML, 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.

📦 Installation

pip install stencil-ui

Requires Python 3.9+


🚀 Usage

1. Initialize Your Project

Create a default stencil.yaml in your current directory:

stencil init

This will give you a well-commented starting point for your UI configuration.

2. Generate Your UI

Use the generate command to create your UI from the stencil.yaml file.

stencil generate

By default, stencil generates an HTML file. You can specify a different backend using the --backend or -b flag:

# Generate an HTML file (index.html)
stencil generate -b html

# Generate an ImGui desktop application (ui.py)
stencil generate -b imgui

# Generate a Curses terminal application (ui.py)
stencil generate -b curses

3. Watch for Changes

For rapid development, you can use the --watch flag to automatically regenerate the UI whenever you save changes to your stencil.yaml:

stencil generate --watch

This is especially useful with a live-reload server for web development.


⚙️ Configuration

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"

Supported Elements

Element YAML Example HTML Output ImGui Output Curses Output
title - title: "My App" <h1> & <title> Window Title Centered bold text
text - text: "Hello!" <p> imgui.text Centered text
button - button: {label: "Click", callback: "on_click"} <button> imgui.button [ Click ]
separator - separator <hr> imgui.separator ──────────
input - input: {label: "Name", placeholder: "Your name"} <input type="text"> imgui.input_text Name: [ ]

🖼 Example Outputs

Based on the configuration example above, here's what stencil will generate for each backend:

  • HTML (-b html): Creates an index.html file with basic styling and a main.js file with JavaScript stubs for your callbacks.
  • ImGui (-b imgui): Creates a ui.py file. Run python ui.py to launch a native desktop window with your UI elements. Callbacks are generated as placeholder Python functions.
  • Curses (-b curses): Creates a ui.py file. Run python ui.py in your terminal to launch a text-based UI. Use Tab to navigate and Enter to press buttons.

🛠 Development

Clone the repository and install it in editable mode:

git clone https://github.com/your-username/stencil.git
cd stencil
pip install -e .

📜 License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stencil_ui-0.2.6.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stencil_ui-0.2.6-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file stencil_ui-0.2.6.tar.gz.

File metadata

  • Download URL: stencil_ui-0.2.6.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for stencil_ui-0.2.6.tar.gz
Algorithm Hash digest
SHA256 22d1e044eb524184e1d730899ba07209dcb7bb1e2979a0b8bee5a897aae3d66d
MD5 173297c334cda5476ae3989678ce2eb4
BLAKE2b-256 d229443b09baf09323987b7a9e7f3c151c4a06eceb6320849544376e23f3e3ba

See more details on using hashes here.

File details

Details for the file stencil_ui-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: stencil_ui-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for stencil_ui-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 553b81c2ca750525483315c76925f85511540b04d26a086a92cc65d165023fae
MD5 8652ad2cbd1ee9b709a46058749c0d46
BLAKE2b-256 f5ed1bfeb7c294a02d79b6f639725e3e2b22fcd8031e5be9c41139a35332548d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page