NiceGUI-UGForm
Form Builder Component for NiceGUI Framework
适用于 NiceGUI 框架的表单构建器组件
Introduction
This Python library provides a flexible form builder for the NiceGUI framework. It allows the user to create a user-generated form (UGForm) via NiceGUI, easily serialize/deserialize form schemas and display them.
Features
- Easy Serialization: Export/import form schemas as JSON or compressed Base64 strings.
- Interactive UI: Built-in form editor and display components for NiceGUI.
- Built-in I18N: Supports multiple languages (currently English and Chinese).
- Well-Designed: Follows best practices such as type annotations.
Currently supported field types:
| Field Type | Validation Approaches |
|---|---|
| TextField | min/max length, regex pattern |
| IntegerField | min/max value |
| FloatField | min/max value |
| BooleanField | - |
Demo
See demo.py for a complete example about what can it do.
| Form Editor | Form Display |
|---|---|
Changelog
See CHANGELOG.md to understand the changes of every release version.
Get Started
Installation
Install from PyPI:
pip install nicegui_ugform
Minimal Example
Here's a simple example to get started:
from nicegui import ui
from nicegui_ugform import Form, FormEditor, FormDisplay, TextField, IntegerField
# Create a form
form = Form(
title="Registration Form",
description="Please fill out your information",
locale="en" # or "zh_cn" for Chinese
)
# Add fields
form.add_field(TextField(
name="username",
label="Username",
required=True,
min_length=3,
max_length=20
))
form.add_field(IntegerField(
name="age",
label="Age",
required=True,
min_value=18,
max_value=120
))
# Create pages
@ui.page('/')
def index():
# Form Editor - allows users to modify form structure
editor = FormEditor(form)
editor.render()
@ui.page('/display')
def display():
# Form Display - shows the form to end users
def on_submit():
data = form.dump_data()
print("Submitted data:", data)
display = FormDisplay(form, on_submit=on_submit)
display.render()
ui.run()
Usage
Schema Serialization
You can export and import form schemas:
# Export as JSON
schema = form.dump_schema()
# Export as compressed Base64
schema_b64 = form.dump_schema_b64(compression_flag=1)
# Import from JSON
loaded_form = Form.load_schema(schema)
# Import from Base64
loaded_form = Form.load_schema_b64(schema_b64)
I18N Support
You can use different locales for the form editor and display:
from nicegui_ugform import FormEditor, I18nHelper
# Get available locales
locales = I18nHelper.get_available_locales()
for loc in locales:
print(f"{loc.name}: {loc.code}") # English: en, Chinese (Simplified): zh_cn
# Use specific locale
editor = FormEditor(form, locale="zh_cn")
# Form locale is saved in schema and auto-applied on display
form.locale = "zh_cn"
display = FormDisplay(form) # Will use zh_cn automatically
Field Types
TextField - Text input with validation
TextField(
name="email",
label="Email",
required=True,
regex=r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
)
IntegerField - Integer number input
IntegerField(
name="age",
label="Age",
min_value=0,
max_value=150
)
FloatField - Decimal number input
FloatField(
name="height",
label="Height (m)",
min_value=0.0,
max_value=3.0
)
BooleanField - Checkbox input
BooleanField(
name="subscribe",
label="Subscribe to newsletter",
default_value=False
)
Licensing
This project is licensed under the MIT License. See the License file for more details.
Metadata
Release files for NiceGui-UGForm 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nicegui_ugform-1.1.1.tar.gz | 14.7 kB | Without provenance | Details for nicegui_ugform-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nicegui_ugform-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for nicegui_ugform-1.1.1-py3-none-any.whl |
Total release size: 34.1 kB
Release files / nicegui_ugform-1.1.1.tar.gz
| Download URL | nicegui_ugform-1.1.1.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6901f93e156f7ca810560c6a596d3b6347c480d46165524239ad5f0627f0b094
|
|
BLAKE2b-256 checksum How to use checksums |
bbe734c1187a2c019bb0982d52b328c8bf155ac776ea73d94f7f7e5133742548
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.12.9 Windows/11
|
Release files / nicegui_ugform-1.1.1-py3-none-any.whl
| Download URL | nicegui_ugform-1.1.1-py3-none-any.whl |
|---|---|
| Size | 19.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a07d23e5613b4eda8f396c62caf379727b3d228a2055ecd00bbdd2e0f95c6da
|
|
BLAKE2b-256 checksum How to use checksums |
f940280052b8a7a36b3997f27f12d1322efed690cc7e268e49710a3e31109842
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.12.9 Windows/11
|
Security for NiceGui-UGForm 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.