app-model: Generic Application Schema

0.5.1 · active · verified Fri Apr 17

app-model is a Python library that provides a generic application schema, inspired by frameworks like VS Code and Qt. It allows defining commands, menus, keybindings, and application state in a structured, framework-agnostic way. Built on Pydantic, it offers strong typing and data validation. The current version is 0.5.1, with releases typically tied to feature development and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic `Application`, define and register commands using `Command` objects, associate them with menus via `Menu` enumerations, and execute commands, retrieving their results. Note the use of `.result()` to unwrap the `Future` returned by `execute` for synchronous retrieval.

from app_model import Application, Command, Menu

def say_hello(name: str = "World") -> str:
    "A command that greets the provided name."
    return f"Hello, {name}!"

def say_goodbye() -> str:
    "A simple command to say goodbye."
    return "Goodbye!"

# 1. Initialize the application
app = Application("my-first-app")

# 2. Register commands
app.register_command(Command("my-app.hello", say_hello, title="Say Hello"))
app.register_command(Command("my-app.goodbye", say_goodbye, title="Say Goodbye"))

# 3. Register a menu item for the 'hello' command
app.register_menu_item(
    Menu.APP,  # or Menu.FILE, Menu.EDIT, etc.
    Command("my-app.hello", title="Say Hello from Menu", menu_path="File > Hello"),
)

# 4. Execute a command and get its result
hello_result = app.commands.execute("my-app.hello", {"name": "Registry"}).result()
print(f"Hello Command Result: {hello_result}")

goodbye_result = app.commands.execute("my-app.goodbye").result()
print(f"Goodbye Command Result: {goodbye_result}")

view raw JSON →