cirro.sdk.portal
1from cirro_api_client.v1.models import Executor 2 3from cirro.cirro_client import CirroApi 4from cirro.sdk.dataset import DataPortalDataset 5from cirro.sdk.developer import DeveloperHelper 6from cirro.sdk.exceptions import DataPortalAssetNotFound 7from cirro.sdk.process import DataPortalProcess, DataPortalProcesses 8from cirro.sdk.project import DataPortalProject, DataPortalProjects 9from cirro.sdk.reference_type import DataPortalReferenceType, DataPortalReferenceTypes 10 11 12class DataPortal: 13 """ 14 Helper functions for exploring the Projects, Datasets, Samples, and Files 15 available in the Data Portal. 16 """ 17 18 def __init__(self, base_url: str = None, client: CirroApi = None): 19 """ 20 Set up the DataPortal object, establishing an authenticated connection. 21 22 Args: 23 base_url (str): Optional base URL of the Cirro instance 24 (if not provided, it uses the `CIRRO_BASE_URL` environment variable, or the config file) 25 client (`cirro.cirro_client.CirroApi`): Optional pre-configured client 26 27 Example: 28 ```python 29 from cirro import DataPortal 30 31 Portal = DataPortal(base_url="app.cirro.bio") 32 portal.list_projects() 33 ``` 34 """ 35 36 if client is not None: 37 self._client = client 38 39 # Set up default client if not provided 40 else: 41 self._client = CirroApi(base_url=base_url) 42 43 def list_projects(self) -> DataPortalProjects: 44 """List all the projects available in the Data Portal.""" 45 46 return DataPortalProjects( 47 [ 48 DataPortalProject(proj, self._client) 49 for proj in self._client.projects.list() 50 ] 51 ) 52 53 def get_project_by_name(self, name: str = None) -> DataPortalProject: 54 """Return the project with the specified name.""" 55 56 return self.list_projects().get_by_name(name) 57 58 def get_project_by_id(self, _id: str = None) -> DataPortalProject: 59 """Return the project with the specified id.""" 60 61 return self.list_projects().get_by_id(_id) 62 63 def get_project(self, project: str = None) -> DataPortalProject: 64 """ 65 Return a project identified by ID or name. 66 67 Args: 68 project (str): ID or name of project 69 70 Returns: 71 `from cirro.sdk.project import DataPortalProject` 72 """ 73 try: 74 return self.get_project_by_id(project) 75 except DataPortalAssetNotFound: 76 return self.get_project_by_name(project) 77 78 def get_dataset(self, project: str = None, dataset: str = None) -> DataPortalDataset: 79 """ 80 Return a dataset identified by ID or name. 81 82 Args: 83 project (str): ID or name of project 84 dataset (str): ID or name of dataset 85 86 Returns: 87 `cirro.sdk.dataset.DataPortalDataset` 88 89 ```python 90 from cirro import DataPortal() 91 portal = DataPortal() 92 dataset = portal.get_dataset( 93 project="id-or-name-of-project", 94 dataset="id-or-name-of-dataset" 95 ) 96 ``` 97 """ 98 try: 99 project: DataPortalProject = self.get_project_by_id(project) 100 except DataPortalAssetNotFound: 101 project: DataPortalProject = self.get_project_by_name(project) 102 103 try: 104 return project.get_dataset_by_id(dataset) 105 except DataPortalAssetNotFound: 106 return project.get_dataset_by_name(dataset) 107 108 def list_processes(self, ingest=False) -> DataPortalProcesses: 109 """ 110 List all the processes available in the Data Portal. 111 By default, only list non-ingest processes (those which can be run on existing datasets). 112 To list the processes which can be used to upload datasets, use `ingest = True`. 113 114 Args: 115 ingest (bool): If True, only list those processes which can be used to ingest datasets directly 116 """ 117 118 return DataPortalProcesses( 119 [ 120 DataPortalProcess(p, self._client) 121 for p in self._client.processes.list() 122 if not ingest or p.executor == Executor.INGEST 123 ] 124 ) 125 126 def get_process_by_name(self, name: str, ingest=False) -> DataPortalProcess: 127 """ 128 Return the process with the specified name. 129 130 Args: 131 name (str): Name of process 132 """ 133 134 return self.list_processes(ingest=ingest).get_by_name(name) 135 136 def get_process_by_id(self, id: str, ingest=False) -> DataPortalProcess: 137 """ 138 Return the process with the specified id 139 140 Args: 141 id (str): ID of process 142 """ 143 144 return self.list_processes(ingest=ingest).get_by_id(id) 145 146 def list_reference_types(self) -> DataPortalReferenceTypes: 147 """ 148 Return the list of all available reference types 149 """ 150 151 return DataPortalReferenceTypes( 152 [ 153 DataPortalReferenceType(ref) 154 for ref in self._client.references.get_types() 155 ] 156 ) 157 158 @property 159 def developer_helper(self) -> DeveloperHelper: 160 return DeveloperHelper(self._client)
13class DataPortal: 14 """ 15 Helper functions for exploring the Projects, Datasets, Samples, and Files 16 available in the Data Portal. 17 """ 18 19 def __init__(self, base_url: str = None, client: CirroApi = None): 20 """ 21 Set up the DataPortal object, establishing an authenticated connection. 22 23 Args: 24 base_url (str): Optional base URL of the Cirro instance 25 (if not provided, it uses the `CIRRO_BASE_URL` environment variable, or the config file) 26 client (`cirro.cirro_client.CirroApi`): Optional pre-configured client 27 28 Example: 29 ```python 30 from cirro import DataPortal 31 32 Portal = DataPortal(base_url="app.cirro.bio") 33 portal.list_projects() 34 ``` 35 """ 36 37 if client is not None: 38 self._client = client 39 40 # Set up default client if not provided 41 else: 42 self._client = CirroApi(base_url=base_url) 43 44 def list_projects(self) -> DataPortalProjects: 45 """List all the projects available in the Data Portal.""" 46 47 return DataPortalProjects( 48 [ 49 DataPortalProject(proj, self._client) 50 for proj in self._client.projects.list() 51 ] 52 ) 53 54 def get_project_by_name(self, name: str = None) -> DataPortalProject: 55 """Return the project with the specified name.""" 56 57 return self.list_projects().get_by_name(name) 58 59 def get_project_by_id(self, _id: str = None) -> DataPortalProject: 60 """Return the project with the specified id.""" 61 62 return self.list_projects().get_by_id(_id) 63 64 def get_project(self, project: str = None) -> DataPortalProject: 65 """ 66 Return a project identified by ID or name. 67 68 Args: 69 project (str): ID or name of project 70 71 Returns: 72 `from cirro.sdk.project import DataPortalProject` 73 """ 74 try: 75 return self.get_project_by_id(project) 76 except DataPortalAssetNotFound: 77 return self.get_project_by_name(project) 78 79 def get_dataset(self, project: str = None, dataset: str = None) -> DataPortalDataset: 80 """ 81 Return a dataset identified by ID or name. 82 83 Args: 84 project (str): ID or name of project 85 dataset (str): ID or name of dataset 86 87 Returns: 88 `cirro.sdk.dataset.DataPortalDataset` 89 90 ```python 91 from cirro import DataPortal() 92 portal = DataPortal() 93 dataset = portal.get_dataset( 94 project="id-or-name-of-project", 95 dataset="id-or-name-of-dataset" 96 ) 97 ``` 98 """ 99 try: 100 project: DataPortalProject = self.get_project_by_id(project) 101 except DataPortalAssetNotFound: 102 project: DataPortalProject = self.get_project_by_name(project) 103 104 try: 105 return project.get_dataset_by_id(dataset) 106 except DataPortalAssetNotFound: 107 return project.get_dataset_by_name(dataset) 108 109 def list_processes(self, ingest=False) -> DataPortalProcesses: 110 """ 111 List all the processes available in the Data Portal. 112 By default, only list non-ingest processes (those which can be run on existing datasets). 113 To list the processes which can be used to upload datasets, use `ingest = True`. 114 115 Args: 116 ingest (bool): If True, only list those processes which can be used to ingest datasets directly 117 """ 118 119 return DataPortalProcesses( 120 [ 121 DataPortalProcess(p, self._client) 122 for p in self._client.processes.list() 123 if not ingest or p.executor == Executor.INGEST 124 ] 125 ) 126 127 def get_process_by_name(self, name: str, ingest=False) -> DataPortalProcess: 128 """ 129 Return the process with the specified name. 130 131 Args: 132 name (str): Name of process 133 """ 134 135 return self.list_processes(ingest=ingest).get_by_name(name) 136 137 def get_process_by_id(self, id: str, ingest=False) -> DataPortalProcess: 138 """ 139 Return the process with the specified id 140 141 Args: 142 id (str): ID of process 143 """ 144 145 return self.list_processes(ingest=ingest).get_by_id(id) 146 147 def list_reference_types(self) -> DataPortalReferenceTypes: 148 """ 149 Return the list of all available reference types 150 """ 151 152 return DataPortalReferenceTypes( 153 [ 154 DataPortalReferenceType(ref) 155 for ref in self._client.references.get_types() 156 ] 157 ) 158 159 @property 160 def developer_helper(self) -> DeveloperHelper: 161 return DeveloperHelper(self._client)
Helper functions for exploring the Projects, Datasets, Samples, and Files available in the Data Portal.
19 def __init__(self, base_url: str = None, client: CirroApi = None): 20 """ 21 Set up the DataPortal object, establishing an authenticated connection. 22 23 Args: 24 base_url (str): Optional base URL of the Cirro instance 25 (if not provided, it uses the `CIRRO_BASE_URL` environment variable, or the config file) 26 client (`cirro.cirro_client.CirroApi`): Optional pre-configured client 27 28 Example: 29 ```python 30 from cirro import DataPortal 31 32 Portal = DataPortal(base_url="app.cirro.bio") 33 portal.list_projects() 34 ``` 35 """ 36 37 if client is not None: 38 self._client = client 39 40 # Set up default client if not provided 41 else: 42 self._client = CirroApi(base_url=base_url)
Set up the DataPortal object, establishing an authenticated connection.
Arguments:
- base_url (str): Optional base URL of the Cirro instance
(if not provided, it uses the
CIRRO_BASE_URL
environment variable, or the config file) - client (
cirro.cirro_client.CirroApi
): Optional pre-configured client
Example:
from cirro import DataPortal
Portal = DataPortal(base_url="app.cirro.bio")
portal.list_projects()
44 def list_projects(self) -> DataPortalProjects: 45 """List all the projects available in the Data Portal.""" 46 47 return DataPortalProjects( 48 [ 49 DataPortalProject(proj, self._client) 50 for proj in self._client.projects.list() 51 ] 52 )
List all the projects available in the Data Portal.
54 def get_project_by_name(self, name: str = None) -> DataPortalProject: 55 """Return the project with the specified name.""" 56 57 return self.list_projects().get_by_name(name)
Return the project with the specified name.
59 def get_project_by_id(self, _id: str = None) -> DataPortalProject: 60 """Return the project with the specified id.""" 61 62 return self.list_projects().get_by_id(_id)
Return the project with the specified id.
64 def get_project(self, project: str = None) -> DataPortalProject: 65 """ 66 Return a project identified by ID or name. 67 68 Args: 69 project (str): ID or name of project 70 71 Returns: 72 `from cirro.sdk.project import DataPortalProject` 73 """ 74 try: 75 return self.get_project_by_id(project) 76 except DataPortalAssetNotFound: 77 return self.get_project_by_name(project)
Return a project identified by ID or name.
Arguments:
- project (str): ID or name of project
Returns:
from cirro.sdk.project import DataPortalProject
79 def get_dataset(self, project: str = None, dataset: str = None) -> DataPortalDataset: 80 """ 81 Return a dataset identified by ID or name. 82 83 Args: 84 project (str): ID or name of project 85 dataset (str): ID or name of dataset 86 87 Returns: 88 `cirro.sdk.dataset.DataPortalDataset` 89 90 ```python 91 from cirro import DataPortal() 92 portal = DataPortal() 93 dataset = portal.get_dataset( 94 project="id-or-name-of-project", 95 dataset="id-or-name-of-dataset" 96 ) 97 ``` 98 """ 99 try: 100 project: DataPortalProject = self.get_project_by_id(project) 101 except DataPortalAssetNotFound: 102 project: DataPortalProject = self.get_project_by_name(project) 103 104 try: 105 return project.get_dataset_by_id(dataset) 106 except DataPortalAssetNotFound: 107 return project.get_dataset_by_name(dataset)
Return a dataset identified by ID or name.
Arguments:
- project (str): ID or name of project
- dataset (str): ID or name of dataset
Returns:
cirro.sdk.dataset.DataPortalDataset
from cirro import DataPortal() portal = DataPortal() dataset = portal.get_dataset( project="id-or-name-of-project", dataset="id-or-name-of-dataset" )
109 def list_processes(self, ingest=False) -> DataPortalProcesses: 110 """ 111 List all the processes available in the Data Portal. 112 By default, only list non-ingest processes (those which can be run on existing datasets). 113 To list the processes which can be used to upload datasets, use `ingest = True`. 114 115 Args: 116 ingest (bool): If True, only list those processes which can be used to ingest datasets directly 117 """ 118 119 return DataPortalProcesses( 120 [ 121 DataPortalProcess(p, self._client) 122 for p in self._client.processes.list() 123 if not ingest or p.executor == Executor.INGEST 124 ] 125 )
List all the processes available in the Data Portal.
By default, only list non-ingest processes (those which can be run on existing datasets).
To list the processes which can be used to upload datasets, use ingest = True
.
Arguments:
- ingest (bool): If True, only list those processes which can be used to ingest datasets directly
127 def get_process_by_name(self, name: str, ingest=False) -> DataPortalProcess: 128 """ 129 Return the process with the specified name. 130 131 Args: 132 name (str): Name of process 133 """ 134 135 return self.list_processes(ingest=ingest).get_by_name(name)
Return the process with the specified name.
Arguments:
- name (str): Name of process
137 def get_process_by_id(self, id: str, ingest=False) -> DataPortalProcess: 138 """ 139 Return the process with the specified id 140 141 Args: 142 id (str): ID of process 143 """ 144 145 return self.list_processes(ingest=ingest).get_by_id(id)
Return the process with the specified id
Arguments:
- id (str): ID of process
147 def list_reference_types(self) -> DataPortalReferenceTypes: 148 """ 149 Return the list of all available reference types 150 """ 151 152 return DataPortalReferenceTypes( 153 [ 154 DataPortalReferenceType(ref) 155 for ref in self._client.references.get_types() 156 ] 157 )
Return the list of all available reference types