sagemaker-rightline


Namesagemaker-rightline JSON
Version 0.3.7 PyPI version JSON
download
home_page
SummaryPython package to easily validate properties of a SageMaker Pipeline.
upload_time2023-11-02 18:57:15
maintainer
docs_urlNone
author
requires_python<3.13,>3.7
licenseMIT License Copyright (c) 2023 stiebels Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords sagemaker pipeline validation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![Test&Build](https://github.com/stiebels/sagemaker-rightline/actions/workflows/python-package.yml/badge.svg)
[![CodeCov](https://codecov.io/gh/stiebels/sagemaker-rightline/branch/main/graph/badge.svg?token=7TCW0GP1NV)](https://codecov.io/gh/stiebels/sagemaker-rightline)
[![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/stiebels/sagemaker-rightline/issues)
[![Documentation](https://readthedocs.org/projects/sagemaker-rightline/badge/?version=latest)](https://sagemaker-rightline.readthedocs.io/en/latest/?badge=latest)

# sagemaker-rightline

This repository contains the source code for sagemaker-rightline, a Python package that eases validation of properties of a SageMaker Pipeline object.

Note that at present this package is in an early stage of development and is not yet ready for production use. We welcome contributions!


## README Content

- [Features](#features)
- [Usage](#usage)
- [Contributing](#contributing)

## Features

### ⚙️ Configuration
The `Configuration` class is responsible for running the `Validations` against the `Pipeline` object and returning a `Report`.
The `Configuration` class is instantiated with a
 - `sagemaker.workflow.pipeline.Pipeline` object, and
 - a list of `Validations`.

### ✔️ Validations
A `Validation` is a class that inherits from the `Validation` base class.
It is responsible for validating a single property of the `Pipeline` object.
We differentiate between `Validations` that check the `Pipeline` object itself (class names beginning with "Pipeline") and `Validations` that check the `Pipeline` object's `Step` objects (class name starting with "Step").
Depending on the specific `Validation`, a different set of `StepTypEnums` may be supported.

For example, the `StepImagesExist` supports `Processing` and `Training` steps. It's a validation checks that all ImageURI that
Steps of the named types of the `Pipeline` object reference indeed exist on the target ECR.

The following `Validations` are currently implemented:
  - `PipelineParametersAsExpected`
  - `StepImagesExist`
  - `StepKmsKeyIdAsExpected`
  - `StepNetworkConfigAsExpected`
  - `StepLambdaFunctionExists`
  - `StepRoleNameExists`
  - `StepRoleNameAsExpected`
  - `StepTagsAsExpected`
  - `StepInputsAsExpected`
  - `StepOutputsAsExpected`
  - `StepOutputsMatchInputsAsExpected`
  - `StepCallbackSqsQueueExists`
  - `PipelineProcessingStepsIONamesUnique`

In most cases, a `Validation` subclass requires passing a `Rule` object to its constructor.

### 📜 Rules
A `Rule` is a class that inherits from the `Rule` base class.
It is responsible for defining the rule that a `Validation` checks for.
For example, passing the list of expected KMSKeyIDs and the `Rule` `Equals` to `StepKmsKeyIdAsExpected` will check that
all `Step` objects of the `Pipeline` object have a `KmsKeyId` property that matches the passed KMSKeyIDs.

Note that not all `Validations` require a `Rule` object, e.g. `StepImagesExist`.

The following `Rules` are currently implemented:
  - `Equals`
  - `Contains`

All rules support the `negative` parameter (default: `False`), which allows for inverting the rule.

### 📝 Report
A `Report` is a class whose instance is returned by the `Configuration` class (optionally a pandas.DataFrame instead).
It contains the results of the `Validations` that were run against the `Pipeline` object as well as additional information
to allow for further analysis.

## Usage

```python
from sagemaker.processing import NetworkConfig, ProcessingInput, ProcessingOutput
from sagemaker.workflow.parameters import ParameterString
from sagemaker_rightline.model import Configuration
from sagemaker_rightline.rules import Contains, Equals
from sagemaker_rightline.validations import (
    PipelineParametersAsExpected,
    StepImagesExist,
    StepKmsKeyIdAsExpected,
    StepNetworkConfigAsExpected,
    StepLambdaFunctionExists,
    StepRoleNameExists,
    StepRoleNameAsExpected,
    StepTagsAsExpected,
    StepInputsAsExpected,
    StepOutputsAsExpected,
    StepOutputsMatchInputsAsExpected,
    StepCallbackSqsQueueExists,
)

# Import a dummy pipeline
from tests.fixtures.pipeline import get_sagemaker_pipeline, DUMMY_BUCKET

sm_pipeline = get_sagemaker_pipeline()

# Define Validations
validations = [
    StepImagesExist(),
    PipelineParametersAsExpected(
        parameters_expected=[
            ParameterString(
                name="parameter-1",
                default_value="some-value",
            ),
        ],
        rule=Contains(),
    ),
    StepKmsKeyIdAsExpected(
        kms_key_id_expected="some/kms-key-alias",
        step_name="sm_training_step_sklearn",  # optional: if not set, will check all steps
        rule=Equals(),
    ),
    StepNetworkConfigAsExpected(
        network_config_expected=NetworkConfig(
            enable_network_isolation=False,
            security_group_ids=["sg-1234567890"],
            subnets=["subnet-1234567890"],
        ),
        rule=Equals(negative=True),
    ),
    StepLambdaFunctionExists(),
    StepRoleNameExists(),
    StepRoleNameAsExpected(
        role_name_expected="some-role-name",
        step_name="sm_training_step_sklearn",  # optional: if not set, will check all steps
        rule=Equals(),
    ),
    StepTagsAsExpected(
        tags_expected=[{
            "some-key": "some-value",
        }],
        step_name="sm_training_step_sklearn",  # optional: if not set, will check all steps
        rule=Equals(),
    ),
    StepInputsAsExpected(
        inputs_expected=[
            ProcessingInput(
                source=f"s3://{DUMMY_BUCKET}/input-1",
                destination="/opt/ml/processing/input",
                input_name="input-2",
            )
        ],
        step_type="Processing",  # either step_type or step_name must be set to filter
        rule=Contains(),
    ),
    StepOutputsAsExpected(
        outputs_expected=[
            ProcessingOutput(
                source="/opt/ml/processing/output",
                destination=f"s3://{DUMMY_BUCKET}/output-1",
                output_name="output-1",
            )
        ],
        step_name="sm_processing_step_spark",  # optional
        rule=Contains(),
    ),
    StepOutputsMatchInputsAsExpected(
        inputs_outputs_expected=[
            {
                "input": {
                    "step_name": "sm_processing_step_sklearn",
                    "input_name": "input-1",
                },
                "output": {
                    "step_name": "sm_processing_step_sklearn",
                    "output_name": "output-1",
                },
            }
        ]
    ),
    StepCallbackSqsQueueExists(),
]

# Add Validations and SageMaker Pipeline to Configuration
cm = Configuration(
    validations=validations,
    sagemaker_pipeline=sm_pipeline,
)

# Run the full Configuration
df = cm.run()

# Show the report
df
```
![img.png](./docs/report.png)

## Release
Publishing a new version to PyPI is done via the `Release` functionality.
This will trigger the `publish.yml` workflow, creating a new release with the version from the tag and publish the package to PyPI.

## Contributing
Contributions welcome! We'll add a guide shortly.
To get an overview of the structure of the project, have a look at the [class diagram](./docs/sagemaker_rightline.svg), which is auto-generated at build time together with the corresponding PUML file.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "sagemaker-rightline",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "<3.13,>3.7",
    "maintainer_email": "",
    "keywords": "sagemaker,pipeline,validation",
    "author": "",
    "author_email": "stiebels <stiebels@github.com>, dipanjank <dipanjank@github.com>",
    "download_url": "https://files.pythonhosted.org/packages/be/81/6d5e8f712916fc0e47a1f56d620c7cc1343f76797a93f651c736edad7808/sagemaker-rightline-0.3.7.tar.gz",
    "platform": null,
    "description": "![Test&Build](https://github.com/stiebels/sagemaker-rightline/actions/workflows/python-package.yml/badge.svg)\n[![CodeCov](https://codecov.io/gh/stiebels/sagemaker-rightline/branch/main/graph/badge.svg?token=7TCW0GP1NV)](https://codecov.io/gh/stiebels/sagemaker-rightline)\n[![Contributions Welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/stiebels/sagemaker-rightline/issues)\n[![Documentation](https://readthedocs.org/projects/sagemaker-rightline/badge/?version=latest)](https://sagemaker-rightline.readthedocs.io/en/latest/?badge=latest)\n\n# sagemaker-rightline\n\nThis repository contains the source code for sagemaker-rightline, a Python package that eases validation of properties of a SageMaker Pipeline object.\n\nNote that at present this package is in an early stage of development and is not yet ready for production use. We welcome contributions!\n\n\n## README Content\n\n- [Features](#features)\n- [Usage](#usage)\n- [Contributing](#contributing)\n\n## Features\n\n### \u2699\ufe0f Configuration\nThe `Configuration` class is responsible for running the `Validations` against the `Pipeline` object and returning a `Report`.\nThe `Configuration` class is instantiated with a\n - `sagemaker.workflow.pipeline.Pipeline` object, and\n - a list of `Validations`.\n\n### \u2714\ufe0f Validations\nA `Validation` is a class that inherits from the `Validation` base class.\nIt is responsible for validating a single property of the `Pipeline` object.\nWe differentiate between `Validations` that check the `Pipeline` object itself (class names beginning with \"Pipeline\") and `Validations` that check the `Pipeline` object's `Step` objects (class name starting with \"Step\").\nDepending on the specific `Validation`, a different set of `StepTypEnums` may be supported.\n\nFor example, the `StepImagesExist` supports `Processing` and `Training` steps. It's a validation checks that all ImageURI that\nSteps of the named types of the `Pipeline` object reference indeed exist on the target ECR.\n\nThe following `Validations` are currently implemented:\n  - `PipelineParametersAsExpected`\n  - `StepImagesExist`\n  - `StepKmsKeyIdAsExpected`\n  - `StepNetworkConfigAsExpected`\n  - `StepLambdaFunctionExists`\n  - `StepRoleNameExists`\n  - `StepRoleNameAsExpected`\n  - `StepTagsAsExpected`\n  - `StepInputsAsExpected`\n  - `StepOutputsAsExpected`\n  - `StepOutputsMatchInputsAsExpected`\n  - `StepCallbackSqsQueueExists`\n  - `PipelineProcessingStepsIONamesUnique`\n\nIn most cases, a `Validation` subclass requires passing a `Rule` object to its constructor.\n\n### \ud83d\udcdc Rules\nA `Rule` is a class that inherits from the `Rule` base class.\nIt is responsible for defining the rule that a `Validation` checks for.\nFor example, passing the list of expected KMSKeyIDs and the `Rule` `Equals` to `StepKmsKeyIdAsExpected` will check that\nall `Step` objects of the `Pipeline` object have a `KmsKeyId` property that matches the passed KMSKeyIDs.\n\nNote that not all `Validations` require a `Rule` object, e.g. `StepImagesExist`.\n\nThe following `Rules` are currently implemented:\n  - `Equals`\n  - `Contains`\n\nAll rules support the `negative` parameter (default: `False`), which allows for inverting the rule.\n\n### \ud83d\udcdd Report\nA `Report` is a class whose instance is returned by the `Configuration` class (optionally a pandas.DataFrame instead).\nIt contains the results of the `Validations` that were run against the `Pipeline` object as well as additional information\nto allow for further analysis.\n\n## Usage\n\n```python\nfrom sagemaker.processing import NetworkConfig, ProcessingInput, ProcessingOutput\nfrom sagemaker.workflow.parameters import ParameterString\nfrom sagemaker_rightline.model import Configuration\nfrom sagemaker_rightline.rules import Contains, Equals\nfrom sagemaker_rightline.validations import (\n    PipelineParametersAsExpected,\n    StepImagesExist,\n    StepKmsKeyIdAsExpected,\n    StepNetworkConfigAsExpected,\n    StepLambdaFunctionExists,\n    StepRoleNameExists,\n    StepRoleNameAsExpected,\n    StepTagsAsExpected,\n    StepInputsAsExpected,\n    StepOutputsAsExpected,\n    StepOutputsMatchInputsAsExpected,\n    StepCallbackSqsQueueExists,\n)\n\n# Import a dummy pipeline\nfrom tests.fixtures.pipeline import get_sagemaker_pipeline, DUMMY_BUCKET\n\nsm_pipeline = get_sagemaker_pipeline()\n\n# Define Validations\nvalidations = [\n    StepImagesExist(),\n    PipelineParametersAsExpected(\n        parameters_expected=[\n            ParameterString(\n                name=\"parameter-1\",\n                default_value=\"some-value\",\n            ),\n        ],\n        rule=Contains(),\n    ),\n    StepKmsKeyIdAsExpected(\n        kms_key_id_expected=\"some/kms-key-alias\",\n        step_name=\"sm_training_step_sklearn\",  # optional: if not set, will check all steps\n        rule=Equals(),\n    ),\n    StepNetworkConfigAsExpected(\n        network_config_expected=NetworkConfig(\n            enable_network_isolation=False,\n            security_group_ids=[\"sg-1234567890\"],\n            subnets=[\"subnet-1234567890\"],\n        ),\n        rule=Equals(negative=True),\n    ),\n    StepLambdaFunctionExists(),\n    StepRoleNameExists(),\n    StepRoleNameAsExpected(\n        role_name_expected=\"some-role-name\",\n        step_name=\"sm_training_step_sklearn\",  # optional: if not set, will check all steps\n        rule=Equals(),\n    ),\n    StepTagsAsExpected(\n        tags_expected=[{\n            \"some-key\": \"some-value\",\n        }],\n        step_name=\"sm_training_step_sklearn\",  # optional: if not set, will check all steps\n        rule=Equals(),\n    ),\n    StepInputsAsExpected(\n        inputs_expected=[\n            ProcessingInput(\n                source=f\"s3://{DUMMY_BUCKET}/input-1\",\n                destination=\"/opt/ml/processing/input\",\n                input_name=\"input-2\",\n            )\n        ],\n        step_type=\"Processing\",  # either step_type or step_name must be set to filter\n        rule=Contains(),\n    ),\n    StepOutputsAsExpected(\n        outputs_expected=[\n            ProcessingOutput(\n                source=\"/opt/ml/processing/output\",\n                destination=f\"s3://{DUMMY_BUCKET}/output-1\",\n                output_name=\"output-1\",\n            )\n        ],\n        step_name=\"sm_processing_step_spark\",  # optional\n        rule=Contains(),\n    ),\n    StepOutputsMatchInputsAsExpected(\n        inputs_outputs_expected=[\n            {\n                \"input\": {\n                    \"step_name\": \"sm_processing_step_sklearn\",\n                    \"input_name\": \"input-1\",\n                },\n                \"output\": {\n                    \"step_name\": \"sm_processing_step_sklearn\",\n                    \"output_name\": \"output-1\",\n                },\n            }\n        ]\n    ),\n    StepCallbackSqsQueueExists(),\n]\n\n# Add Validations and SageMaker Pipeline to Configuration\ncm = Configuration(\n    validations=validations,\n    sagemaker_pipeline=sm_pipeline,\n)\n\n# Run the full Configuration\ndf = cm.run()\n\n# Show the report\ndf\n```\n![img.png](./docs/report.png)\n\n## Release\nPublishing a new version to PyPI is done via the `Release` functionality.\nThis will trigger the `publish.yml` workflow, creating a new release with the version from the tag and publish the package to PyPI.\n\n## Contributing\nContributions welcome! We'll add a guide shortly.\nTo get an overview of the structure of the project, have a look at the [class diagram](./docs/sagemaker_rightline.svg), which is auto-generated at build time together with the corresponding PUML file.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 stiebels  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Python package to easily validate properties of a SageMaker Pipeline.",
    "version": "0.3.7",
    "project_urls": {
        "Homepage": "https://github.com/stiebels/sagemaker-rightline"
    },
    "split_keywords": [
        "sagemaker",
        "pipeline",
        "validation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d67099167223becc8cbf46700c5f97fa20b794cacf377d51ce429e260e78cbe9",
                "md5": "6ff614aef11d801e7a7ac9cbdd42776b",
                "sha256": "2c0dce2f4bcf7dcb9646abc5bd4f8bf7f8ee03fa1bea2483ff62b8411b5eb2ed"
            },
            "downloads": -1,
            "filename": "sagemaker_rightline-0.3.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6ff614aef11d801e7a7ac9cbdd42776b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>3.7",
            "size": 14823,
            "upload_time": "2023-11-02T18:57:12",
            "upload_time_iso_8601": "2023-11-02T18:57:12.077320Z",
            "url": "https://files.pythonhosted.org/packages/d6/70/99167223becc8cbf46700c5f97fa20b794cacf377d51ce429e260e78cbe9/sagemaker_rightline-0.3.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "be816d5e8f712916fc0e47a1f56d620c7cc1343f76797a93f651c736edad7808",
                "md5": "23e0837d7d4ef06d839bfced5887e7f5",
                "sha256": "b1475b77e5bdf0713aa5af25373f706390136da5c0169bc088c352cf06f1c1af"
            },
            "downloads": -1,
            "filename": "sagemaker-rightline-0.3.7.tar.gz",
            "has_sig": false,
            "md5_digest": "23e0837d7d4ef06d839bfced5887e7f5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>3.7",
            "size": 21393,
            "upload_time": "2023-11-02T18:57:15",
            "upload_time_iso_8601": "2023-11-02T18:57:15.319927Z",
            "url": "https://files.pythonhosted.org/packages/be/81/6d5e8f712916fc0e47a1f56d620c7cc1343f76797a93f651c736edad7808/sagemaker-rightline-0.3.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-02 18:57:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stiebels",
    "github_project": "sagemaker-rightline",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sagemaker-rightline"
}
        
Elapsed time: 0.17073s