Skip to content

Commit e26e7b0

Browse files
authored
feat: add paging to find functions (influxdata#237)
1 parent f698030 commit e26e7b0

File tree

8 files changed

+63
-19
lines changed

8 files changed

+63
-19
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 1.18.0 [unreleased]
22

3+
### Features
4+
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.
5+
36
## 1.17.0 [2021-04-30]
47

58
### Features

examples/buckets_management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
The Bucket API uses as a parameter the Organization ID. We have to retrieve ID by Organization API.
1818
"""
1919
org_name = "my-org"
20-
org = list(filter(lambda it: it.name == org_name, client.organizations_api().find_organizations()))[0]
20+
org = client.organizations_api().find_organizations(org=org_name)[0]
2121

2222
"""
2323
Create Bucket with retention policy set to 3600 seconds and name "bucket-by-python"

influxdb_client/client/authorizations_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def find_authorizations(self, **kwargs):
4242
"""
4343
Get a list of all authorizations.
4444
45-
:param str user_id: filter authorizations belonging to a user id
46-
:param str user: filter authorizations belonging to a user name
47-
:param str org_id: filter authorizations belonging to a org id
48-
:param str org: filter authorizations belonging to a org name
45+
:key str user_id: filter authorizations belonging to a user id
46+
:key str user: filter authorizations belonging to a user name
47+
:key str org_id: filter authorizations belonging to a org id
48+
:key str org: filter authorizations belonging to a org name
4949
:return: Authorizations
5050
"""
5151
authorizations = self._authorizations_service.get_authorizations(**kwargs)

influxdb_client/client/bucket_api.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ def find_bucket_by_name(self, bucket_name):
8787
else:
8888
return None
8989

90-
def find_buckets(self):
91-
"""Get all buckets."""
92-
return self._buckets_service.get_buckets()
90+
def find_buckets(self, **kwargs):
91+
"""List buckets.
92+
93+
:key int offset: Offset for pagination
94+
:key int limit: Limit for pagination
95+
:key str after: The last resource ID from which to seek from (but not including).
96+
This is to be used instead of `offset`.
97+
:key str org: The organization name.
98+
:key str org_id: The organization ID.
99+
:key str name: Only returns buckets with a specific name.
100+
:return: Buckets
101+
"""
102+
return self._buckets_service.get_buckets(**kwargs)

influxdb_client/client/labels_api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ def clone_label(self, cloned_name: str, label: Label) -> Label:
6767

6868
return self.create_label(name=cloned_name, properties=cloned_properties, org_id=label.org_id)
6969

70-
def find_labels(self) -> List['Label']:
70+
def find_labels(self, **kwargs) -> List['Label']:
7171
"""
7272
Get all available labels.
7373
74+
:key str org_id: The organization ID.
75+
7476
:return: labels
7577
"""
76-
return self._service.get_labels().labels
78+
return self._service.get_labels(**kwargs).labels
7779

7880
def find_label_by_id(self, label_id: str):
7981
"""

influxdb_client/client/organizations_api.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,18 @@ def find_organization(self, org_id):
2626
"""Retrieve an organization."""
2727
return self._organizations_service.get_orgs_id(org_id=org_id)
2828

29-
def find_organizations(self):
30-
"""List all organizations."""
31-
return self._organizations_service.get_orgs().orgs
29+
def find_organizations(self, **kwargs):
30+
"""
31+
List all organizations.
32+
33+
:key int offset: Offset for pagination
34+
:key int limit: Limit for pagination
35+
:key bool descending:
36+
:key str org: Filter organizations to a specific organization name.
37+
:key str org_id: Filter organizations to a specific organization ID.
38+
:key str user_id: Filter organizations to a specific user ID.
39+
"""
40+
return self._organizations_service.get_orgs(**kwargs).orgs
3241

3342
def create_organization(self, name: str = None, organization: Organization = None) -> Organization:
3443
"""Create an organization."""

influxdb_client/client/tasks_api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ def find_task_by_id(self, task_id) -> Task:
2828
def find_tasks(self, **kwargs):
2929
"""List all tasks.
3030
31-
:param str name: only returns tasks with the specified name
32-
:param str after: returns tasks after specified ID
33-
:param str user: filter tasks to a specific user ID
34-
:param str org: filter tasks to a specific organization name
35-
:param str org_id: filter tasks to a specific organization ID
36-
:param int limit: the number of tasks to return
31+
:key str name: only returns tasks with the specified name
32+
:key str after: returns tasks after specified ID
33+
:key str user: filter tasks to a specific user ID
34+
:key str org: filter tasks to a specific organization name
35+
:key str org_id: filter tasks to a specific organization ID
36+
:key int limit: the number of tasks to return
3737
:return: Tasks
3838
"""
3939
return self._service.get_tasks(**kwargs).tasks

tests/test_BucketsApi.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ def test_create_bucket_retention_list(self):
8383

8484
self.delete_test_bucket(my_bucket)
8585

86+
def test_pagination(self):
87+
my_org = self.find_my_org()
88+
buckets = self.buckets_api.find_buckets().buckets
89+
size = len(buckets)
90+
91+
# create 2 buckets
92+
self.buckets_api.create_bucket(bucket_name=generate_bucket_name(), org_id=my_org.id)
93+
self.buckets_api.create_bucket(bucket_name=generate_bucket_name(), org_id=my_org.id)
94+
95+
buckets = self.buckets_api.find_buckets().buckets
96+
self.assertEqual(size + 2, len(buckets))
97+
98+
# offset 1
99+
buckets = self.buckets_api.find_buckets(offset=1).buckets
100+
self.assertEqual(size + 1, len(buckets))
101+
102+
# count 1
103+
buckets = self.buckets_api.find_buckets(limit=1).buckets
104+
self.assertEqual(1, len(buckets))
105+
86106

87107
if __name__ == '__main__':
88108
unittest.main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy