Skip to main content

nicegui-autoform

tests

Render a NiceGUI web form from a command line interface.

If you already have a function wired up as a CLI, AutoForm reads that CLI's own parameter metadata -- types, defaults, help text, choices, flags -- and builds a form that calls the same function.

from nicegui import ui
from nicegui_autoform import AutoForm

AutoForm(app, command="train")  # a cyclopts App, click Command, Typer app, ...
ui.run()

Supported frameworks

Framework Install Notes
cyclopts nicegui-autoform[cyclopts] Including CLIs defined with a @dataclass
click nicegui-autoform[click]
Typer nicegui-autoform[typer]
argparse built in No callback exists, so on_submit is required
Plain @dataclass or annotated function built in No CLI framework needed

The core package depends only on NiceGUI. CLI frameworks are optional extras and are imported lazily, so nothing is imported that you do not already use.

Install

uv add "nicegui-autoform[all]"

Supported versions

Python 3.13, 3.14 and 3.15. The dependency floors below were measured by running the test suite against each version rather than guessed:

Dependency Floor Why not lower
NiceGUI 3.12 NiceGUI's own user test fixture only works from 3.12, so earlier versions cannot be verified end to end
cyclopts 4.0 3.x has a different ArgumentCollection API
click 8.1 8.0 predates the parameter metadata the adapter reads
Typer 0.13 0.12 cannot build its commands against current click

One caveat on click 8.1 and 8.2: they report an option with no default the same way as default=None, so those two cases are indistinguishable. From click 8.3 onwards an unset default is a distinct UNSET sentinel and the form can tell "no default" from "defaults to None".

How it works

Each framework has an adapter that produces a CommandSpec -- a flat list of ParamSpec leaves plus the containers needed to rebuild nested objects. Everything downstream (widget selection, validation, rendering) works on that spec alone, so all frameworks get identical behaviour and a new framework only needs a new adapter.

On submit the form validates its values against the spec and then calls the command's own function directly. It does not shell out or re-parse a command line.

Usage

Choosing a command

AutoForm(cyclopts_app, command="train")
AutoForm(typer_app, command="train")
AutoForm(click_group, command="train")

A single-command CLI needs no command=.

Overriding the callback

By default the form calls the command's own function. Pass on_submit to intercept it:

async def run(*args, **kwargs):
    ui.notify(f"running with {kwargs}")


AutoForm(app, command="train", on_submit=run)

on_submit may be sync or async. For an argparse.ArgumentParser there is no callback to default to, so on_submit is required and receives an argparse.Namespace.

Nested dataclasses

A cyclopts command taking a dataclass renders its fields as a labelled section, and the dataclass is rebuilt before the callback is called:

@dataclass
class Config:
    """Training configuration.

    Parameters
    ----------
    epochs: int
        number of epochs
    """

    data: Path
    epochs: int = 10


@app.command
def train(config: Config, seed: int = 0): ...

Help text comes from the dataclass's own numpydoc docstring, exactly as cyclopts' --help renders it.

Widgets and exclusions

from nicegui_autoform import WidgetKind

AutoForm(
    app,
    command="train",
    exclude=["debug", "config.seed"],  # bare name or dotted path
    widgets={"notes": WidgetKind.TEXTAREA},
    initial={"epochs": 50},
)

Path parameters render as a file upload by default. The upload is written to a private temporary directory under its original name, so the callback receives a real, readable Path whose .name is the file the user picked -- useful when the function derives an output name or switches on the extension. Only the basename of the client-supplied filename is ever used, so an uploaded name cannot escape that directory.

Use widgets={"out": WidgetKind.PATH_TEXT} for an output path that should be typed rather than uploaded.

Examples

Four runnable demos, one per framework:

uv run python examples/cyclopts_demo.py    # nested dataclass as a section
uv run python examples/click_demo.py       # IntRange, Choice, repeatable option
uv run python examples/typer_demo.py       # rich_help_panel as a section
uv run python examples/argparse_demo.py    # on_submit receives a Namespace

Each has a required data upload. examples/data/measurements.csv (12 rows of dose/response data) is there to drop into it, and examples/data/notes.txt shows that a non-CSV extension survives the round trip. On submit each demo reads the uploaded file and reports its name and line count, so you can see the real file reached the function.

Development

uv sync
uv run pytest
uv run ruff check
uv run ruff format
uv run ty check src tests examples

To check a dependency floor, run the suite against that exact version:

uv run --isolated --with "click==8.1.8" pytest

License

MIT

Release files for nicegui-autoform 0.1.1

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

Source distribution (sdist)

Source distribution for nicegui-autoform 0.1.1
File Size Uploaded
nicegui_autoform-0.1.1.tar.gz 127.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nicegui-autoform 0.1.1
File Interpreter ABI Platform
nicegui_autoform-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 156.6 kB

Release files / nicegui_autoform-0.1.1.tar.gz

Download URL nicegui_autoform-0.1.1.tar.gz
Size 127.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9de1f0f64d2fd73cbddbe43b23fa1e8d5325a310ae4300845f3e7b9c615034be
BLAKE2b-256 checksum
How to use checksums
397905adeb2c6379dd046149f95bdf9ed2acb7f017091e5c0a19fda524b793c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / nicegui_autoform-0.1.1-py3-none-any.whl

Download URL nicegui_autoform-0.1.1-py3-none-any.whl
Size 29.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0a88c02132408196046a08bcea065387cfc2963743648433d59e8d66905d5fbc
BLAKE2b-256 checksum
How to use checksums
55a187f94a9587fc7358d6d16cc9d154f8b2ba8f29804cbbbdbdcea6b10cc697
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

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