NiceGUI
NiceGUI is an open-source Python library for creating web-based user interfaces. It follows a backend-first philosophy, handling web development details like HTML, CSS, and JavaScript, allowing developers to focus on Python code. It's actively maintained with frequent releases, providing a wide range of UI elements, data binding, and the ability to run as a web server or in a native desktop window. The current version is 3.10.0.
Warnings
- breaking Since v3.8.0, `run_method()` and `run_*_method()` no longer accept arbitrary JavaScript expressions as method names. Only actual method names are supported for security reasons.
- breaking In v3.0.0, the `ui.html` element now requires a `sanitize` argument to prevent Cross-Site Scripting (XSS) attacks. `ui.chat_message` also has this argument, especially if `text_html=True`.
- gotcha Several security vulnerabilities related to Cross-Site Scripting (XSS) via unsanitized user input (e.g., in `ui.markdown()`, user-defined links, and sub-pages) have been addressed across multiple versions (v3.5.0, v3.7.0). Always sanitize or validate any user-provided content before rendering it.
- gotcha Vulnerabilities related to file handling (e.g., filename sanitization bypass in `ui.upload` v3.10.0, path traversal via `FileUpload.name` v3.7.0, and arbitrary file access via `app.add_media_files` v3.4.0) have been reported. Be cautious when exposing uploaded or local files.
- breaking With v3.0.0, the `ui.element.tailwind` API was removed. Upgrading to Tailwind 4 also introduced some breaking changes in layout and styling.
- breaking In NiceGUI 3.0, you must directly modify `table.rows`, `table.columns`, or `aggrid.options` instead of using methods like `table.add_rows()` to update table data.
- gotcha Memory exhaustion via media streaming routes (v3.9.0) was a security vulnerability. Ensure your application handles media streaming efficiently and is updated to prevent such resource attacks.
Install
-
pip install nicegui
Imports
- ui
from nicegui import ui
- app
from nicegui import ui, app
Quickstart
from nicegui import ui
ui.label('Hello NiceGUI!')
ui.button('Click me!', on_click=lambda: ui.notify('Hello from NiceGUI!'))
ui.run()