Name | iot-edge-validator JSON |
Version |
1.0.5
JSON |
| download |
home_page | |
Summary | IoT Edge Validator Library for Python |
upload_time | 2022-08-17 18:58:32 |
maintainer | |
docs_url | None |
author | Dylan Gonzales |
requires_python | >=3.7 |
license | MIT License |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# iot-edge-validator
[](https://img.shields.io/badge/python_v3.9-blue?logo=python&logoColor=yellow) [](https://img.shields.io/badge/pre--commit-blue?logo=pre-commit&logoColor=FAB040) [](https://img.shields.io/badge/keep_a_changelog-blue?logo=keepachangelog&logoColor=E05735) [](https://img.shields.io/badge/GitHub_Actions-blue?logo=githubactions&logoColor=black) [](https://img.shields.io/badge/PyPI-blue?logo=pypi&logoColor=yellow) [](https://img.shields.io/badge/azure_iot_device-v2.11.0-blue?logo=microsoft-azure&logoColor=black)
This package is a wrapper around the [azure-iot-device](https://pypi.org/project/azure-iot-device/) SDK to provide standardized exception handling and direct method request validation.
[Official Documentation](https://py-iot-utils.azurewebsites.net/packages/iotEdgeValidator) | [Source code](https://github.com/dgonzo27/py-iot-utils/tree/master/iot-edge-validator) | [Package PyPI](https://pypi.org/project/iot-edge-validator/)
## Table of Contents
- [Versioning](#versioning)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Basic Examples](#basic-examples)
## Versioning
This repository adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). It will be maintained through the `CHANGELOG.md` and in GitHub Releases. **It's important to note** that you must maintain the version with your releases in `iot/edge/validator/_version.py`, otherwise a new package version will fail to get published.
## Getting Started
This section provides basic examples with the `iot-edge-validator`.
### Prerequisites
- Python 3.7 or later is required to use this package.
- You must have an Azure subscription and Azure IoT Edge Device to use this package.
### Basic Examples
1. Install via [pip](https://pypi.org/project/pip/):
```sh
pip install iot-edge-validator
```
2. Import and say hello:
```python
from iot.edge.validator import __version__
print(f"hello world from iot-edge-validator version: {__version__}")
```
3. Basic usage:
```python
from typing import Any, Dict, Union
from azure.iot.device.iothub.models.methods import MethodRequest, MethodResponse
from iot.edge.validator import (
format_exception_error,
generate_error_response,
compare_dictionary,
)
EXPECTED_METHOD_NAME: str = "some_method_name"
EXPECTED_METHOD_PAYLOAD: Dict[str, Any] = {
"some": {},
"expected": {},
"payload": {},
}
def validate_method_requests(method_request: MethodRequest) -> Union[MethodResponse, None]:
"""validation handler for some_method_name listener"""
if method_request.name == EXPECTED_METHOD_NAME:
pass
else:
return generate_error_response(method_request,
f"received unknown method request for {method_request.name}",
400,
)
def validate_some_method_name_request(method_request: MethodRequest) -> Union[MethodResponse, None]:
"""validation for expected payload of some_method_name direct method request"""
# top level basic format validation
error_msg = compare_dictionary(
d1=method_request.payload,
d2=EXPECTED_METHOD_PAYLOAD,
value_match=False,
recurse=False,
)
if error_msg:
return generate_error_response(
method_request, f"error parsing payload: {error_msg}", 400
)
return None
```
Raw data
{
"_id": null,
"home_page": "",
"name": "iot-edge-validator",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Dylan Gonzales",
"author_email": "py.iot.utils@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5d/c9/167fc3782f500fbba87837b8176e58d4081a2cdc4d1f01e93fe003c22cee/iot-edge-validator-1.0.5.tar.gz",
"platform": null,
"description": "# iot-edge-validator\n\n[](https://img.shields.io/badge/python_v3.9-blue?logo=python&logoColor=yellow) [](https://img.shields.io/badge/pre--commit-blue?logo=pre-commit&logoColor=FAB040) [](https://img.shields.io/badge/keep_a_changelog-blue?logo=keepachangelog&logoColor=E05735) [](https://img.shields.io/badge/GitHub_Actions-blue?logo=githubactions&logoColor=black) [](https://img.shields.io/badge/PyPI-blue?logo=pypi&logoColor=yellow) [](https://img.shields.io/badge/azure_iot_device-v2.11.0-blue?logo=microsoft-azure&logoColor=black)\n\nThis package is a wrapper around the [azure-iot-device](https://pypi.org/project/azure-iot-device/) SDK to provide standardized exception handling and direct method request validation.\n\n[Official Documentation](https://py-iot-utils.azurewebsites.net/packages/iotEdgeValidator) | [Source code](https://github.com/dgonzo27/py-iot-utils/tree/master/iot-edge-validator) | [Package PyPI](https://pypi.org/project/iot-edge-validator/)\n\n## Table of Contents\n\n- [Versioning](#versioning)\n- [Getting Started](#getting-started)\n - [Prerequisites](#prerequisites)\n - [Basic Examples](#basic-examples)\n\n## Versioning\n\nThis repository adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). It will be maintained through the `CHANGELOG.md` and in GitHub Releases. **It's important to note** that you must maintain the version with your releases in `iot/edge/validator/_version.py`, otherwise a new package version will fail to get published.\n\n## Getting Started\n\nThis section provides basic examples with the `iot-edge-validator`.\n\n### Prerequisites\n\n- Python 3.7 or later is required to use this package.\n\n- You must have an Azure subscription and Azure IoT Edge Device to use this package.\n\n### Basic Examples\n\n1. Install via [pip](https://pypi.org/project/pip/):\n\n ```sh\n pip install iot-edge-validator\n ```\n\n2. Import and say hello:\n\n ```python\n from iot.edge.validator import __version__\n\n\n print(f\"hello world from iot-edge-validator version: {__version__}\")\n ```\n\n3. Basic usage:\n\n ```python\n from typing import Any, Dict, Union\n\n from azure.iot.device.iothub.models.methods import MethodRequest, MethodResponse\n\n from iot.edge.validator import (\n format_exception_error,\n generate_error_response,\n compare_dictionary,\n )\n\n EXPECTED_METHOD_NAME: str = \"some_method_name\"\n\n EXPECTED_METHOD_PAYLOAD: Dict[str, Any] = {\n \"some\": {},\n \"expected\": {},\n \"payload\": {},\n }\n\n\n def validate_method_requests(method_request: MethodRequest) -> Union[MethodResponse, None]:\n \"\"\"validation handler for some_method_name listener\"\"\"\n if method_request.name == EXPECTED_METHOD_NAME:\n pass\n else:\n return generate_error_response(method_request,\n f\"received unknown method request for {method_request.name}\",\n 400,\n )\n\n\n def validate_some_method_name_request(method_request: MethodRequest) -> Union[MethodResponse, None]:\n \"\"\"validation for expected payload of some_method_name direct method request\"\"\"\n # top level basic format validation\n error_msg = compare_dictionary(\n d1=method_request.payload,\n d2=EXPECTED_METHOD_PAYLOAD,\n value_match=False,\n recurse=False,\n )\n if error_msg:\n return generate_error_response(\n method_request, f\"error parsing payload: {error_msg}\", 400\n )\n return None\n ```\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "IoT Edge Validator Library for Python",
"version": "1.0.5",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "59f2bcf5bb3c0fd38364ad4c099c93fa",
"sha256": "3ffc14c14c6b5a86eef792fb287f1fb8db5e372208bd502d685af95459603916"
},
"downloads": -1,
"filename": "iot_edge_validator-1.0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "59f2bcf5bb3c0fd38364ad4c099c93fa",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 4628,
"upload_time": "2022-08-17T18:58:30",
"upload_time_iso_8601": "2022-08-17T18:58:30.597446Z",
"url": "https://files.pythonhosted.org/packages/06/9a/9eed5aa6781e66c4a08b11670a237485e0791502d0c5b8b3c9a13128012a/iot_edge_validator-1.0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "06439db3b3c8159ffce0f8d49134514f",
"sha256": "f7a598e352648e5e7eca28ed4b304de5ec654e0fe4ce12a5b1ffe5ace6e6f2cf"
},
"downloads": -1,
"filename": "iot-edge-validator-1.0.5.tar.gz",
"has_sig": false,
"md5_digest": "06439db3b3c8159ffce0f8d49134514f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 4882,
"upload_time": "2022-08-17T18:58:32",
"upload_time_iso_8601": "2022-08-17T18:58:32.228367Z",
"url": "https://files.pythonhosted.org/packages/5d/c9/167fc3782f500fbba87837b8176e58d4081a2cdc4d1f01e93fe003c22cee/iot-edge-validator-1.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-08-17 18:58:32",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "iot-edge-validator"
}