Skip to main content

IBM Watson Studio Pipelines Python Client

This package provides various utilities for working with IBM Watson Studio Pipelines. Its primary usage is to enable users to store artifact results of a notebook run.

Usage

Construction

WSPipelines client is constructed from IAM APIKEY, which can be provided in a few ways:

  • explicitly:

    from ibm_watson_studio_pipelines import WSPipelines
    
    client = WSPipelines(apikey)
    # or
    client = WSPipelines.from_apikey(apikey)
    # or
    client = WSPipelines.from_token(token)
    
  • implicitly:

    APIKEY=...
    export APIKEY
    

    or

    USER_ACCESS_TOKEN=...
    export USER_ACCESS_TOKEN
    
    from ibm_watson_studio_pipelines import WSPipelines
    
    # use APIKEY
    client = WSPipelines.from_apikey()
    
    # use USER_ACCESS_TOKEN
    client = WSPipelines.from_token()
    
    # try APIKEY, if absent then USER_ACCESS_TOKEN:
    client = WSPipelines()
    # or
    client = WSPipelines.new_instance()
    

All of the above may also define service_name and url.

The exact procedure of deciding which authentication method to use:

  1. If from_apikey or from_token is used, the method is forced.
  2. If constructor is used but either apikey or bearer_token argument was provided, that method will be forced (if both are present, an overloading error will be raised). Note that providing a nameless argument is equivalent to providing apikey.
  3. If constructor or new_instance is used, APIKEY env-var is used.
  4. If constructor or new_instance is used, but APIKEY env-var is not present, USER_ACCESS_TOKEN env-var is used.
  5. If none of the above matches, an error is returned.

Usage in Python notebooks

Notebooks run in IBM Watson Studio Pipelines get inputs and expose outputs as a node:

{
  "id": ...,
  "type": "execution_node",
  "op": "run_container",
  "app_data": {
    "pipeline_data": {
      "name": ...,
      "config": {
        "link": {
          "component_id_ref": "run-notebook"
        }
      },
      "inputs": [
        ...,
        {
          "name": "model_name",
          "group": "env_variables",
          "type": "String",
          "value_from": ...
        }
      ],
      "outputs": [
        {
          "name": "trained_model",
          "group": "output_variables",
          "type": {
            "CPDPath": {
              "path_type": "resource",
              "resource_type": "asset",
              "asset_type": "wml_model"
            }
          }
        }
      ]
    }
  },
  ...
}

Inside of the notebook, inputs are available as environmental variables:

model_name = os.environ['model_name']

Outputs are exposed using sdk method, store_results:

client = WSPipelines.from_apikey(...)
client.store_results({
  "trained_model": ... // cpd path to the trained model
})

Extracting credentials

On public cloud, this client provides a method for easy retrieval of WML instance credentials and scope storage credentials:

client.get_wml_credentials() # the scope passed in notebook
# or
client.get_wml_credentials("cpd:///projects/123456789")
client.get_storage_credentials() # the scope passed in notebook
# or
client.get_storage_credentials("cpd:///projects/123456789")

Note how the result will vary depending on the authentication method used to create the client.

CPD-Path manipulation

CPD-Path parsing is manipulation is also supported:

from ibm_watson_studio_pipelines import CpdScope, WSPipelines

client = WSPipelines.from_apikey()

scope = CpdScope.from_string("cpd:///projects/123456789")

assert scope.scope_type() == "projects"
assert scope.scope_id() == "123456789"

client.get_wml_credentials(scope)

Different kinds of CPD-Paths will have different properties, providing the same interface across scopes, resource and file paths:

from ibm_watson_studio_pipelines import CpdPath

scope_file_path = CpdPath.from_string("cpd:///projects/123456789/files/abc/def")
assert scope_file_path.scope_type() == "projects"
assert scope_file_path.scope_id() == "123456789"
assert scope_file_path.file_path() == "/abc/def"

connection_path = CpdPath.from_string("cpd:///projects/123456789/connections/3141592")
assert connection_path.scope_type() == "projects"
assert connection_path.scope_id() == "123456789"
assert connection_path.resource_type() == "connections"
assert connection_path.resource_id() == "3141592"

connection_file_path = CpdPath.from_string("cpd:///projects/123456789/connections/3141592/files/~/abc/def")
assert connection_file_path.scope_type() == "projects"
assert connection_file_path.scope_id() == "123456789"
assert connection_file_path.resource_type() == "connections"
assert connection_file_path.resource_id() == "3141592"
assert connection_file_path.bucket_name() == "~"
assert connection_file_path.file_path() == "/abc/def"

...additionally, for non-scope paths the scope can be extracted, if present:

from ibm_watson_studio_pipelines import CpdPath

scope_path = CpdPath.from_string("cpd:///projects/123456789")
connection_path = CpdPath.from_string("cpd:///projects/123456789/connections/3141592")
assert connection_path.scope() == scope_path

Contribution

See a separate document on contribution.

Metadata

Release files for ibm-watson-studio-pipelines 0.2.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ibm-watson-studio-pipelines 0.2.12
File Size Uploaded
ibm-watson-studio-pipelines-0.2.12.tar.gz 30.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ibm-watson-studio-pipelines 0.2.12
File Interpreter ABI Platform
ibm_watson_studio_pipelines-0.2.12-py3-none-any.whl Python 3 none any Details

Total release size: 61.5 kB

Release files / ibm-watson-studio-pipelines-0.2.12.tar.gz

Download URL ibm-watson-studio-pipelines-0.2.12.tar.gz
Size 30.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0d91c9e1b7769e702644f510646796de67757d0a7ea9d68ddbd9da035590ddc1
BLAKE2b-256 checksum
How to use checksums
65207ee608a0ec1958bfe4b8fad6da9715980fda3a7383e645ab0dcae86727c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.15

Release files / ibm_watson_studio_pipelines-0.2.12-py3-none-any.whl

Download URL ibm_watson_studio_pipelines-0.2.12-py3-none-any.whl
Size 30.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52093cc9b73b1f8fd9d8ff9dd981ce91f8a8d844d03b0ec146fa8bdd29771299
BLAKE2b-256 checksum
How to use checksums
a2c48219778eb5650c7c6e2b2f7bf486d621fd83c53f8a99fcdf15fc7e8225f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.9.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.9.15

Release history Release notifications | RSS feed

This release

0.2.12 This release

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

1 release file

0.2.2

3 release files

0.2.1

1 release file

0.2.0

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page