Skip to content

Workspaces

This class contains functions to interact with workspaces on Polly. Users can create a workspace, fetch list of workspaces, upload data to workspace and download data from workspace. To get started, users need to initialize a object that can use all function and methods of Workspaces class.

Parameters:

Name Type Description Default
token str

Authentication token from polly

None
Usage

from polly.workspaces import Workspaces

workspaces = Workspaces(token)

create_copy(source_id, source_path, destination_id, destination_path='')

Function to create a copy of files/folders existing in a workspace into another workspace.

Parameters:

Name Type Description Default
source_id int

workspace id of the source workspace where the file/folder exists

required
source_path str)

file/folder path on the source workspace to be copied

required
destination_id int)

workspace id of the destination workspace where the file/folder is to be copied

required
destination_path str, optional)

optional parameter to specify the destination path

''

Raises:

Type Description
InvalidParameterException

when the parameter like source id is invalid

InvalidPathException

when the source path is invalid

create_workspace(name, description=None)

This function create workspace on Polly. Returns a Dictionary object like this { 'id': 9999, 'name': 'rrrrr', 'active': True, 'description': 'for docu', 'created_time': '2022-03-16 11:08:47.127260', 'last_modified': '2022-03-16 11:08:47.127260', 'creator': 1127, 'project_property': { 'type': 'workspaces', 'labels': '' }, 'organisation': 1 }

Parameters:

Name Type Description Default
name str

name of the workspace

required
description str

general information about workspace

None

download_from_workspaces(workspace_id, workspace_path, local_path)

Function to download files/folders from workspaces. A message will be displayed on the status of the operation.

Parameters:

Name Type Description Default
workspace_id int)

Id of the workspace where file needs to uploaded

required
workspace_path str)

Downloaded file on workspace. The workspace path should be prefixed with "polly://"

required

Returns:

Type Description
None

None

Raises:

Type Description
InvalidPathException

Invalid file path provided

OperationFailedException

Failed download

InvalidParameterException

Invalid parameter passed

fetch_my_workspaces()

This function fetch workspaces from Polly.

Returns:

Type Description

A table with workspace specific attributes

list_contents(workspace_id)

This function fetches contents of a workspace from Polly.

Args: | workspace_id : workspace id for the target workspace.

Returns: | it will return a table with attributes.

.. code::

    # create a obj
    workspaces = Workspaces(token)
    # from there you can other methods
    workspaces.list_contents(workspace_id)

sync_data(workspace_id, source_path, destination_path)

Function to sync directory to or from workspaces and local.

Parameters:

Name Type Description Default
workspace_id int)

id of the workspace which is used for sync

required
source_path str)

path for the directory that is to be used for sync.

required
Can be local path or a workspace path. The workspace path should be prefixed with "polly

//".

required
destination_path str)

path for the directory that is to be used for sync.

required
The workspace path should be prefixed with "polly

//".Creates the folder if provided folder path doesn't exist.

required

Raises:

Type Description
InvalidParameterException

when the parameter like workspace id is invalid

InvalidDirectoryPath

when the folder to path is invalid

InvalidWorkspaceDetails

when the workspace path is not prefixed with "polly://"

upload_to_workspaces(workspace_id, workspace_path, local_path)

Function to upload files/folders to workspaces.

Parameters:

Name Type Description Default
workspace_id int)

id of the workspace where file need to uploaded

required
workspace_path str)

path where the file/folder is to be uploaded.

required
The workspace path should be prefixed with "polly

//". Creates the folder if provided folder path doesn't exist.

required
local_path str)

uploaded file/folder path

required

Raises:

Type Description
InvalidParameterException

when the parameter like workspace id is invalid

InvalidPathException

when the file to path is invalid

Examples

Workspaces class of polly-python can be initialised using the code block below:-

# Install polly python
pip install polly-python

# Import libraries
from polly.auth import Polly
from polly.workspaces import Workspaces

# Create omixatlas object and authenticate
AUTH_TOKEN=(os.environ['POLLY_REFRESH_TOKEN'])
Polly.auth(AUTH_TOKEN)
workspace_obj = Workspaces()

Create a workspace

workspace_obj.create_workspace("demo_workspace","To demo the workspace functionalities")
INFO:root:Workspace Created !

{'id': 11139,
 'name': 'demo_workspace',
 'status': 1,
 'active': 't',
 'description': 'To demo the workspace functionalities',
 'created_time': '2023-03-29 03:08:04.179298',
 'last_modified': '2023-03-29 03:08:04.179298',
 'creator': '1105',
 'project_property': {'type': 'workspaces', 'labels': ''},
 'organisation': 1653310312,
 'tag_names': []}

Fetch list of all the workspaces users have access to

Users can fetch the details of workspaces they have access to as shown below:-

workspace_obj.fetch_my_workspaces()
Workspace_id Workspace_name status description last_modified tag_names favourite watch
0 11139 demo_workspace active To demo the workspace functionalities 2023-03-29 03:08:04 [] False False
34 7214 LiverOmixCS active Liver Omix Case Study stuff 2021-05-19 15:30:28 [] False False

Fetch contents of a given workspace

Users can fetch the contents of workspaces they have access to as shown below:-

workspace_obj.list_contents(8861)
file_name size last_modified
0 high_brca_impact_p53.pco - -
1 high_edited.pco - -
10 polly_python_transcriptomics_geo.ipynb 12.48 KB 2022-04-26 12:04:24.000000

Upload files/folders from local to workspace

workspace_obj.upload_to_workspaces(11139, "new_report.html", "GSE96058_GPL11154_report (1).html")
INFO:root:Upload successful on workspace-id=11139.

Download files/folders from workspace to local

workspace_obj.download_from_workspaces(11139, "new_report.html")
INFO:root:Download successful to path=/import

Alternatively, users can also use the CLI command on either CLI or on Polly Notebooks to download data from workspace to local.

!polly files sync -s "polly://demo.txt" -d "demo.txt" -y
# source is the path of the file/folder in the workspace where the notebook is # present, is prefixed by "polly://" and the option -s is used.
# destination file/folder with the given name will be created in the notebook, 
# is written after option -d.

/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8) Success: Sync complete

Copy file from one workspace to another

Users can copy files from one workspace to another as shown below:-

workspace_obj.create_copy(8223, "local_folder/demo.txt", 11139, destination_path='')
Workspace_copy started, You will be notified upon completion.
Copy Operation Successful!

Sync files or folders between workspace to local

Users can sync files or folders in their local with workspaces. In the example below, we demonstrate how users can sync a folder from workspace to their local:-

workspace_id = 14645
source_path = "polly://newest_dir"
destination_path = "/import/Untitled Folder"
# Note:- The workspace path should be prefixed with "polly://".

workspace_obj.sync_data(14645, source_path, destination_path)