Turn your Python CLI program into a modern web-based UI
Project description
NiceGooey
Turn your Python CLI program into a modern web-based UI
Based on Gooey and created using nicegui, NiceGooey transforms your CLI tool written with Python's argparse into a modern web UI with just a single line of code.
(NiceGooey is currently released as a Beta. It is functional and no major refactorings are planned, but some breaking changes and bug might happen.)
This project is published at Codeberg and mirrored to GitHub. It is available on PyPi as nicegooey.
Minimal example
Just importing and adding the annotation @nice_gooey_argparse_main(patch_argparse=True) to your main function is
enough to start using NiceGooey.
from nicegooey.argparse import nice_gooey_argparse_main
import argparse
@nice_gooey_argparse_main(patch_argparse=True)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--my-name", type=str, required=True)
namespace = parser.parse_args()
print(f"Hi, {namespace.my_name}")
Without using NiceGooey, this is a simple command line tool for which the call tool --my-name=Max would print Hi, Max to the terminal.
With NiceGooey, this renders a web page with a text input and a submit button that shows "Hi, Max" in your browser.
More control by using NgArgumentParser
If the simple one-liner patch is not enough for you, a more type-safe and configurable version of NiceGooey
can be used by using the NgArgumentParser class instead of argparse.ArgumentParser.
See below for more info about nicegooey_config.
from nicegooey.argparse import nice_gooey_argparse_main, NgArgumentParser, NiceGooeyConfig
from nicegooey.argparse.ui_classes.actions.action_alternatives import store_action_slider
@nice_gooey_argparse_main(patch_argparse=False)
def main1(*args, **kwargs):
parser = NgArgumentParser()
my_name_action = parser.add_argument("--my-name", type=str, required=True)
my_age_action = parser.add_argument("--my-age", type=int, required=True)
parser.nicegooey_config = NiceGooeyConfig(
root_card_class="max-w-4xl", # don't take up the entire screen on wide desktops
action_element_overrides={
# Display the age as a slider instead of a number field.
my_age_action: store_action_slider(min=0, max=100, step=1)
}
)
namespace = parser.parse_args()
print(f"Hi, {namespace.my_name}")
Configuring your application
By setting the nicegooey_config field of an NgArgumentParser instance, you can configure the style and behavior of your page.
NiceGooeyConfig
root_card_class
A space-separated list of Tailwind classes to be applied to the root of the argument UI.
Especially useful to pass something like 'w-4xl' to limit the width on large screens.
action_config
A dict that maps parser action objects to ActionConfig classes.
Use this to set configurations affecting individual actions.
ActionConfig
element_override
If set, this class is instantiated to display the widget for this element in the UI instead of the default.
For example, use this to render a slider with min and max limits, instead of a numeric input field.
Look at nicegooey.argparse.ui_classes.actions.action_alternatives for predefined options.
validation
A callable that is run when "Submit" is pressed. The value of the action is passed as the argument.
If the function returns a string, the process is stopped and the string is shown as an error.
License
NiceGooey is published under LGPL. You are almost certainly allowed to use it for whatever your use case is, but are required to publish a copy of LGPL with it. This is covered by NiceGooey already, which shows a "License" button at the bottom of the page.
Artificial Intelligence
Generative AI and coding agents being a hot topic at the moment, especially in Open Source projects, this section is about disclosing any use of AI within this project, for anyone who is intersted:
- There is no AI of any kind being called from the NiceGooey code itself.
- Anthropic's Claude Code was used in some occasions of:
- writing unit tests
- creating showcase examples
- refactorings on the implementation
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 nicegooey-1.0.0b2.tar.gz.
File metadata
- Download URL: nicegooey-1.0.0b2.tar.gz
- Upload date:
- Size: 38.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caa77364438d9529420fc312c2071f478dd4b8db5e7f6782e2d8af024cd003f1
|
|
| MD5 |
eb9c6332adb20d1958fc7e165e37cd39
|
|
| BLAKE2b-256 |
8755baf3bd1113190c19ddb93aa56121d1acc9d1175491e9598037723eb112c7
|
File details
Details for the file nicegooey-1.0.0b2-py3-none-any.whl.
File metadata
- Download URL: nicegooey-1.0.0b2-py3-none-any.whl
- Upload date:
- Size: 47.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19b0329818dd1450e169cba0b06d0ff91cedf3edf254007c44a050ede0a4d209
|
|
| MD5 |
368386b9dd9af2a651412fc1ba249ee8
|
|
| BLAKE2b-256 |
21eaa6685e7223883498e830aa3e4f2ccbe6a77b164f4e609f85c648b3ea8518
|