Skip to main content

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

nicegui_router-0.0.4.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

nicegui_router-0.0.4-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file nicegui_router-0.0.4.tar.gz.

File metadata

  • Download URL: nicegui_router-0.0.4.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.12

File hashes

Hashes for nicegui_router-0.0.4.tar.gz
Algorithm Hash digest
SHA256 fcd142c3f6eaedb159e187447069599cb0d3fa4c675dd9b20ed4a5b8c7a13a2b
MD5 377d77f9c6a3517dc3ea2aaca820b9c4
BLAKE2b-256 8a03b8ee3e62b4645d9a42c8fd883ae00b2364850476022f520b347160e867b3

See more details on using hashes here.

File details

Details for the file nicegui_router-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: nicegui_router-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.12

File hashes

Hashes for nicegui_router-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a0641edf5587a828e245af4d46677fbdc1745a3129d0233ea8610fa004a4b6bf
MD5 f7cbb046fc533f729d05a450f42092d4
BLAKE2b-256 428a24b839bf560fe077fadb40a12c8ce1230d0de69f1e540f4b158f48c9a126

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