Skip to content

All possible interfaces

Apart from the default Mininterface – the base interface all the others are fully compatible with – several interfaces exist in mininterface.interfaces.

shortcut full name
min Mininterface
gui GuiInterface | TkInterface
tui | textual TuiInterface
text | tui TextInterface
web WebInterface

Ordering

We try to obtain the best interface available. The preference is gui, then tui (textual, or at least text); finally, the original non-interactive min is used. This ensures the program still works in cron jobs etc. (Web is never chosen automatically.)

graph LR
gui --> tk{ tk } --> tui --> textual{ textual } --> text{ text } --> min
web

Getting one

Normally, you get an interface through mininterface.run but if you do not wish to parse the CLI and config file, you can invoke one directly through from mininterface.interfaces import *. You may as well use the get_interface function to ensure the interface is available, or invoke the program with the MININTERFACE_INTERFACE environment variable.

Info

Performance boost: Only the interfaces actually used are loaded into memory, for a faster start.

Direct invocation

How to invoke a specific interface directly?

from mininterface.interfaces import TuiInterface

with TuiInterface("My program") as m:
    number = m.ask("Returns number", int)

get_interface

Returns the best available interface.

Similar to mininterface.run but without CLI or config file parsing.

from mininterface.interfaces import get_interface
m = get_interface()
m.ask("...")

Parameters:

Name Type Description Default
interface InterfaceType

An interface type of preference.

None
title str

Window title

''
settings Optional[MininterfaceSettings] None
env Optional[EnvClass]

You can specify the .env attribute of the returned object.

None

Without an explicit interface, the preference is taken from the MININTERFACE_INTERFACE environment variable, then from settings.interface.

Environment variable MININTERFACE_INTERFACE

From outside, you may override the default interface choice with the environment variable.

$ MININTERFACE_INTERFACE=web program.py

Mininterface

The base interface. It is configured via UiSettings.

Non-interactive; it behaves as if the user confirmed everything. Useful e.g. in cron scripts.

$ MININTERFACE_INTERFACE=min ./program.py
Asking the form Env(my_flag=False, my_number=4)
4
Code
from dataclasses import dataclass
from mininterface import run

@dataclass
class Env:
    """ This calculates something. """

    my_flag: bool = False
    """ This switches the functionality """

    my_number: int = 4
    """ This number is very important """

if __name__ == "__main__":
    m = run(Env, title="My application")
    m.form()
    # Attributes are suggested by the IDE
    # along with the hint text 'This number is very important'.
    print(m.env.my_number)

If that is not possible, the program ends with a warning.

$ MININTERFACE_INTERFACE=gui ./program.py
Asking the form Env(my_flag=MISSING, my_number=4)
the following arguments are required: --my-flag
Code
from dataclasses import dataclass
from mininterface import run

@dataclass
class Env:
    """ This calculates something. """

    my_flag: bool # no default value here
    """ This switches the functionality """

    my_number: int = 4
    """ This number is very important """

if __name__ == "__main__":
    m = run(Env, title="My application")
    m.form()

GuiInterface or TkInterface or 'gui'

A tkinter window. It is configured via GuiSettings.

$ MININTERFACE_INTERFACE=gui ./program.py

Hello world example: GUI window

TuiInterface or 'tui'

An interactive terminal. It tries to use TextualInterface, with TextInterface as a fallback. Configured via TuiSettings.

TextualInterface

If textual is installed, a rich, mouse-clickable interface is used. It is configured via TextualSettings.

$ MININTERFACE_INTERFACE=tui ./program.py

Hello world example: TUI fallback

TextInterface

A plain-text fallback interface with no dependencies. It is configured via TextSettings. A non-interactive session becomes interactive if possible, but there is no mouse support. Unlike TextualInterface, it does not clear the whole screen, should that suit your program flow better.

$ MININTERFACE_INTERFACE=text ./program.py
Hello world example: text fallback

WebInterface or 'web'

Exposes the program to the web. It is configured via WebSettings.

You can expose any script to the web by invoking it through the bundled mininterface program.

$ mininterface web ./program.py --port 9997

Still, you can request the web interface by preference in the run or get_interface method, invoke it directly by importing WebInterface from mininterface.interfaces, or use the environment variable.

$ MININTERFACE_INTERFACE=web ./program.py
Serving './program.py' on http://localhost:64646

Press Ctrl+C to quit
Hello world example: web

Caveat

Should you plan to use the WebInterface, we recommend making its invocation the first thing your program does. All the statements before it run multiple times!

hello = "world"  # This line would run for every browser client!
with run(interface="web") as m:
    m.form({"one": 1})
    m.form({"two": 2})

Warning

Still in beta. We appreciate help with testing etc.