Skip to main content

Web User Interface with Buttons, Dialogs, Markdown, 3D Scences and Plots

Project description

NiceGUI

NiceGUI is an easy-to-use, Python-based UI framework, which renders to the web browser. You can create buttons, dialogs, markdown, 3D scenes, plots and much more.

It is great for micro web apps, dashboards, robotics projects, smart home solutions and similar use cases. You can also use it in development, for example when tweaking/configuring a machine learning algorithm or tuning motor controllers.

NiceGUI is available as PyPI package, Docker image and on GitHub.

PyPI version PyPI - Downloads Docker Pulls
GitHub commit activity GitHub issues GitHub forks GitHub stars GitHub license

Features

  • browser-based graphical user interface
  • implicit reload on code change
  • standard GUI elements like label, button, checkbox, switch, slider, input, file upload, ...
  • simple grouping with rows, columns, cards and dialogs
  • general-purpose HTML and markdown elements
  • powerful high-level elements to
    • plot graphs and charts,
    • render 3D scenes,
    • get steering events via virtual joysticks
    • annotate and overlay images
    • interact with tables
    • navigate foldable tree structures
  • built-in timer to refresh data in intervals (even every 10 ms)
  • straight-forward data binding to write even less code
  • notifications, dialogs and menus to provide state of the art user interaction
  • shared and individual web pages
  • ability to add custom routes and data responses
  • capture keyboard input for global shortcuts etc
  • customize look by defining primary, secondary and accent colors
  • live-cycle events and session data

Installation

python3 -m pip install nicegui

Usage

Write your nice GUI in a file main.py:

from nicegui import ui

ui.label('Hello NiceGUI!')
ui.button('BUTTON', on_click=lambda: ui.notify('button was pressed'))

ui.run()

Launch it with:

python3 main.py

The GUI is now available through http://localhost:8080/ in your browser. Note: The script will automatically reload the page when you modify the code.

Full documentation can be found at https://nicegui.io.

Configuration

You can call ui.run() with optional arguments:

  • host (default: '0.0.0.0')
  • port (default: 8080)
  • title (default: 'NiceGUI')
  • favicon (default: 'favicon.ico')
  • dark: whether to use Quasar's dark mode (default: False, use None for "auto" mode)
  • main_page_classes: configure Quasar classes of main page (default: 'q-ma-md column items-start')
  • binding_refresh_interval: time between binding updates (default: 0.1 seconds, bigger is more cpu friendly)
  • show: automatically open the ui in a browser tab (default: True)
  • reload: automatically reload the ui on file changes (default: True)
  • uvicorn_logging_level: logging level for uvicorn server (default: 'warning')
  • uvicorn_reload_dirs: string with comma-separated list for directories to be monitored (default is current working directory only)
  • uvicorn_reload_includes: string with comma-separated list of glob-patterns which trigger reload on modification (default: '.py')
  • uvicorn_reload_excludes: string with comma-separated list of glob-patterns which should be ignored for reload (default: '.*, .py[cod], .sw.*, ~*')
  • exclude: comma-separated string to exclude elements (with corresponding JavaScript libraries) to save bandwidth (possible entries: chart, colors, custom_example, interactive_image, keyboard, log, joystick, scene, table)

The environment variables HOST and PORT can also be used to configure NiceGUI.

To avoid the potentially costly import of Matplotlib, you set the environment variable MATPLOTLIB=false. This will make ui.plot and ui.line_plot unavailable.

Note: The parameter exclude from earlier versions of NiceGUI has been removed. Libraries are now automatically served on demand. As a small caveat, the page will be reloaded if a new dependency is added dynamically, e.g. when adding a ui.chart only after pressing a button.

Docker

You can use our multi-arch Docker image for pain-free installation:

docker run --rm -p 8888:8080 -v $(pwd):/app/ -it zauberzeug/nicegui:latest

This will start the server at http://localhost:8888 with the code from your current directory. The file containing your ui.run(port=8080, ...) command must be named main.py. Code modification triggers an automatic reload.

Why?

We like Streamlit but find it does too much magic when it comes to state handling. In search for an alternative nice library to write simple graphical user interfaces in Python we discovered JustPy. While it is too "low-level HTML" for our daily usage, it provides a great basis for NiceGUI.

Documentation and Examples

The API reference is hosted at https://nicegui.io. It is implemented with NiceGUI itself. You may also have a look at examples.py for more demonstrations of what you can do with NiceGUI.

Abstraction

NiceGUI is based on JustPy which is based on the ASGI framework Starlette and the ASGI webserver Uvicorn.

Deployment

To deploy your NiceGUI app, you will need to execute your main.py (or whichever file contains your ui.run(...)) on your server infrastructure. You can either install the NiceGUI python package via pip on the server or use our pre-built Docker image which contains all necessary dependencies. For example you can use this docker run command to start the script main.py in the current directory on port 80:

docker run -p 80:8080 -v $(pwd)/:/app/ -d --restart always zauberzeug/nicegui:latest

The example assumes main.py uses the port 8080 in the ui.run command (which is the default). The --restart always makes sure the container is restarted if the app crashes or the server reboots. Of course this can also be written in a docker compose file:

nicegui:
  image: zauberzeug/nicegui:latest
  restart: always
  ports:
    - 80:8080
  volumes:
    - ./:/app/

While it is possible to provide SSL certificates directly through NiceGUI (using JustPy config), we also like reverse proxies like Traefik or NGINX. See our docker-compose.yml as an example.

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

nicegui-0.9.1.tar.gz (4.6 MB view details)

Uploaded Source

Built Distribution

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

nicegui-0.9.1-py3-none-any.whl (4.7 MB view details)

Uploaded Python 3

File details

Details for the file nicegui-0.9.1.tar.gz.

File metadata

  • Download URL: nicegui-0.9.1.tar.gz
  • Upload date:
  • Size: 4.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.10.6 Linux/5.15.0-1019-azure

File hashes

Hashes for nicegui-0.9.1.tar.gz
Algorithm Hash digest
SHA256 b664c37ba48e4ca89e87e28a5e8c4c5601b3cf10e164293e07d7fd59be8fd3f6
MD5 96c8cb9c500e1312ff793a18e143d5cb
BLAKE2b-256 143513c0a7161cdb63e7281be714ecf6c0c7f3cab9cb560fe58519282bf650c0

See more details on using hashes here.

File details

Details for the file nicegui-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: nicegui-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.10.6 Linux/5.15.0-1019-azure

File hashes

Hashes for nicegui-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4293a48e43fe8a3c1f75f93ee360c2b5257e9174443dacab2f3840a2cea8cbd7
MD5 33f4a58666ce5106d3930b99caedfa78
BLAKE2b-256 745d1addf393299a5192c5386dbbe7dfa5fcb1deee10e19faca1631cc805e6f8

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