From 4fc844b4df1985ace07e4e8fa193ac6de593ae85 Mon Sep 17 00:00:00 2001 From: Philipp Wassibauer Date: Sun, 16 Jun 2024 14:37:56 +0100 Subject: [PATCH 1/9] reading custom endpoint results works locally. --- dune_client/api/custom.py | 52 +++++++++++++++++++++++++++++++++++ dune_client/api/extensions.py | 3 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 dune_client/api/custom.py diff --git a/dune_client/api/custom.py b/dune_client/api/custom.py new file mode 100644 index 0000000..b581172 --- /dev/null +++ b/dune_client/api/custom.py @@ -0,0 +1,52 @@ +""" +Custom endpoints API enables users to +fetch and filter data from custom endpoints. +""" + +from __future__ import annotations +from typing import List, Optional + +from dune_client.api.base import BaseRouter +from dune_client.models import ( + DuneError, + ResultsResponse, +) + + +class CustomEndpointAPI(BaseRouter): + """ + + """ + + def get_custom_endpoint_result( + self, + handle: str, + endpoint: str, + limit: Optional[int] = None, + offset: Optional[int] = None, + columns: Optional[List[str]] = None, + sample_count: Optional[int] = None, + filters: Optional[str] = None, + sort_by: Optional[List[str]] = None, + ) -> ResultsResponse: + """ + + """ + params = self._build_parameters( + columns=columns, + sample_count=sample_count, + filters=filters, + sort_by=sort_by, + limit=limit, + offset=offset, + ) + response_json = self._get( + route=f"/endpoints/{handle}/{endpoint}/results", + params=params, + ) + try: + return ResultsResponse.from_dict(response_json) + except KeyError as err: + raise DuneError(response_json, "ResultsResponse", err) from err + + \ No newline at end of file diff --git a/dune_client/api/extensions.py b/dune_client/api/extensions.py index e4c074c..3aba004 100644 --- a/dune_client/api/extensions.py +++ b/dune_client/api/extensions.py @@ -20,6 +20,7 @@ from dune_client.api.execution import ExecutionAPI from dune_client.api.query import QueryAPI from dune_client.api.table import TableAPI +from dune_client.api.custom import CustomEndpointAPI from dune_client.models import ( ResultsResponse, DuneError, @@ -37,7 +38,7 @@ POLL_FREQUENCY_SECONDS = 1 -class ExtendedAPI(ExecutionAPI, QueryAPI, TableAPI): +class ExtendedAPI(ExecutionAPI, QueryAPI, TableAPI, CustomEndpointAPI): """ Provides higher level helper methods for faster and easier development on top of the base ExecutionAPI. From 3e5568340e7730a80ef3aa4a67ca57b675ae4729 Mon Sep 17 00:00:00 2001 From: Philipp Wassibauer Date: Mon, 17 Jun 2024 09:14:28 +0100 Subject: [PATCH 2/9] Update dune_client/api/custom.py Co-authored-by: Benjamin Smith --- dune_client/api/custom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dune_client/api/custom.py b/dune_client/api/custom.py index b581172..3a0291f 100644 --- a/dune_client/api/custom.py +++ b/dune_client/api/custom.py @@ -49,4 +49,4 @@ def get_custom_endpoint_result( except KeyError as err: raise DuneError(response_json, "ResultsResponse", err) from err - \ No newline at end of file + From a812f5b2165fb73f369d76838c3bee82bba3d2c9 Mon Sep 17 00:00:00 2001 From: Philipp Wassibauer Date: Mon, 17 Jun 2024 09:49:32 +0100 Subject: [PATCH 3/9] add docstrings --- dune_client/api/custom.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/dune_client/api/custom.py b/dune_client/api/custom.py index b581172..9662300 100644 --- a/dune_client/api/custom.py +++ b/dune_client/api/custom.py @@ -15,7 +15,9 @@ class CustomEndpointAPI(BaseRouter): """ - + Custom endpoints API implementation. + Methods: + get_custom_endpoint_result(): returns the results of a custom endpoint. """ def get_custom_endpoint_result( @@ -30,7 +32,18 @@ def get_custom_endpoint_result( sort_by: Optional[List[str]] = None, ) -> ResultsResponse: """ + Custom endpoints allow you to fetch and filter data from any custom endpoint you created. + More information on Custom Endpoints can be round here: https://docs.dune.com/api-reference/custom/overview + Args: + handle (str): The handle of the team/user. + endpoint (str): The slug of the custom endpoint. + limit (int, optional): The maximum number of results to return. + offset (int, optional): The number of results to skip. + columns (List[str], optional): A list of columns to return. + sample_count (int, optional): The number of results to return. + filters (str, optional): The filters to apply. + sort_by (List[str], optional): The columns to sort by. """ params = self._build_parameters( columns=columns, @@ -49,4 +62,3 @@ def get_custom_endpoint_result( except KeyError as err: raise DuneError(response_json, "ResultsResponse", err) from err - \ No newline at end of file From 9aa2f863835e1347d66c802688b71cb6bcae8bca Mon Sep 17 00:00:00 2001 From: Philipp Wassibauer Date: Mon, 17 Jun 2024 10:17:55 +0100 Subject: [PATCH 4/9] fix to get pylint to play --- dune_client/api/custom.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dune_client/api/custom.py b/dune_client/api/custom.py index 9662300..d351d02 100644 --- a/dune_client/api/custom.py +++ b/dune_client/api/custom.py @@ -32,8 +32,10 @@ def get_custom_endpoint_result( sort_by: Optional[List[str]] = None, ) -> ResultsResponse: """ - Custom endpoints allow you to fetch and filter data from any custom endpoint you created. - More information on Custom Endpoints can be round here: https://docs.dune.com/api-reference/custom/overview + Custom endpoints allow you to fetch and filter data from any + custom endpoint you created. + More information on Custom Endpoints can be round here: + https://docs.dune.com/api-reference/custom/overview Args: handle (str): The handle of the team/user. @@ -61,4 +63,3 @@ def get_custom_endpoint_result( return ResultsResponse.from_dict(response_json) except KeyError as err: raise DuneError(response_json, "ResultsResponse", err) from err - From 92254e1759894cc2008f77244607d0f95051d96b Mon Sep 17 00:00:00 2001 From: Philipp Wassibauer Date: Wed, 19 Jun 2024 14:36:17 +0100 Subject: [PATCH 5/9] add basic integration testing for custom endpoints --- tests/e2e/test_custom_endpoints.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/e2e/test_custom_endpoints.py diff --git a/tests/e2e/test_custom_endpoints.py b/tests/e2e/test_custom_endpoints.py new file mode 100644 index 0000000..3faf7ab --- /dev/null +++ b/tests/e2e/test_custom_endpoints.py @@ -0,0 +1,25 @@ +import copy +import os +import time +import unittest + +import dotenv + +from dune_client.client import DuneClient + +dotenv.load_dotenv() + + +class TestCustomEndpoints(unittest.TestCase): + def setUp(self) -> None: + self.valid_api_key = os.environ["DUNE_API_KEY"] + + def test_get_execution_status(self): + dune = DuneClient(self.valid_api_key) + results = dune.get_custom_endpoint_result("dune", "new-test") + self.assertEqual(len(results.get_rows()), 10) + self.assertEqual(len(results.get_columns()), 5) + + +if __name__ == "__main__": + unittest.main() From fc3a52bff209a39db9ff0249ad4c9ec1e5cdfa12 Mon Sep 17 00:00:00 2001 From: Philipp Wassibauer Date: Wed, 19 Jun 2024 14:42:09 +0100 Subject: [PATCH 6/9] fix --- tests/e2e/test_custom_endpoints.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/e2e/test_custom_endpoints.py b/tests/e2e/test_custom_endpoints.py index 3faf7ab..1c6a637 100644 --- a/tests/e2e/test_custom_endpoints.py +++ b/tests/e2e/test_custom_endpoints.py @@ -18,8 +18,6 @@ def test_get_execution_status(self): dune = DuneClient(self.valid_api_key) results = dune.get_custom_endpoint_result("dune", "new-test") self.assertEqual(len(results.get_rows()), 10) - self.assertEqual(len(results.get_columns()), 5) - if __name__ == "__main__": unittest.main() From 8b20baddd604cc0d45a6e462e8a86ffa1e450d8d Mon Sep 17 00:00:00 2001 From: Philipp Wassibauer Date: Wed, 19 Jun 2024 14:42:44 +0100 Subject: [PATCH 7/9] test naming fix --- tests/e2e/test_custom_endpoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/test_custom_endpoints.py b/tests/e2e/test_custom_endpoints.py index 1c6a637..cf87aff 100644 --- a/tests/e2e/test_custom_endpoints.py +++ b/tests/e2e/test_custom_endpoints.py @@ -14,7 +14,7 @@ class TestCustomEndpoints(unittest.TestCase): def setUp(self) -> None: self.valid_api_key = os.environ["DUNE_API_KEY"] - def test_get_execution_status(self): + def test_gettin_custom_endpoint_results(self): dune = DuneClient(self.valid_api_key) results = dune.get_custom_endpoint_result("dune", "new-test") self.assertEqual(len(results.get_rows()), 10) From bbfb862c3159a00fe79ecdda8c9a865fed39678e Mon Sep 17 00:00:00 2001 From: Philipp Wassibauer Date: Thu, 20 Jun 2024 09:43:37 +0100 Subject: [PATCH 8/9] fix pyling --- dune_client/api/custom.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dune_client/api/custom.py b/dune_client/api/custom.py index d351d02..704bc2b 100644 --- a/dune_client/api/custom.py +++ b/dune_client/api/custom.py @@ -12,7 +12,7 @@ ResultsResponse, ) - +# pylint: disable=duplicate-code class CustomEndpointAPI(BaseRouter): """ Custom endpoints API implementation. From e41ff9c5d876478d787b03bfe7f32a2adfd0e4a1 Mon Sep 17 00:00:00 2001 From: Philipp Wassibauer Date: Thu, 20 Jun 2024 18:22:48 +0100 Subject: [PATCH 9/9] linted --- dune_client/api/custom.py | 9 +++++---- tests/e2e/test_custom_endpoints.py | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dune_client/api/custom.py b/dune_client/api/custom.py index 704bc2b..3809036 100644 --- a/dune_client/api/custom.py +++ b/dune_client/api/custom.py @@ -12,6 +12,7 @@ ResultsResponse, ) + # pylint: disable=duplicate-code class CustomEndpointAPI(BaseRouter): """ @@ -32,12 +33,12 @@ def get_custom_endpoint_result( sort_by: Optional[List[str]] = None, ) -> ResultsResponse: """ - Custom endpoints allow you to fetch and filter data from any + Custom endpoints allow you to fetch and filter data from any custom endpoint you created. - More information on Custom Endpoints can be round here: + More information on Custom Endpoints can be round here: https://docs.dune.com/api-reference/custom/overview - - Args: + + Args: handle (str): The handle of the team/user. endpoint (str): The slug of the custom endpoint. limit (int, optional): The maximum number of results to return. diff --git a/tests/e2e/test_custom_endpoints.py b/tests/e2e/test_custom_endpoints.py index cf87aff..2f12d45 100644 --- a/tests/e2e/test_custom_endpoints.py +++ b/tests/e2e/test_custom_endpoints.py @@ -19,5 +19,6 @@ def test_gettin_custom_endpoint_results(self): results = dune.get_custom_endpoint_result("dune", "new-test") self.assertEqual(len(results.get_rows()), 10) + if __name__ == "__main__": unittest.main()