A library for creating declarative, interactive CLI menus with Pydantic and prompt-toolkit.
Project description
🗿 Typerdantic
Typerdantic is a Python library for building powerful, interactive, and self-documenting command-line interface (CLI) menus. It combines the command-line elegance of Typer, the robust data modeling of Pydantic, and the rich terminal UI capabilities of prompt-toolkit.
The goal is to abstract away the boilerplate of creating interactive menus, allowing developers to define complex, multi-screen applications using simple Pydantic models or configuration files.
Core Features
- Declarative & Dynamic Menus: Define menus by subclassing
TyperdanticMenuor generate them on the fly from configuration files (e.g., YAML, JSON) using a Pydantic-validated schema. - External Action Execution: Run shell commands and scripts directly from your menu configuration using action strings like
"command::echo Hello"or"script::./deploy.sh". - Seamless Navigation: A top-level
TyperdanticAppcontroller manages a single, persistent UI, eliminating screen flashes when navigating between menus. - Custom Styling: Theme your entire application by loading a simple TOML style file.
- Asynchronous by Design: Built with
asyncioto handle user input and execute subprocesses without blocking or freezing the UI.
Example Usage
Define your menu in a configuration file, like menu.yml:
# file: menu.yml
doc: My Awesome CLI
items:
list_files:
description: List files in the current directory
action: "command::ls -l"
run_backup:
description: Run the backup script
action: "script::./scripts/backup.sh"
quit:
description: Exit the application
is_quit: true
Then, load and run your application:
# main.py
import asyncio
import yaml
from pathlib import Path
from typerdantic import TyperdanticApp, create_menu_from_config
from typerdantic.config_models import MenuConfig
async def main():
# Load and parse the YAML configuration
config_path = Path("menu.yml")
with open(config_path, "r") as f:
config_dict = yaml.safe_load(f)
menu_config = MenuConfig(**config_dict)
# Create a menu class from the validated config
MyMenu = create_menu_from_config("MyMenu", menu_config)
# Create and run the app
app = TyperdanticApp(main_menu=MyMenu)
await app.run()
if __name__ == "__main__":
asyncio.run(main())
Future Goals
- YAML/JSON Loaders: Add convenience functions like
load_menu_from_yaml()to simplify the loading process. - Internal Action Registry: Create a system for registering and calling internal Python functions via action strings (e.g.,
"internal::backup_database"). - CLI Menu Builder: An interactive command to help scaffold new
Typerdanticapps, menus, and actions. - More Widgets: Support for forms, confirmation dialogs, and progress bars.
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 typerdantic-1.0.3.tar.gz.
File metadata
- Download URL: typerdantic-1.0.3.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08b2cc29fd6e97bf08ba59a14ee72bab29053654c11acb9593cb2363f133f628
|
|
| MD5 |
b1a0b7170b529ebddf4298849422fde2
|
|
| BLAKE2b-256 |
363ea17fcb6c195e0c1e60bbfe33e5602e119e1ca54f0be2dea0ce21e852407c
|
Provenance
The following attestation bundles were made for typerdantic-1.0.3.tar.gz:
Publisher:
python-publish.yml on Willmo103/typerdantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typerdantic-1.0.3.tar.gz -
Subject digest:
08b2cc29fd6e97bf08ba59a14ee72bab29053654c11acb9593cb2363f133f628 - Sigstore transparency entry: 295555694
- Sigstore integration time:
-
Permalink:
Willmo103/typerdantic@7619ca5e6d1dec8bf35743e71083e39c35a91296 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/Willmo103
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7619ca5e6d1dec8bf35743e71083e39c35a91296 -
Trigger Event:
release
-
Statement type:
File details
Details for the file typerdantic-1.0.3-py3-none-any.whl.
File metadata
- Download URL: typerdantic-1.0.3-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9b0522532cf52804ea2348079987e5053eb98c6a45ba8e69929659da163e754
|
|
| MD5 |
ef22039cab6a6728693dbb830aedc0d4
|
|
| BLAKE2b-256 |
b1ba98103530b59d444eda006df1eb69fa0d00fbdb3aa5f87fd72a411442dd51
|
Provenance
The following attestation bundles were made for typerdantic-1.0.3-py3-none-any.whl:
Publisher:
python-publish.yml on Willmo103/typerdantic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
typerdantic-1.0.3-py3-none-any.whl -
Subject digest:
c9b0522532cf52804ea2348079987e5053eb98c6a45ba8e69929659da163e754 - Sigstore transparency entry: 295555697
- Sigstore integration time:
-
Permalink:
Willmo103/typerdantic@7619ca5e6d1dec8bf35743e71083e39c35a91296 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/Willmo103
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@7619ca5e6d1dec8bf35743e71083e39c35a91296 -
Trigger Event:
release
-
Statement type: