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:
-
token
(str
, default:None
) –Authentication token from polly
Usage
from polly.workspaces import Workspaces
workspaces = Workspaces(token)
create_copy
Function to create a copy of files/folders existing in a workspace into another workspace.
Parameters:
-
source_id
(int
) –workspace id of the source workspace where the file/folder exists
-
source_path
(str
) –file/folder path on the source workspace to be copied
-
destination_id
(int
) –workspace id of the destination workspace where the file/folder is to be copied
-
destination_path
(str
, default:''
) –optional parameter to specify the destination path
Raises:
-
InvalidParameterException
–when the parameter like source id is invalid
-
InvalidPathException
–when the source path is invalid
create_workspace
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
(str
) –name of the workspace
-
description
(str
, default:None
) –general information about workspace
download_from_workspaces
Function to download files/folders from workspaces. A message will be displayed on the status of the operation.
Parameters:
-
workspace_id
(int
) –Id of the workspace where file needs to uploaded
-
workspace_path
(str
) –Downloaded file on workspace. The workspace path should be prefixed with "polly://"
-
copy_workspace_path
(bool
, default:True
) –Flag indicating whether the workspace path needs to copied in the working directory
Returns:
-
None
–None
Raises:
-
InvalidPathException
–Invalid file path provided
-
OperationFailedException
–Failed download
-
InvalidParameterException
–Invalid parameter passed
fetch_my_workspaces
This function fetch workspaces from Polly.
Parameters:
-
None
–None
Returns:
-
Table
–A table with workspace specific attributes
list_contents
This function fetches contents of a workspace from Polly.
Parameters:
-
workspace_id
–workspace id for the target workspace.
Returns:
-
Table
–it will return a table with attributes.
sync_data
Function to sync directory to or from workspaces and local.
Parameters:
-
workspace_id
(int
) –id of the workspace which is used for sync
-
source_path
(str
) –path for the directory that is to be used for sync. Can be local path or a workspace path. The workspace path should be prefixed with "polly://".
-
destination_path
(str
) –path for the directory that is to be used for sync. Can be local path or a workspace path. The workspace path should be prefixed with "polly://".Creates the folder if provided folder path doesn't exist.
Raises:
-
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
Function to upload files/folders to workspaces.
Parameters:
-
workspace_id
(int
) –id of the workspace where file need to uploaded
-
workspace_path
(str
) –path where the file/folder is to be uploaded. The workspace path should be prefixed with "polly://". Creates the folder if provided folder path doesn't exist.
-
local_path
(str
) –uploaded file/folder path
Raises:
-
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
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_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:-
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
INFO:root:Upload successful on workspace-id=11139.
Download files/folders from workspace to local
INFO:root:Download successful to path=/import
Also with copy_workspace_path parameter, users can control whether to maintain the original directory structure of the downloaded files/folders. When this parameter is set to False, only the contents of the specified folder will be downloaded to the local path, without preserving the directory structure
workspace_obj.download_from_workspaces(11139, "folder1/folder2/", local_path, copy_workspace_path = False)
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) [32m[1mSuccess: Sync complete[22m[39m
Copy file from one workspace to another
Users can copy files from one workspace to another as shown below:-
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:-