paramify


Nameparamify JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/luxai-qtrobot/paramify
SummaryA lightweight Python library for dynamic parameter management and runtime configuration.
upload_time2025-01-12 21:43:33
maintainerNone
docs_urlNone
authorAli PAikan
requires_python>=3.7
licenseMIT
keywords parameter management configuration dynamic runtime ui
VCS
bugtrack_url
requirements pydantic pyyaml flask
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Paramify

**Paramify** is a lightweight Python library designed to simplify dynamic parameter management. It allows developers to define, validate, and manage parameters dynamically using a JSON or YAML schema, with optional support for **command-line integration** and a **web-based parameter configuration**.

---

## Key Features

- **Dynamic Parameter Management**: Easily define and manage parameters using a simple JSON schema.
- **Command-Line Integration**: Automatically generate CLI arguments using `argparser` based on your configuration, allowing runtime overrides without separate definitions.
- **Web Interface**: Expose parameters through a user-friendly Flask-based UI for runtime configuration.
- **Validation**: Automatically validate parameters with the help of Pydantic.
- **Custom Callbacks**: Define optional callbacks to handle updates to specific parameters.
- **JSON/YAML Integration**: Load and manage parameters directly from JSON or YAML files for flexible configurations.
- **Scope-Based Control:** Specify a parameter's scope as `"runtime"`, `"cli"` and `"all"`
- **Extensible**: Developers can extend the base class to add custom behaviors.


Here is an example of the Paramify web interface:

