Using Workspace Metadata

Important

While you can get objects using the workspace client, it is not the recommended way to do it. We suggest using the file utilities instead.

You can download the Workspace client by running the following inside an SDK module:

kb-sdk install https://raw.githubusercontent.com/kbase/workspace_deluxe/master/workspace.spec

Retrieving workspace object metadata

If you don’t want to retrieve the entire object, and just want information about it, the most efficient way is to use the ws.get_object_info3 function. To read more about the available functions, see the workspace spec file .

Initialize the workspace client and get an object’s information by reference

# The config object is passed into the __init__ function for your *Impl.py module
from Workspace.WorkspaceClient import Workspace as Workspace
self.ws_url = config["workspace-url"]
self.token = config["KB_AUTH_TOKEN"]
self.ws = Workspace(self.ws_url, token=self.token)
obj_ref = "your/object/reference"
object_info = self.ws.get_object_info3([{"ref": obj_ref}])[0]
object_type_full = object_info[2] # This could be KBaseGenomes.Genome-8.3
object_type = object_type_full.split('-')[0] # This would be KBaseGenomes.Genome

How to use the Workspace Client in the narrative

You can access the workspace client from within narrative code cells. See this example narrative example narrative .

ws = biokbase.narrative.clients.get('workspace')
obj = ws.get_objects2({'objects' : [{'ref' : '30170/2/1'}]})

How to add types to the workspace

How to get a given typespec / .spec file?

If you can’t find a typespec in a repo, you can find it doing the following:

# Example spec file snippet

from biokbase.workspace.client import Workspace
ws = Workspace('https://ci.kbase.us/services/ws')
print(ws.get_module_info({'mod': 'YourModuleName'})['spec'])