nicegui-router


Namenicegui-router JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/puntorigen/nicegui-router
SummaryFile-based routing and theming for NiceGUI, bringing structured navigation and consistent page themes
upload_time2025-01-10 01:40:32
maintainerNone
docs_urlNone
authorPablo Schaffner
requires_python>=3.6
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```plaintext
my_nicegui_app/
├── main.py
└── routes
    ├── home.py
    └── about.py
    └── counter.py
```

### Example Code

#### `main.py`
```python
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`
```python
from nicegui_router import page, ui

@page('/')
def home():
    ui.markdown("Welcome to the Home Page!")
```

#### `routes/about.py`
```python
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`
```python
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:
```bash
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](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/puntorigen/nicegui-router",
    "name": "nicegui-router",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Pablo Schaffner",
    "author_email": "pablo@puntorigen.com",
    "download_url": "https://files.pythonhosted.org/packages/7e/b5/d3dce82f7eb4fb486bea35afb705520a25826cb2bc0ab3c47993299b57ef/nicegui_router-0.0.3.tar.gz",
    "platform": null,
    "description": "# nicegui-router\n\nFile-based routing and theming for NiceGUI, bringing structured navigation and consistent page themes.\n\n## Features\n- **File-Based Routing**: Automatically organize your application routes using a file-based structure, making navigation in NiceGUI applications clean and scalable.\n- **Theming Support**: Apply consistent UI themes across your NiceGUI application for a uniform user experience.\n- **WebSocket and HTTP Route Decorators**: Easy route handling with support for WebSockets and RESTful HTTP methods.\n- **JWT Authentication**: Built-in support for authenticated routes to secure your application.\n- **Dynamic Route Loading**: Dynamically register routes from specified directories, streamlining development workflow.\n- **Custom Error Handling**: Log and manage route errors efficiently.\n- **NiceGUI Integration**: Seamlessly integrated with the NiceGUI environment for web application development.\n\n## Usage\n\nThis 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`.\n\n### Example Project Structure\n\n```plaintext\nmy_nicegui_app/\n\u251c\u2500\u2500 main.py\n\u2514\u2500\u2500 routes\n    \u251c\u2500\u2500 home.py\n    \u2514\u2500\u2500 about.py\n    \u2514\u2500\u2500 counter.py\n```\n\n### Example Code\n\n#### `main.py`\n```python\nfrom nicegui_router import Server\nfrom pathlib import Path\n\n# Initialize the router with the directory containing your route files\nserver = Server(\n    title='Example Server', \n    routes_dir=Path(__file__).parent / \"routes\"\n)\n\n# Get the Fastapi app instance (for advanced use cases)\napp = server.app\n\n# Start the server if the script is run directly\nif __name__ == '__main__':\n    server.listen(port=8080)\n```\n\n#### `routes/index.py`\n```python\nfrom nicegui_router import page, ui\n\n@page('/')\ndef home():\n    ui.markdown(\"Welcome to the Home Page!\")\n```\n\n#### `routes/about.py`\n```python\nfrom nicegui_router import page, ui, theme\n\ncustomTheme = theme(\n    {\n        'primary': '#FF5733', # orange\n        'secondary': '#33FF57', # green\n        'accent': '#3357FF'\n    }, font=\"Lato\")\n\n@page(theme=customTheme)\ndef about():\n    ui.markdown(\"About Us Page themed with custom colors.\")\n```\n\n#### `routes/counter.py`\n```python\nfrom nicegui_router import page, ui, theme, component, use_state\n\ncustomTheme = theme(\n    {\n        'primary': '#FF5733', # orange\n        'secondary': '#33FF57', # green\n        'accent': '#3357FF'\n    }, font=\"Lato\")\n\n@page(theme=customTheme)\ndef counter():\n    # custom component with state reactivity support\n    @component\n    def customCounter():\n        count, setCount = use_state(0)\n        return ui.button(f\"Count: {count}\").on(\"click\", lambda: setCount(count + 1))\n\n    with ui.header():\n        title = ui.label(\"Example 2\")\n        ui.space()\n        customCounter()\n    ui.markdown(\"Custom component with state reactivity.\")\n```\n\n### Starting the Server\nTo start the server, simply run the following command in your terminal from the project's root directory:\n```bash\npython example/main.py\n```\n\nNavigate to `http://localhost:8080` to see your NiceGUI application in action.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "File-based routing and theming for NiceGUI, bringing structured navigation and consistent page themes",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/puntorigen/nicegui-router"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "90d5fd97690f73bdc475686703ee4187d29086bc7ff4f4b394070edf027e7208",
                "md5": "6fb8d257e835e35435e539059e83506c",
                "sha256": "e61d55eea965581b7a0a6ebfeedf1c3c2abfe9cba90f68ab79c463233942afa7"
            },
            "downloads": -1,
            "filename": "nicegui_router-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6fb8d257e835e35435e539059e83506c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 14403,
            "upload_time": "2025-01-10T01:40:30",
            "upload_time_iso_8601": "2025-01-10T01:40:30.032433Z",
            "url": "https://files.pythonhosted.org/packages/90/d5/fd97690f73bdc475686703ee4187d29086bc7ff4f4b394070edf027e7208/nicegui_router-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7eb5d3dce82f7eb4fb486bea35afb705520a25826cb2bc0ab3c47993299b57ef",
                "md5": "499e08f5150ac7117a2fc2b3c4e2243f",
                "sha256": "a9d9798085ef9f3e673f8a3cdf162b9b8d40ecc8f468f77d3cb0dd3f26bd6869"
            },
            "downloads": -1,
            "filename": "nicegui_router-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "499e08f5150ac7117a2fc2b3c4e2243f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 14158,
            "upload_time": "2025-01-10T01:40:32",
            "upload_time_iso_8601": "2025-01-10T01:40:32.324725Z",
            "url": "https://files.pythonhosted.org/packages/7e/b5/d3dce82f7eb4fb486bea35afb705520a25826cb2bc0ab3c47993299b57ef/nicegui_router-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-10 01:40:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "puntorigen",
    "github_project": "nicegui-router",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "nicegui-router"
}
        
Elapsed time: 1.02753s