![Paramify Web UI](https://github.com/luxai-qtrobot/paramify/raw/main/assets/ui-screenshot.png)

---

## Installation

To install Paramify, use the following command:

```bash
pip install paramify
```

---

## Quick Start

### 1. Programmatic Parameter Management

Below is an example of using Paramify for managing parameters dynamically:

```python
from logger import Logger
from paramify.paramify import Paramify

# Define optional callback functions
class MyApp(Paramify):    
    def on_param1_set(self, value):
        Logger.info(f"param1 was updated to {value}")

    def on_param2_set(self, value):
        Logger.info(f"param2 was updated to {value}")


if __name__ == '__main__':
    params = {
        "parameters": [
            {"name": "param1", "type": "bool", "label": "Enable Feature", "default": True},
            {"name": "param2", "type": "int", "label": "Integer Value", "default": 4},
        ]
    }

    app = MyApp(params)

    # Access default or loaded values
    Logger.info(app.parameters.param1)
    Logger.info(app.parameters.param2)

    # Update values and trigger callbacks
    app.set_param1(False)
    app.set_param2(23)

    # View current parameters
    Logger.info(app.get_parameters())
```

This example demonstrates how to define parameters, set values programmatically, and trigger custom callbacks.

---

### 2. Web-Based Parameter Management

Below is an example of using **ParamifyWeb** to expose parameters through a web interface:

```python
import json
from logger import Logger
from paramify.paramify_web import ParamifyWeb

# Define optional callback functions
class MyApp(ParamifyWeb):
    def on_param1_set(self, value):
        Logger.info(f"Boolean parameter was updated to {value}")

    def on_param2_set(self, value):
        Logger.info(f"Integer parameter was updated to {value}")

    def on_param3_set(self, value):
        Logger.info(f"Float parameter was updated to {value}")

    def on_param4_set(self, value):
        Logger.info(f"Selectable parameter was updated to {value}")

    def on_param5_set(self, value):
        Logger.info(f"List parameter was updated to {value}")

    def on_param6_set(self, value):
        Logger.info(f"Simple string was updated to {value}")

    def on_param7_set(self, value):
        Logger.info(f"Text area value was updated to {value}")


if __name__ == '__main__':    
    # Initialize the app with parameters from a YAML file
    app = MyApp('config.yaml')

    # Prevent the script from exiting immediately
    input("Press Enter to continue...")
```

This example demonstrates how to load parameters from a YAML file and expose them via a web interface. Callback functions are triggered when parameters are updated.

---

## YAML Configuration Example

Here is an example of a JSON configuration file:
```yaml
name: "My Example App"
description: "This is an example app to demonstrate the usage of Paramify"
parameters:
  - name: "param1"
    type: "bool"
    label: "Enable Feature"
    description: "A boolean parameter to enable or disable a feature."
    default: true
    scope: "all" # cli, runtime, all    

  - name: "param2"
    type: "int"
    label: "Integer Value"
    description: "An integer parameter for numeric configuration."
    default: 4
    ui:
      element: "slider"
      min: 1
      max: 10

  - name: "param3"
    type: "str"
    label: "Select Option"
    description: "A parameter to select from predefined options."
    default: "option 2"
    ui:
      element: "select"
      items:
        - "option 1"
        - "option 2"
        - "option 3"

```

## JSON Configuration Example

Here is an example of a JSON configuration file:

```json
{
    "name": "My Example App",
    "description": "This is an example app to demonstrate the usage of Paramify",
    "parameters": [
        {
            "name": "param1",
            "type": "bool",
            "label": "Enable Feature",
            "description": "A boolean parameter to enable or disable a feature.",
            "default": true
        },
        {
            "name": "param2",
            "type": "int",
            "label": "Integer Value",
            "description": "An integer parameter for numeric configuration.",
            "default": 4,
            "ui": {"element": "slider", "min": 1, "max": 10}
        },
        {
            "name": "param3",
            "type": "str",
            "label": "Select Option",
            "description": "A parameter to select from predefined options.",
            "default": "option 2",
            "ui": {"element": "select", "items": ["option 1", "option 2", "option 3"]}
        }
    ]
}
```

---

## Command-Line Integration
Paramify automatically generates CLI arguments based on your parameter schema, eliminating the need for separate argument definitions. Parameters defined with scope: `"cli"` or scope: `"all"` (it is the default) are included in the command-line interface, allowing users to override default values directly from the terminal.

Here is an example of the generated CLI for a simple application using Paramify:

```bash
usage: simple_params_web.py [-h] [--param1] [--param2 PARAM2] [--param3 PARAM3]

This is an example app to demonstrate the usage of Paramify

options:
  -h, --help            show this help message and exit
  --param1              A boolean parameter to enable or disable a feature.
  --param2 PARAM2       An integer parameter for numeric configuration.
  --param3 PARAM3       A parameter to select from predefined options.
```

---

## Features Overview

- **Ease of Use**: Simple, human-readable JSON schema for parameter definitions.
- **Web UI**: Manage and modify parameters in real-time through a web interface.
- **Custom Logic**: Implement application-specific callbacks for parameters.
- **JSON/YAML Support**: Load configurations from external JSON or YAML files for flexibility.

---

## Contributing

Contributions are welcome! Feel free to open issues or submit pull requests to improve this library.

---

## License

This project is licensed under the MIT License. See the `LICENSE` file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/luxai-qtrobot/paramify",
    "name": "paramify",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "parameter management configuration dynamic runtime UI",
    "author": "Ali PAikan",
    "author_email": "ali.paikan@gmail.com",
    "download_url": null,
    "platform": null,
    "description": "\r\n# Paramify\r\n\r\n**Paramify** is a lightweight Python library designed to simplify dynamic parameter management. It allows developers to define, validate, and manage parameters dynamically using a JSON or YAML schema, with optional support for **command-line integration** and a **web-based parameter configuration**.\r\n\r\n---\r\n\r\n## Key Features\r\n\r\n- **Dynamic Parameter Management**: Easily define and manage parameters using a simple JSON schema.\r\n- **Command-Line Integration**: Automatically generate CLI arguments using `argparser` based on your configuration, allowing runtime overrides without separate definitions.\r\n- **Web Interface**: Expose parameters through a user-friendly Flask-based UI for runtime configuration.\r\n- **Validation**: Automatically validate parameters with the help of Pydantic.\r\n- **Custom Callbacks**: Define optional callbacks to handle updates to specific parameters.\r\n- **JSON/YAML Integration**: Load and manage parameters directly from JSON or YAML files for flexible configurations.\r\n- **Scope-Based Control:** Specify a parameter's scope as `\"runtime\"`, `\"cli\"` and `\"all\"`\r\n- **Extensible**: Developers can extend the base class to add custom behaviors.\r\n\r\n\r\nHere is an example of the Paramify web interface:\r\n\r\n![Paramify Web UI](https://github.com/luxai-qtrobot/paramify/raw/main/assets/ui-screenshot.png)\r\n\r\n---\r\n\r\n## Installation\r\n\r\nTo install Paramify, use the following command:\r\n\r\n```bash\r\npip install paramify\r\n```\r\n\r\n---\r\n\r\n## Quick Start\r\n\r\n### 1. Programmatic Parameter Management\r\n\r\nBelow is an example of using Paramify for managing parameters dynamically:\r\n\r\n```python\r\nfrom logger import Logger\r\nfrom paramify.paramify import Paramify\r\n\r\n# Define optional callback functions\r\nclass MyApp(Paramify):    \r\n    def on_param1_set(self, value):\r\n        Logger.info(f\"param1 was updated to {value}\")\r\n\r\n    def on_param2_set(self, value):\r\n        Logger.info(f\"param2 was updated to {value}\")\r\n\r\n\r\nif __name__ == '__main__':\r\n    params = {\r\n        \"parameters\": [\r\n            {\"name\": \"param1\", \"type\": \"bool\", \"label\": \"Enable Feature\", \"default\": True},\r\n            {\"name\": \"param2\", \"type\": \"int\", \"label\": \"Integer Value\", \"default\": 4},\r\n        ]\r\n    }\r\n\r\n    app = MyApp(params)\r\n\r\n    # Access default or loaded values\r\n    Logger.info(app.parameters.param1)\r\n    Logger.info(app.parameters.param2)\r\n\r\n    # Update values and trigger callbacks\r\n    app.set_param1(False)\r\n    app.set_param2(23)\r\n\r\n    # View current parameters\r\n    Logger.info(app.get_parameters())\r\n```\r\n\r\nThis example demonstrates how to define parameters, set values programmatically, and trigger custom callbacks.\r\n\r\n---\r\n\r\n### 2. Web-Based Parameter Management\r\n\r\nBelow is an example of using **ParamifyWeb** to expose parameters through a web interface:\r\n\r\n```python\r\nimport json\r\nfrom logger import Logger\r\nfrom paramify.paramify_web import ParamifyWeb\r\n\r\n# Define optional callback functions\r\nclass MyApp(ParamifyWeb):\r\n    def on_param1_set(self, value):\r\n        Logger.info(f\"Boolean parameter was updated to {value}\")\r\n\r\n    def on_param2_set(self, value):\r\n        Logger.info(f\"Integer parameter was updated to {value}\")\r\n\r\n    def on_param3_set(self, value):\r\n        Logger.info(f\"Float parameter was updated to {value}\")\r\n\r\n    def on_param4_set(self, value):\r\n        Logger.info(f\"Selectable parameter was updated to {value}\")\r\n\r\n    def on_param5_set(self, value):\r\n        Logger.info(f\"List parameter was updated to {value}\")\r\n\r\n    def on_param6_set(self, value):\r\n        Logger.info(f\"Simple string was updated to {value}\")\r\n\r\n    def on_param7_set(self, value):\r\n        Logger.info(f\"Text area value was updated to {value}\")\r\n\r\n\r\nif __name__ == '__main__':    \r\n    # Initialize the app with parameters from a YAML file\r\n    app = MyApp('config.yaml')\r\n\r\n    # Prevent the script from exiting immediately\r\n    input(\"Press Enter to continue...\")\r\n```\r\n\r\nThis example demonstrates how to load parameters from a YAML file and expose them via a web interface. Callback functions are triggered when parameters are updated.\r\n\r\n---\r\n\r\n## YAML Configuration Example\r\n\r\nHere is an example of a JSON configuration file:\r\n```yaml\r\nname: \"My Example App\"\r\ndescription: \"This is an example app to demonstrate the usage of Paramify\"\r\nparameters:\r\n  - name: \"param1\"\r\n    type: \"bool\"\r\n    label: \"Enable Feature\"\r\n    description: \"A boolean parameter to enable or disable a feature.\"\r\n    default: true\r\n    scope: \"all\" # cli, runtime, all    \r\n\r\n  - name: \"param2\"\r\n    type: \"int\"\r\n    label: \"Integer Value\"\r\n    description: \"An integer parameter for numeric configuration.\"\r\n    default: 4\r\n    ui:\r\n      element: \"slider\"\r\n      min: 1\r\n      max: 10\r\n\r\n  - name: \"param3\"\r\n    type: \"str\"\r\n    label: \"Select Option\"\r\n    description: \"A parameter to select from predefined options.\"\r\n    default: \"option 2\"\r\n    ui:\r\n      element: \"select\"\r\n      items:\r\n        - \"option 1\"\r\n        - \"option 2\"\r\n        - \"option 3\"\r\n\r\n```\r\n\r\n## JSON Configuration Example\r\n\r\nHere is an example of a JSON configuration file:\r\n\r\n```json\r\n{\r\n    \"name\": \"My Example App\",\r\n    \"description\": \"This is an example app to demonstrate the usage of Paramify\",\r\n    \"parameters\": [\r\n        {\r\n            \"name\": \"param1\",\r\n            \"type\": \"bool\",\r\n            \"label\": \"Enable Feature\",\r\n            \"description\": \"A boolean parameter to enable or disable a feature.\",\r\n            \"default\": true\r\n        },\r\n        {\r\n            \"name\": \"param2\",\r\n            \"type\": \"int\",\r\n            \"label\": \"Integer Value\",\r\n            \"description\": \"An integer parameter for numeric configuration.\",\r\n            \"default\": 4,\r\n            \"ui\": {\"element\": \"slider\", \"min\": 1, \"max\": 10}\r\n        },\r\n        {\r\n            \"name\": \"param3\",\r\n            \"type\": \"str\",\r\n            \"label\": \"Select Option\",\r\n            \"description\": \"A parameter to select from predefined options.\",\r\n            \"default\": \"option 2\",\r\n            \"ui\": {\"element\": \"select\", \"items\": [\"option 1\", \"option 2\", \"option 3\"]}\r\n        }\r\n    ]\r\n}\r\n```\r\n\r\n---\r\n\r\n## Command-Line Integration\r\nParamify automatically generates CLI arguments based on your parameter schema, eliminating the need for separate argument definitions. Parameters defined with scope: `\"cli\"` or scope: `\"all\"` (it is the default) are included in the command-line interface, allowing users to override default values directly from the terminal.\r\n\r\nHere is an example of the generated CLI for a simple application using Paramify:\r\n\r\n```bash\r\nusage: simple_params_web.py [-h] [--param1] [--param2 PARAM2] [--param3 PARAM3]\r\n\r\nThis is an example app to demonstrate the usage of Paramify\r\n\r\noptions:\r\n  -h, --help            show this help message and exit\r\n  --param1              A boolean parameter to enable or disable a feature.\r\n  --param2 PARAM2       An integer parameter for numeric configuration.\r\n  --param3 PARAM3       A parameter to select from predefined options.\r\n```\r\n\r\n---\r\n\r\n## Features Overview\r\n\r\n- **Ease of Use**: Simple, human-readable JSON schema for parameter definitions.\r\n- **Web UI**: Manage and modify parameters in real-time through a web interface.\r\n- **Custom Logic**: Implement application-specific callbacks for parameters.\r\n- **JSON/YAML Support**: Load configurations from external JSON or YAML files for flexibility.\r\n\r\n---\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Feel free to open issues or submit pull requests to improve this library.\r\n\r\n---\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. See the `LICENSE` file for details.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A lightweight Python library for dynamic parameter management and runtime configuration.",
    "version": "0.1.2",
    "project_urls": {
        "Documentation": "https://github.com/luxai-qtrobot/paramify#readme",
        "Homepage": "https://github.com/luxai-qtrobot/paramify",
        "Source": "https://github.com/luxai-qtrobot/paramify",
        "Tracker": "https://github.com/luxai-qtrobot/paramify/issues"
    },
    "split_keywords": [
        "parameter",
        "management",
        "configuration",
        "dynamic",
        "runtime",
        "ui"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "16f654dc96adfb070e19e9585c71df7bd2c28f0b30dd055117ba70033065bcb7",
                "md5": "f05dfacae590eee1bb336e028198ef95",
                "sha256": "4488de29fb50df9038dc01154125b158051c5a7113542b92477a214cc7ef2a70"
            },
            "downloads": -1,
            "filename": "paramify-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f05dfacae590eee1bb336e028198ef95",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 403514,
            "upload_time": "2025-01-12T21:43:33",
            "upload_time_iso_8601": "2025-01-12T21:43:33.627814Z",
            "url": "https://files.pythonhosted.org/packages/16/f6/54dc96adfb070e19e9585c71df7bd2c28f0b30dd055117ba70033065bcb7/paramify-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-12 21:43:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "luxai-qtrobot",
    "github_project": "paramify",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "pydantic",
            "specs": []
        },
        {
            "name": "pyyaml",
            "specs": []
        },
        {
            "name": "flask",
            "specs": []
        }
    ],
    "lcname": "paramify"
}
        
Elapsed time: 0.40574s