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.3.tar.gz (13.3 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.3-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stencil_ui-0.2.3.tar.gz
  • Upload date:
  • Size: 13.3 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.3.tar.gz
Algorithm Hash digest
SHA256 7ce3a021a1e426a6f2153d8550ad5c4cd68ff0a33a947cb18e8c0e689d6ed079
MD5 457aba3e77d88e86b42c6659f632ee6a
BLAKE2b-256 50d2101ae53a41ad49e61aba6d1f944a803a7a291f7bc1397417084dbed2b448

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stencil_ui-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 14.3 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2afbef2dbac92f2e45e7fae0784c274b52bbee4f9c6e3d0abb42d1caa6a98c4a
MD5 e27f367dbfd235556af9184732f03d32
BLAKE2b-256 2a2766ffaa8a76abed432a6a9ad1acb553dd36abf9b4fbc2b2fe13628b218acd

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