File-based routing and theming for NiceGUI, bringing structured navigation and consistent page themes
Project description
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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nicegui_router-0.0.1.tar.gz.
File metadata
- Download URL: nicegui_router-0.0.1.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf40d9a8339e7f271d1ccd5cc69d1fb12fcd3686640cf151ceba3d51ac6646c8
|
|
| MD5 |
8f05e44589a83216fdaaf048ff10250f
|
|
| BLAKE2b-256 |
e9200aaf1b9da2b0954ac0bc3fcb9d0d611b58ca2eae92164eb90b63ee8dc429
|
File details
Details for the file nicegui_router-0.0.1-py3-none-any.whl.
File metadata
- Download URL: nicegui_router-0.0.1-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7349005f48070296b63c69d86f28941e2582ca83175304a8191c0bde18852c18
|
|
| MD5 |
0c0b249c47d244f06939c44b1eda75ef
|
|
| BLAKE2b-256 |
8684dbcffc6d92b72d9aecf568d08d324b2b5aceec2b7824b9a7568e0f0c8d60
|