nicegui-router
File-based routing and theming for NiceGUI, bringing structured navigation and consistent page themes.
Features
- File-Based Routing: Automatically organize your application routes using a file-based structure, making navigation in NiceGUI applications clean and scalable.
- Theming Support: Apply consistent UI themes across your NiceGUI application for a uniform user experience.
- WebSocket and HTTP Route Decorators: Easy route handling with support for WebSockets and RESTful HTTP methods.
- JWT Authentication: Built-in support for authenticated routes to secure your application.
- Dynamic Route Loading: Dynamically register routes from specified directories, streamlining development workflow.
- Custom Error Handling: Log and manage route errors efficiently.
- NiceGUI Integration: Seamlessly integrated with the NiceGUI environment for web application development.
Usage
This package is designed to simplify the development of applications using NiceGUI by enabling file-based routing and consistent theming. Below is a demonstration of how to set up a simple application using nicegui-router.
Example Project Structure
my_nicegui_app/
├── main.py
└── routes
├── home.py
└── about.py
└── counter.py
Example Code
main.py
from nicegui_router import Server
from pathlib import Path
# Initialize the router with the directory containing your route files
server = Server(
title='Example Server',
routes_dir=Path(__file__).parent / "routes"
)
# Get the Fastapi app instance (for advanced use cases)
app = server.app
# Start the server if the script is run directly
if __name__ == '__main__':
server.listen(port=8080)
routes/index.py
from nicegui_router import page, ui
@page('/')
def home():
ui.markdown("Welcome to the Home Page!")
routes/about.py
from nicegui_router import page, ui, theme
customTheme = theme(
{
'primary': '#FF5733', # orange
'secondary': '#33FF57', # green
'accent': '#3357FF'
}, font="Lato")
@page(theme=customTheme)
def about():
ui.markdown("About Us Page themed with custom colors.")
routes/counter.py
from nicegui_router import page, ui, theme, component, use_state
customTheme = theme(
{
'primary': '#FF5733', # orange
'secondary': '#33FF57', # green
'accent': '#3357FF'
}, font="Lato")
@page(theme=customTheme)
def counter():
# custom component with state reactivity support
@component
def customCounter():
count, setCount = use_state(0)
return ui.button(f"Count: {count}").on("click", lambda: setCount(count + 1))
with ui.header():
title = ui.label("Example 2")
ui.space()
customCounter()
ui.markdown("Custom component with state reactivity.")
Starting the Server
To start the server, simply run the following command in your terminal from the project's root directory:
python example/main.py
Navigate to http://localhost:8080 to see your NiceGUI application in action.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Release files for nicegui-router 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nicegui_router-0.0.4.tar.gz | 14.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nicegui_router-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.7 kB
Release files / nicegui_router-0.0.4.tar.gz
| Download URL | nicegui_router-0.0.4.tar.gz |
|---|---|
| Size | 14.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fcd142c3f6eaedb159e187447069599cb0d3fa4c675dd9b20ed4a5b8c7a13a2b
|
|
BLAKE2b-256 checksum How to use checksums |
8a03b8ee3e62b4645d9a42c8fd883ae00b2364850476022f520b347160e867b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.12
|
Release files / nicegui_router-0.0.4-py3-none-any.whl
| Download URL | nicegui_router-0.0.4-py3-none-any.whl |
|---|---|
| Size | 14.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a0641edf5587a828e245af4d46677fbdc1745a3129d0233ea8610fa004a4b6bf
|
|
BLAKE2b-256 checksum How to use checksums |
428a24b839bf560fe077fadb40a12c8ce1230d0de69f1e540f4b158f48c9a126
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.12
|