Skip to main content

wizard-ui-bridge

wizard-ui-bridge is the user-interface-independent way for a wizard to ask a user questions.

A wizard asks a series of questions and turns the answers into something, often a configuration file. WizardUiBridge is the interface it asks through, so the same wizard runs on a plain console, on a full-screen Textual user interface, in a graphical user interface (Tkinter through the companion package below, or a toolkit you write a bridge for yourself), or on a scripted bridge in your tests.

Tk companion

wizard-ui-bridge has a companion wizard-tk-bridge that implements the same user-interface-independent way for a wizard to ask a user questions using a Tkinter GUI.

Is this package for you?

This package is a good fit when one or more of these apply:

  • You have a wizard, or a program that asks a user a series of questions, and you do not want the questions to be tied to one user interface.
  • You want typed questions, each with validation and re-asking: text, integer, path, yes/no, choice and multi-choice asked one at a time, and float, date, time, date and time and duration as fields of a form or cells of a matrix form.
  • You want to ask a whole form at once where the user interface can show one, and fall back to one question at a time where it cannot.
  • You want to ask a grid of values, such as one row per person and one column per weekday, as a matrix form that the user may also grow and shrink by whole rows or columns.
  • You want the user to be able to go back a step or cancel, without every question having to handle that.
  • You want a full-screen text user interface for free when the program runs in a terminal, and a plain console fallback when it does not.
  • You want your wizard to be testable without a terminal.

This package is probably not the right one when:

  • You want a general widget toolkit. Use Textual or a GUI toolkit directly.
  • You only need one input() call.

Installation

wizard-ui-bridge requires Python 3.12 or newer.

pip install --upgrade wizard-ui-bridge

Textual is optional. Install it with the extra when you want the full-screen text user interface:

pip install --upgrade 'wizard-ui-bridge[textual]'

Without the extra, everything except the Textual bridge works, and make_text_ui_bridge() returns the console bridge. Importing wizard_ui_bridge never imports Textual; it is imported the first time a Textual bridge is actually used. Asking for the Textual bridge without Textual installed raises ImportError naming the extra to install.

Quick start

Ask a small form, on the best user interface the terminal allows:

import sys

from wizard_ui_bridge import AskTextField, AskIntField, AskYesNoField, \
    make_text_ui_bridge

bridge = make_text_ui_bridge(sys.stdout, sys.stdin, sys.stderr)
answers = bridge.ask_form('Describe the export', [
    AskTextField('Report name', 'Shown as the title of the report'),
    AskIntField('Rows', 'How many rows to export', min_value=1),
    AskYesNoField('Headings', 'Write a heading row', True)])
for answer in answers:
    print(f'{answer.asking.short_question}: {answer.value}')

The same code runs as a full-screen form when Textual is installed and the program runs in a terminal, and as one console question at a time when it does not.

Ask one question at a time instead:

name = bridge.ask_text('Report name', default='report')
rows = bridge.ask_int('Rows', min_value=1)

Main entry points

  • WizardUiBridge The bridge a wizard asks through. Subclass it to connect a wizard to a user interface of your own; the base class turns the typed questions and whole-form questions into the few methods your subclass implements.

  • make_text_ui_bridge() and UiBridgeType Return the Textual bridge when Textual is installed and both streams are a terminal, and the console bridge otherwise. UiBridgeType forces one or the other.

  • WizardUiBridgeConsole Asks one question at a time on plain text streams.

  • WizardUiBridgeTextual Full-screen text user interface, needs the textual extra.

  • AskTextField, AskIntField, AskFloatField, AskPathField, AskYesNoField, AskChoiceField, AskMultiChoiceField, AskDateField, AskTimeField, AskDateTimeField, AskDurationField The typed fields a form is built from, each with a matching Answer...Field.

  • LiveFormValidator An optional callback of ask_form() that checks the form while it is filled in, and may disable fields, prefill them and show a message.

  • ask_matrix_form(), MatrixRequest and MatrixDimensions Ask a matrix form: a context setting question above a grid of cells, whose number of rows and columns may vary within the bounds of the request. The Textual and Tk bridges show the whole matrix at once; the console bridge asks one cell at a time.

  • AskLabelCell, AskTextCell, AskIntCell, AskFloatCell, AskPathCell, AskYesNoCell, AskChoiceCell, AskMultiChoiceCell, AskDateCell, AskTimeCell, AskDateTimeCell, AskDurationCell The cells a matrix form is built from, each input cell with a matching Answer...Cell. Each Ask...Field derives from its Ask...Cell.

  • WizardBack, WizardAbort, WizardCancelLevel, WizardNavigation How a user asks to go back a step or to give up, without every question having to handle it.

  • TableColumn, TableCell and ask_table() Ask for a small table of values, with a fixed or variable number of rows. The base ask_table() asks the table as a matrix form.

  • textual_installed() and load_textual_bridge() Ask whether the optional Textual bridge can be used, and get the class when it can.

