{"id":8870,"library":"azure-ml-component","title":"Azure Machine Learning Component SDK","description":"The `azure-ml-component` library is a low-level Python SDK providing core functionalities and base classes for defining and managing components within Azure Machine Learning. It is primarily an internal dependency of the higher-level `azure-ai-ml` SDK, which is the recommended package for most end-user interactions. This package is actively maintained with frequent updates, currently at version 0.9.18.post2, usually released in sync with the `azure-ai-ml` ecosystem.","status":"active","version":"0.9.18.post2","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/ml/azure-ml-component","tags":["azure","ml","machine-learning","component","sdk","azureml"],"install":[{"cmd":"pip install azure-ml-component","lang":"bash","label":"Install `azure-ml-component`"},{"cmd":"pip install azure-ai-ml","lang":"bash","label":"Recommended: Install `azure-ai-ml` (includes `azure-ml-component`)"}],"dependencies":[{"reason":"Core Azure SDK functionalities","package":"azure-core","optional":false},{"reason":"Blob storage interactions for component assets","package":"azure-storage-blob","optional":false},{"reason":"YAML parsing for component definitions","package":"pyyaml","optional":false}],"imports":[{"note":"While `azure-ml-component` contains base classes, `azure.ai.ml.entities.CommandComponent` is the high-level, recommended way to define components using the `azure-ai-ml` SDK.","symbol":"CommandComponent","correct":"from azure.ai.ml.entities import CommandComponent"},{"note":"The `@command` decorator from `azure.ai.ml` is the most common and ergonomic way to define a command component.","symbol":"command","correct":"from azure.ai.ml import command"}],"quickstart":{"code":"import os\nfrom azure.ai.ml import command, Input, Output\nfrom azure.ai.ml.entities import CommandComponent\n\n# Define a simple command component using the recommended azure.ai.ml SDK\n# This component takes an input string and produces an output string.\n\n# For this example, we'll define a simple Python script as the command source\ncomponent_script_content = \"\"\"\nimport argparse\n\nparser = argparse.ArgumentParser()\nparser.add_argument(\"--input_data\", type=str)\nparser.add_argument(\"--output_data\", type=str)\nargs = parser.parse_args()\n\nprint(f\"Received input: {args.input_data}\")\n\nwith open(args.output_data, \"w\") as f:\n    f.write(f\"Processed: {args.input_data.upper()}\")\nprint(f\"Wrote output to {args.output_data}\")\n\"\"\"\n\n# Create a temporary directory and save the script\nimport tempfile\nimport shutil\n\nwith tempfile.TemporaryDirectory() as temp_dir:\n    script_path = os.path.join(temp_dir, \"process.py\")\n    with open(script_path, \"w\") as f:\n        f.write(component_script_content)\n\n    # Define the command component\n    hello_world_component = command(\n        name=\"hello_world_component\",\n        display_name=\"Hello World Component Example\",\n        description=\"A simple component that processes input text.\",\n        inputs={\n            \"input_data\": Input(type=\"string\", description=\"Input string for processing\")\n        },\n        outputs={\n            \"output_data\": Output(type=\"uri_file\", description=\"Processed output string\")\n        },\n        command=f\"python {{inputs.script_path}}/process.py --input_data {{inputs.input_data}} --output_data {{outputs.output_data}}\",\n        environment=dict(\n            conda_file=os.path.join(temp_dir, \"conda_env.yml\"),\n            image=\"mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04:latest\"\n        ),\n        code=temp_dir\n    )\n\n    print(\"\\n--- Component Definition ---\")\n    print(hello_world_component.as_dict())\n\n    # To actually run this, you would need an MLClient connected to an Azure ML workspace.\n    # from azure.ai.ml import MLClient\n    # from azure.identity import DefaultAzureCredential\n    # ml_client = MLClient(\n    #     DefaultAzureCredential(), \n    #     subscription_id=os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"\"),\n    #     resource_group_name=os.environ.get(\"AZURE_RESOURCE_GROUP\", \"\"),\n    #     workspace_name=os.environ.get(\"AZURE_WORKSPACE_NAME\", \"\")\n    # )\n    # registered_component = ml_client.components.create_or_update(hello_world_component)\n    # print(f\"Component registered with name: {registered_component.name}, version: {registered_component.version}\")\n","lang":"python","description":"This quickstart demonstrates defining a basic command component using the `azure.ai.ml` SDK, which is the recommended way to interact with Azure Machine Learning components. Although `azure-ml-component` provides underlying classes, direct usage is uncommon. This example defines a component that takes a string input and writes a processed string to an output file. To actually register and run this component, an `MLClient` connected to an Azure ML Workspace would be required (commented out for quickstart runnability)."},"warnings":[{"fix":"Always use `azure.ai.ml` for creating, registering, and managing components. Refer to official Azure ML documentation for examples using `from azure.ai.ml import command` or `from azure.ai.ml.entities import CommandComponent`.","message":"The `azure-ml-component` library is a low-level dependency of the `azure-ai-ml` SDK and is generally not intended for direct end-user interaction for defining or managing components. For these tasks, the `azure.ai.ml` package (the main Azure Machine Learning Python SDK) is the recommended and stable entry point.","severity":"gotcha","affected_versions":"All"},{"fix":"Manage `azure-ai-ml` as your primary dependency. Let `pip` resolve `azure-ml-component` as a sub-dependency when installing or upgrading `azure-ai-ml`. Avoid manually pinning `azure-ml-component` unless explicitly instructed for specific advanced scenarios.","message":"Versions of `azure-ml-component` are tightly coupled with `azure-ai-ml` versions. Direct upgrades of `azure-ml-component` without upgrading `azure-ai-ml` can lead to version conflicts, unexpected behavior, or API incompatibilities.","severity":"breaking","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Instead, use the `azure.ai.ml` SDK, which is the high-level API for defining components. For example, use `from azure.ai.ml import command` or `from azure.ai.ml.entities import CommandComponent`.","cause":"Attempting to directly import internal modules of `azure-ml-component` which are not exposed or intended for direct user consumption.","error":"ModuleNotFoundError: No module named 'azure.ml.component.core'"},{"fix":"Carefully review the component's YAML definition or the arguments passed to the `command` decorator/ `CommandComponent` constructor. Ensure all required fields are present and their types/formats match the official `azure.ai.ml` component schema documentation.","cause":"This error typically occurs when the component definition (e.g., inputs, outputs, command, environment) does not conform to the expected schema of `azure.ai.ml`.","error":"azure.ai.ml.exceptions.ValidationException: Invalid schema for component"}]}