Skip to main content

CLI tool to generate UI code for multiple backends like HTML, React, Flutter, ImGui, and 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, 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.

📦 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 stencil command to create your UI from the stencil.yaml file.

stencil

By 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 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 --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 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: [ ]

🖼 Example Outputs

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

  • HTML (-b html): Creates an index.html and style.css in output/html/.
  • React (-b react): Generates a set of React components and an App.tsx file in output/react/src. To use this, you need a React project.
  • Flutter (-b flutter): Creates a new Flutter project in output/flutter_app/ and generates the main.dart file. Run flutter run in output/flutter_app to launch the mobile app.
  • ImGui (-b imgui): Creates a ui.py file in output/imgui/. Run python output/imgui/ui.py to launch a native desktop window.
  • Curses (-b curses): Creates a tui.py file in output/curses/. Run python output/curses/tui.py in your terminal to launch a text-based UI.

🛠 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-1.0.0.tar.gz (17.1 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-1.0.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for stencil_ui-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cfbc4a56eed4e1c64f6a05923258f8c2054806f7109d90f2fb63ff5d9bd658a6
MD5 393e4384194548d3d483748a0b49e821
BLAKE2b-256 252a8ffce54ca3ee3ff61c26abe59ad3d042214cdcd38d1906bd6c22b146436a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: stencil_ui-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.2 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-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d6f89a84fbfae439931368135b6211a0fb524cf65a747900726e9fddf3e5d3e
MD5 acb7078964f26bd91a7c706a8834296b
BLAKE2b-256 8cedb71a3d1f234b7f3a9c9a90ac52d31260ceb1a4a9c9b87b1a99e7718d2474

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