Skip to main content

IoT Edge Validator Library for Python

Project description

iot-edge-validator

python version pre-commit Keep a Changelog CI_CD GitHub_Actions package PyPI azure-iot-device

This package is a wrapper around the azure-iot-device SDK to provide standardized exception handling and direct method request validation.

Official Documentation | Source code | Package PyPI

Table of Contents

Versioning

This repository adheres to Semantic Versioning. 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:

    pip install iot-edge-validator
    
  2. Import and say hello:

    from iot.edge.validator import __version__
    
    
    print(f"hello world from iot-edge-validator version: {__version__}")
    
  3. Basic usage:

    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
    

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

iot-edge-validator-1.0.6.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

iot_edge_validator-1.0.6-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file iot-edge-validator-1.0.6.tar.gz.

File metadata

  • Download URL: iot-edge-validator-1.0.6.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for iot-edge-validator-1.0.6.tar.gz
Algorithm Hash digest
SHA256 c1ef1a7319e55bfc0c8faacaf18817719c460312a08777a7c41fe663f5d2531d
MD5 61b19660b98d4f166685829c6910853d
BLAKE2b-256 f89c53d18fdc86a98db5d25c6601b81edff9589c452381772bb5ab59d76485bb

See more details on using hashes here.

File details

Details for the file iot_edge_validator-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for iot_edge_validator-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 81c4eabb7a7eaf0cd4b1080cde25ca9639c52d60f0f2435cc008ed933d94f992
MD5 56c93cc21113dbeca12180111f5457bc
BLAKE2b-256 2fdcfa7637cc949eb03b15192ac85ec561518bfdd62bee0d0a62bd554efbdb7f

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