diff --git a/CHANGELOG.md b/CHANGELOG.md index a5bc4403..f6f80e06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## 1.18.0 [unreleased] +### Features +1. [#237](https://github.com/influxdata/influxdb-client-python/pull/237): Use kwargs to pass query parameters into API list call - useful for the ability to use pagination. + ## 1.17.0 [2021-04-30] ### Features diff --git a/examples/buckets_management.py b/examples/buckets_management.py index a26926ee..2ff7966f 100644 --- a/examples/buckets_management.py +++ b/examples/buckets_management.py @@ -17,7 +17,7 @@ The Bucket API uses as a parameter the Organization ID. We have to retrieve ID by Organization API. """ org_name = "my-org" - org = list(filter(lambda it: it.name == org_name, client.organizations_api().find_organizations()))[0] + org = client.organizations_api().find_organizations(org=org_name)[0] """ Create Bucket with retention policy set to 3600 seconds and name "bucket-by-python" diff --git a/influxdb_client/client/authorizations_api.py b/influxdb_client/client/authorizations_api.py index 32deffae..9c5bfe84 100644 --- a/influxdb_client/client/authorizations_api.py +++ b/influxdb_client/client/authorizations_api.py @@ -42,10 +42,10 @@ def find_authorizations(self, **kwargs): """ Get a list of all authorizations. - :param str user_id: filter authorizations belonging to a user id - :param str user: filter authorizations belonging to a user name - :param str org_id: filter authorizations belonging to a org id - :param str org: filter authorizations belonging to a org name + :key str user_id: filter authorizations belonging to a user id + :key str user: filter authorizations belonging to a user name + :key str org_id: filter authorizations belonging to a org id + :key str org: filter authorizations belonging to a org name :return: Authorizations """ authorizations = self._authorizations_service.get_authorizations(**kwargs) diff --git a/influxdb_client/client/bucket_api.py b/influxdb_client/client/bucket_api.py index cd91ef42..c20e6c59 100644 --- a/influxdb_client/client/bucket_api.py +++ b/influxdb_client/client/bucket_api.py @@ -87,6 +87,16 @@ def find_bucket_by_name(self, bucket_name): else: return None - def find_buckets(self): - """Get all buckets.""" - return self._buckets_service.get_buckets() + def find_buckets(self, **kwargs): + """List buckets. + + :key int offset: Offset for pagination + :key int limit: Limit for pagination + :key str after: The last resource ID from which to seek from (but not including). + This is to be used instead of `offset`. + :key str org: The organization name. + :key str org_id: The organization ID. + :key str name: Only returns buckets with a specific name. + :return: Buckets + """ + return self._buckets_service.get_buckets(**kwargs) diff --git a/influxdb_client/client/labels_api.py b/influxdb_client/client/labels_api.py index 9cb43c5a..006cb90c 100644 --- a/influxdb_client/client/labels_api.py +++ b/influxdb_client/client/labels_api.py @@ -67,13 +67,15 @@ def clone_label(self, cloned_name: str, label: Label) -> Label: return self.create_label(name=cloned_name, properties=cloned_properties, org_id=label.org_id) - def find_labels(self) -> List['Label']: + def find_labels(self, **kwargs) -> List['Label']: """ Get all available labels. + :key str org_id: The organization ID. + :return: labels """ - return self._service.get_labels().labels + return self._service.get_labels(**kwargs).labels def find_label_by_id(self, label_id: str): """ diff --git a/influxdb_client/client/organizations_api.py b/influxdb_client/client/organizations_api.py index ec59b04f..6c1301e0 100644 --- a/influxdb_client/client/organizations_api.py +++ b/influxdb_client/client/organizations_api.py @@ -26,9 +26,18 @@ def find_organization(self, org_id): """Retrieve an organization.""" return self._organizations_service.get_orgs_id(org_id=org_id) - def find_organizations(self): - """List all organizations.""" - return self._organizations_service.get_orgs().orgs + def find_organizations(self, **kwargs): + """ + List all organizations. + + :key int offset: Offset for pagination + :key int limit: Limit for pagination + :key bool descending: + :key str org: Filter organizations to a specific organization name. + :key str org_id: Filter organizations to a specific organization ID. + :key str user_id: Filter organizations to a specific user ID. + """ + return self._organizations_service.get_orgs(**kwargs).orgs def create_organization(self, name: str = None, organization: Organization = None) -> Organization: """Create an organization.""" diff --git a/influxdb_client/client/tasks_api.py b/influxdb_client/client/tasks_api.py index d67b5d73..d6b318b1 100644 --- a/influxdb_client/client/tasks_api.py +++ b/influxdb_client/client/tasks_api.py @@ -28,12 +28,12 @@ def find_task_by_id(self, task_id) -> Task: def find_tasks(self, **kwargs): """List all tasks. - :param str name: only returns tasks with the specified name - :param str after: returns tasks after specified ID - :param str user: filter tasks to a specific user ID - :param str org: filter tasks to a specific organization name - :param str org_id: filter tasks to a specific organization ID - :param int limit: the number of tasks to return + :key str name: only returns tasks with the specified name + :key str after: returns tasks after specified ID + :key str user: filter tasks to a specific user ID + :key str org: filter tasks to a specific organization name + :key str org_id: filter tasks to a specific organization ID + :key int limit: the number of tasks to return :return: Tasks """ return self._service.get_tasks(**kwargs).tasks diff --git a/tests/test_BucketsApi.py b/tests/test_BucketsApi.py index 768e002d..79e0c458 100644 --- a/tests/test_BucketsApi.py +++ b/tests/test_BucketsApi.py @@ -83,6 +83,26 @@ def test_create_bucket_retention_list(self): self.delete_test_bucket(my_bucket) + def test_pagination(self): + my_org = self.find_my_org() + buckets = self.buckets_api.find_buckets().buckets + size = len(buckets) + + # create 2 buckets + self.buckets_api.create_bucket(bucket_name=generate_bucket_name(), org_id=my_org.id) + self.buckets_api.create_bucket(bucket_name=generate_bucket_name(), org_id=my_org.id) + + buckets = self.buckets_api.find_buckets().buckets + self.assertEqual(size + 2, len(buckets)) + + # offset 1 + buckets = self.buckets_api.find_buckets(offset=1).buckets + self.assertEqual(size + 1, len(buckets)) + + # count 1 + buckets = self.buckets_api.find_buckets(limit=1).buckets + self.assertEqual(1, len(buckets)) + if __name__ == '__main__': unittest.main()
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: