Skip to main content

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

Screenshot of the UI displaying an example application

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.

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.

Screenshot of the UI displaying an example application

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}")

Screenshot of the UI displaying an example application

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 chat was used when planning ideas, implementations, and troubleshooting of the implementation.
  • Anthropic's Claude Code was used occasionally to write unit tests and perform refactorings on the implementation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nicegooey-1.0.0b1.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nicegooey-1.0.0b1-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

Details for the file nicegooey-1.0.0b1.tar.gz.

File metadata

  • Download URL: nicegooey-1.0.0b1.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","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

Hashes for nicegooey-1.0.0b1.tar.gz
Algorithm Hash digest
SHA256 8ef3515c54476dca73aeb8857bc68452c6ac6000c276755631bad119a5d36609
MD5 e28244b3a0dd42b35d49f27c048977c4
BLAKE2b-256 0b80e513d05bb6bc790d6d63d33d13e9e1847dfefeb5ef9601c64502f37536d7

See more details on using hashes here.

File details

Details for the file nicegooey-1.0.0b1-py3-none-any.whl.

File metadata

  • Download URL: nicegooey-1.0.0b1-py3-none-any.whl
  • Upload date:
  • Size: 40.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","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

Hashes for nicegooey-1.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 b0e355367ef5daf271c09c94974f0c14847d3add7796155c3e2073665250e8d5
MD5 6ae72b64f467bf206b0222469425023f
BLAKE2b-256 bc65874e03a84ef69782c1d2779c24f55942e3a83db51e2b3415acd68f3b73dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page