diff --git a/scaleapi/__init__.py b/scaleapi/__init__.py index c0f32c8..b8b7a19 100644 --- a/scaleapi/__init__.py +++ b/scaleapi/__init__.py @@ -3,6 +3,7 @@ from .tasks import Task from .batches import Batch +from .projects import Project TASK_TYPES = [ 'annotation', @@ -55,6 +56,10 @@ class Batchlist(Paginator): pass +class Projectlist(Paginator): + pass + + class ScaleClient(object): def __init__(self, api_key): self.api_key = api_key @@ -156,7 +161,7 @@ def create_batch(self, project, batch_name, callback): batchdata = self._postrequest('batches', payload) return Batch(batchdata, self) - def get_batch(self, batch_name: str): + def get_batch(self, batch_name): batchdata = self._getrequest('batches/%s' % batch_name) return Batch(batchdata, self) @@ -167,13 +172,27 @@ def list_batches(self, **kwargs): if key not in allowed_kwargs: raise ScaleInvalidRequest('Illegal parameter %s for ScaleClient.tasks()' % key, None) - response = self._getrequest('tasks', params=kwargs) + response = self._getrequest('batches', params=kwargs) docs = [Batch(doc, self) for doc in response['docs']] return Batchlist( docs, response['total'], response['limit'], response['offset'], response['has_more'], response.get('next_token'), ) + def create_project(self, annotation_type, project_name, params): + payload = dict(type=annotation_type, name=project_name, params=params) + data = self._postrequest('projects', payload) + return Project(data, self) + + def get_project(self, project_name): + data = self._getrequest('projects/%s' % project_name) + return Project(data, self) + + def list_projects(self): + responses = self._getrequest('projects') + projects = [Project(response, self) for response in responses] + return projects + def _AddTaskTypeCreator(task_type): def create_task_wrapper(self, **kwargs): diff --git a/scaleapi/projects.py b/scaleapi/projects.py new file mode 100644 index 0000000..5911b46 --- /dev/null +++ b/scaleapi/projects.py @@ -0,0 +1,23 @@ +class Project(object): + """Project class""" + def __init__(self, param_dict, client): + self.client = client + self.param_dict = param_dict + self.name = param_dict['name'] + + def __getattr__(self, name): + if name in self.param_dict: + return self.param_dict[name] + if name in self.params: + return self.params[name] + raise AttributeError("'%s' object has no attribute %s" + % (type(self).__name__, name)) + + def __hash__(self): + return hash(self.name) + + def __str__(self): + return 'Project(name=%s)' % self.name + + def __repr__(self): + return 'Project(%s)' % self.param_dict