# SAP Cloud SDK for AI (Python): Core SDK
The SDK formerly known as *AI Core SDK* was rebranded.
The class names have not changed i.e., you can continue to use existing code.
The SAP AI Core SDK can be used to interact with SAP AI Core.
It provides access to all public lifecycle and administration APIs.
For example:
* You can execute pipelines as a batch job to preprocess or train your models, or perform batch inference.
* You can deploy а trained machine learning model as a web service to serve inference requests with high performance.
* You can register your own Docker registry, synchronize your AI content from your own git repository, and register your own object store for training data and trained models.
* You can log metrics within a workflow execution using the SDK. You can use the same code for tracking metrics in both your local environment and in the workflow execution (production).
> **Notes**
>
> - Executing online inference is not part of Core SDK.
>
> - Metrics persistence is not currently available in your local environment using the SDK. However, it is available in your productive workflow execution.
>
> - *Content packages* for AICore are no longer supported.
>
## Example Usage
Here are a few examples how to use this SDK.
For details on the methods, please refer to the [API documentation](https://api.sap.com/api/AI_CORE_API/resource/Scenario).
### Import Definitions
```python
from ai_core_sdk.ai_core_v2_client import AICoreV2Client
```
## Create Client
The SDK requires credentials from your tenant's subaccount Service Key:
```python
client = AICoreV2Client(base_url=AI_API_BASE,
                        auth_url=AUTH_URL,
                        client_id=CLIENT_ID,
                        client_secret=CLIENT_SECRET,
                        resource_group=resource_group_id)
```
(For persistent client configuration see below.)
### Create New Resource Group
```python
resource_group_create = client.resource_groups.create(resource_group_id=resource_group_id)
print(resource_group_create.resource_group_id)
resource_group_details = client.resource_groups.get(resource_group_id=resource_group_id)
print(f"{resource_group_details.status_message} \n{resource_group_details.resource_group_id}")
```
### Create Object Store Secret
```python
# access key and secret are assumed to reside in environment variables OSS_KEY and OSS_SECRET
object_store_secret_create = client.object_store_secrets.create(
            name="default",
            type="S3",
            bucket="<your S3 bucket>",
            endpoint="<your S3 host>",
            path_prefix="<your path prefix in S3>", region="<your S3 region>",
            data={"AWS_ACCESS_KEY_ID": os.environ.get("OSS_KEY"),
            "AWS_SECRET_ACCESS_KEY": os.environ.get("OSS_SECRET")})
secret_get = client.object_store_secrets.get(name="default")
print(f"{secret_get.metadata}")
```
### List Scenarios
```python
scenarios = client.scenario.query()
for scenario in scenarios.resources:
    print(f"{scenario.name} {scenario.id}")
```
## Client Configuration
There are different options to persist the client credentials
(in this order of precedence):
 - in code via keyword arguments (see above),
 - environment variables,
 - profile configuration file.
 - from VCAP_SERVICES environment variable, if exists
A **profile** is a json file residing in a config directory,
which can be set via environment variable `AICORE_HOME` (the default being `~/.aicore/config.json`).
The command `ai-core-sdk configure --help` can be used to generate a profile.
With profile names one can switch easily between profiles e.g., for different (sub)accounts.
The profile name can be passed also as a keyword. If no profile is specified, the default profile is used.
## Tracking
 The tracking module of the SAP AI Core SDK can be used to log metrics in both your local environment, and productive workflow executions. Metrics persistence is currently available in your productive environment.
 Here are a few code samples demonstrating how to use the SDK for metrics tracking.
### Modify Metrics
 ```
 from ai_core_sdk.tracking import Tracking
 from ai_core_sdk.models import Metric, MetricTag, MetricCustomInfo
 tracking_client = Tracking()
 tracking_client.modify(
    tags = [
        # list
        MetricTag(name="Our Team Tag", value="Tutorial Team"),
        MetricTag(name="Stage", value="Development")
    ],
    metrics = [
        Metric(
            name="Training Loss",
            value=np.finfo(np.float64).max,
            timestamp= datetime.now().utcnow(),
            step = 1, # denotes epoch 1
            labels = []
        )
    ],
    custom_info = [
        # list of Custom Information
         MetricCustomInfo(
             name = "My Classification Report",
             # you may convert anything to string and store it
             value = str('''{
                 "Cats": {
                     "Precision": 75,
                     "Recall": 74
                 },
                 "Dogs": {
                     "Precision": 85,
                     "Recall": 84
                 }
             }''')
        )
    ]
 )
 ```
 ### Log Metrics
 ```
 tracking_client.log_metrics(
    metrics = [
        Metric(
            name="Training Loss",
            value=float(86.99),
            timestamp= datetime.now().utcnow(),
            step = 1, # denotes epoch 1
            labels = []
        ),
    ],
 )
 ```
 ### Set Tags
 ```
 tracking_client.set_tags(
    tags = [
        # list
        MetricTag(name="Our Team Tag", value="Tutorial Team"),
        MetricTag(name="Stage", value="Development")
    ]
 )
 ```
 ### Set Custom Info
 ```
 tracking_client.set_custom_info(
    custom_info = [
        # list of Custom Information
         MetricCustomInfo(
             name = "My Classification Report",
             # you may convert anything to string and store it
             value = str('''
             {
                 "Cats": {
                     "Precision": 75,
                     "Recall": 74
                 },
                 "Dogs": {
                     "Precision": 85,
                     "Recall": 84
                 }
             }
             '''
             )
        ),
    ]
 )
 ```
  ### Query Metrics
 ```
 metrics_response = tracking_client.query(execution_ids = [
    "test_execution_id"    # Change this with the training execution id
 ])
 ```
  ### Delete Metrics
 ```
 metrics_response = tracking_client.delete(execution_id = "test_execution_id") # Change this with the actual execution id
 ```
            
         
        Raw data
        
            {
    "_id": null,
    "home_page": "https://www.sap.com/",
    "name": "sap-ai-sdk-core",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "SAP AI Core, SAP AI Core API",
    "author": "SAP SE",
    "author_email": null,
    "download_url": "https://pypi.python.org/pypi/ai-core-sdk",
    "platform": "Windows",
    "description": "# SAP Cloud SDK for AI (Python): Core SDK\nThe SDK formerly known as *AI Core SDK* was rebranded.\n\nThe class names have not changed i.e., you can continue to use existing code.\n\nThe SAP AI Core SDK can be used to interact with SAP AI Core.\nIt provides access to all public lifecycle and administration APIs.\n\nFor example:\n\n* You can execute pipelines as a batch job to preprocess or train your models, or perform batch inference.\n\n* You can deploy \u0430 trained machine learning model as a web service to serve inference requests with high performance.\n\n* You can register your own Docker registry, synchronize your AI content from your own git repository, and register your own object store for training data and trained models.\n\n* You can log metrics within a workflow execution using the SDK. You can use the same code for tracking metrics in both your local environment and in the workflow execution (production).\n\n> **Notes**\n>\n> - Executing online inference is not part of Core SDK.\n>\n> - Metrics persistence is not currently available in your local environment using the SDK. However, it is available in your productive workflow execution.\n>\n> - *Content packages* for AICore are no longer supported.\n>\n## Example Usage\n\nHere are a few examples how to use this SDK.\nFor details on the methods, please refer to the [API documentation](https://api.sap.com/api/AI_CORE_API/resource/Scenario).\n\n### Import Definitions\n\n```python\nfrom ai_core_sdk.ai_core_v2_client import AICoreV2Client\n```\n\n## Create Client\n\nThe SDK requires credentials from your tenant's subaccount Service Key:\n```python\nclient = AICoreV2Client(base_url=AI_API_BASE,\n                        auth_url=AUTH_URL,\n                        client_id=CLIENT_ID,\n                        client_secret=CLIENT_SECRET,\n                        resource_group=resource_group_id)\n```\n(For persistent client configuration see below.)\n\n### Create New Resource Group\n\n```python\nresource_group_create = client.resource_groups.create(resource_group_id=resource_group_id)\nprint(resource_group_create.resource_group_id)\nresource_group_details = client.resource_groups.get(resource_group_id=resource_group_id)\nprint(f\"{resource_group_details.status_message} \\n{resource_group_details.resource_group_id}\")\n```\n\n### Create Object Store Secret\n\n```python\n# access key and secret are assumed to reside in environment variables OSS_KEY and OSS_SECRET\nobject_store_secret_create = client.object_store_secrets.create(\n            name=\"default\",\n            type=\"S3\",\n            bucket=\"<your S3 bucket>\",\n            endpoint=\"<your S3 host>\",\n            path_prefix=\"<your path prefix in S3>\", region=\"<your S3 region>\",\n            data={\"AWS_ACCESS_KEY_ID\": os.environ.get(\"OSS_KEY\"),\n            \"AWS_SECRET_ACCESS_KEY\": os.environ.get(\"OSS_SECRET\")})\n\nsecret_get = client.object_store_secrets.get(name=\"default\")\nprint(f\"{secret_get.metadata}\")\n```\n\n### List Scenarios\n\n```python\nscenarios = client.scenario.query()\nfor scenario in scenarios.resources:\n    print(f\"{scenario.name} {scenario.id}\")\n```\n## Client Configuration\n\nThere are different options to persist the client credentials\n(in this order of precedence):\n - in code via keyword arguments (see above),\n - environment variables,\n - profile configuration file.\n - from VCAP_SERVICES environment variable, if exists\n\nA **profile** is a json file residing in a config directory,\nwhich can be set via environment variable `AICORE_HOME` (the default being `~/.aicore/config.json`).\n\nThe command `ai-core-sdk configure --help` can be used to generate a profile.\n\nWith profile names one can switch easily between profiles e.g., for different (sub)accounts.\nThe profile name can be passed also as a keyword. If no profile is specified, the default profile is used.\n\n## Tracking\n\n The tracking module of the SAP AI Core SDK can be used to log metrics in both your local environment, and productive workflow executions. Metrics persistence is currently available in your productive environment.\n\n Here are a few code samples demonstrating how to use the SDK for metrics tracking.\n\n\n### Modify Metrics\n\n ```\n from ai_core_sdk.tracking import Tracking\n\n from ai_core_sdk.models import Metric, MetricTag, MetricCustomInfo\n\n tracking_client = Tracking()\n\n tracking_client.modify(\n    tags = [\n        # list\n        MetricTag(name=\"Our Team Tag\", value=\"Tutorial Team\"),\n        MetricTag(name=\"Stage\", value=\"Development\")\n    ],\n    metrics = [\n        Metric(\n            name=\"Training Loss\",\n            value=np.finfo(np.float64).max,\n            timestamp= datetime.now().utcnow(),\n            step = 1, # denotes epoch 1\n            labels = []\n        )\n    ],\n    custom_info = [\n        # list of Custom Information\n         MetricCustomInfo(\n             name = \"My Classification Report\",\n             # you may convert anything to string and store it\n             value = str('''{\n                 \"Cats\": {\n                     \"Precision\": 75,\n                     \"Recall\": 74\n                 },\n                 \"Dogs\": {\n                     \"Precision\": 85,\n                     \"Recall\": 84\n                 }\n             }''')\n        )\n    ]\n )\n\n ```\n\n ### Log Metrics\n\n ```\n tracking_client.log_metrics(\n    metrics = [\n        Metric(\n            name=\"Training Loss\",\n            value=float(86.99),\n            timestamp= datetime.now().utcnow(),\n            step = 1, # denotes epoch 1\n            labels = []\n        ),\n    ],\n )\n\n ```\n\n ### Set Tags\n\n ```\n tracking_client.set_tags(\n    tags = [\n        # list\n        MetricTag(name=\"Our Team Tag\", value=\"Tutorial Team\"),\n        MetricTag(name=\"Stage\", value=\"Development\")\n    ]\n )\n\n ```\n\n ### Set Custom Info\n\n ```\n tracking_client.set_custom_info(\n    custom_info = [\n        # list of Custom Information\n         MetricCustomInfo(\n             name = \"My Classification Report\",\n             # you may convert anything to string and store it\n             value = str('''\n             {\n                 \"Cats\": {\n                     \"Precision\": 75,\n                     \"Recall\": 74\n                 },\n                 \"Dogs\": {\n                     \"Precision\": 85,\n                     \"Recall\": 84\n                 }\n             }\n             '''\n             )\n        ),\n    ]\n )\n\n ```\n  ### Query Metrics\n\n ```\n metrics_response = tracking_client.query(execution_ids = [\n    \"test_execution_id\"    # Change this with the training execution id\n ])\n ```\n\n  ### Delete Metrics\n\n ```\n metrics_response = tracking_client.delete(execution_id = \"test_execution_id\") # Change this with the actual execution id\n ```\n\n",
    "bugtrack_url": null,
    "license": "SAP DEVELOPER LICENSE AGREEMENT",
    "summary": "SAP Cloud SDK for AI (Python): Core SDK",
    "version": "3.0.10",
    "project_urls": {
        "Download": "https://pypi.python.org/pypi/ai-core-sdk",
        "Homepage": "https://www.sap.com/"
    },
    "split_keywords": [
        "sap ai core",
        " sap ai core api"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "e3199a04c3d6be04fa31299ec225e4d91c9fe3df36506b85d1fe49aa98c79d0f",
                "md5": "95918131356beb6b1311305038967c86",
                "sha256": "db1996cdf89fd91d092c6b1ae14c56ad9241ab0ac073294a79fccb4ee7c4a8b7"
            },
            "downloads": -1,
            "filename": "sap_ai_sdk_core-3.0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "95918131356beb6b1311305038967c86",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 118721,
            "upload_time": "2025-08-04T13:52:11",
            "upload_time_iso_8601": "2025-08-04T13:52:11.430327Z",
            "url": "https://files.pythonhosted.org/packages/e3/19/9a04c3d6be04fa31299ec225e4d91c9fe3df36506b85d1fe49aa98c79d0f/sap_ai_sdk_core-3.0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-04 13:52:11",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "sap-ai-sdk-core"
}