Writing your own bridge

A bridge of your own subclasses WizardUiBridge and implements the few asking methods. The modules wizard_ui_bridge.bridge_helpers, wizard_ui_bridge.form_helpers and wizard_ui_bridge.matrix_helpers hold the helpers the bundled bridges use to interpret raw answers and to build form and matrix answers, so that a bridge of your own behaves the same way.

Source code repo history

The two git repos https://github.com/tom-bjorkholm/wizard-ui-bridge and https://github.com/tom-bjorkholm/tableio_cfg_json share a common history. Up until version 1.1 there was only one repo. Now that repo is split in two, and each repo holds only code for its package. However, both repos have the common history.

Documentation

Deprecations

Each deprecated use below still works and issues a DeprecationWarning. All of them will be removed in version 2.0.

  • partial_validator of ask_form() and ask_form_w_fake(), and its type PartialFormValidator (the type itself issues no warning). Use live_validator with the type LiveFormValidator instead. A live validator gets None as the changed row index when no row has changed yet, for instance when the form is first shown; a partial_validator gets 0 there instead. Passing both raises TypeError. A bridge that overrides ask_form() should accept both until 2.0, combining them with wizard_ui_bridge.form_helpers.live_validator_of(), which will be removed in 2.0 as well. ask_form_w_fake() passes the validator as partial_validator to an ask_form() override that does not accept live_validator.
  • A bridge ask method without the keyword-only help_text. A typed ask method, or an AskReader of the table helpers, that does not accept help_text is called without it.
  • A typed ask method without the keyword-only start_value. Such a method is called with the start value as its default instead, and not nullable, so the user cannot empty the answer.

License

MIT

Test summary

  • Test result: 2066 passed, 9 deselected in 63s (0:01:03)
  • No flake8 warnings.
  • No mypy errors found.
  • No pylint warnings.
  • No python layout warnings.
  • Built version(s): 1.6
  • Build and test using Python 3.15.2

Metadata

Release files for wizard-ui-bridge 1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wizard-ui-bridge 1.6
File Size Uploaded Provenance Actions
wizard_ui_bridge-1.6.tar.gz 96.0 kB Without provenance Details for wizard_ui_bridge-1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wizard-ui-bridge 1.6
File Interpreter ABI Platform Actions
wizard_ui_bridge-1.6-py3-none-any.whl Python 3 none any Details for wizard_ui_bridge-1.6-py3-none-any.whl

Total release size: 204.1 kB

Release files / wizard_ui_bridge-1.6.tar.gz

Download URL wizard_ui_bridge-1.6.tar.gz
Size 96.0 kB
Tags Source
SHA-256 checksum
How to use checksums
129a8affc06bbe24f907fcbba73d0b8d368c9ae6d84eced79b5dd9c0cec9e7e3
BLAKE2b-256 checksum
How to use checksums
71e0b8319daf216ce7abc9c2079cd1ea8cd039675ceee3799b7bd1f2661cbac0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / wizard_ui_bridge-1.6-py3-none-any.whl

Download URL wizard_ui_bridge-1.6-py3-none-any.whl
Size 108.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bdf7d8cc2ac65f8b797966ec1d18d3305d8e6770be9de3146d97900fd36c58ee
BLAKE2b-256 checksum
How to use checksums
44657e0333f83fa681eaf26ed4887467d8ad893ce07d55358712cb57ea896e1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for wizard-ui-bridge 1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page