-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reading custom endpoint results SDK support #132
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4fc844b
reading custom endpoint results works locally.
philippWassibauer 3e55683
Update dune_client/api/custom.py
a812f5b
add docstrings
philippWassibauer 13fcc1b
Merge branch 'add-custom-endpoints' of github.com:duneanalytics/dune-…
philippWassibauer 9aa2f86
fix to get pylint to play
philippWassibauer 92254e1
add basic integration testing for custom endpoints
philippWassibauer fc3a52b
fix
philippWassibauer 8b20bad
test naming fix
philippWassibauer bbfb862
fix pyling
philippWassibauer e41ff9c
linted
philippWassibauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
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, | ||
) | ||
|
||
# pylint: disable=duplicate-code | ||
class CustomEndpointAPI(BaseRouter): | ||
""" | ||
Custom endpoints API implementation. | ||
Methods: | ||
get_custom_endpoint_result(): returns the results of a custom endpoint. | ||
""" | ||
|
||
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: | ||
""" | ||
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 | ||
|
||
philippWassibauer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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_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) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is likely because of all the filter arguments and suggests a deeper change to the project. Introduce a
ResultFilter
structure that contains all the filtering possibilities:Then here would look more like:
It would resolve both duplicated code lint warning and also reduce the "argument overload" lint error that is being globally suppressed here
dune-client/.pylintrc
Line 4 in ed3836d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will log this and do at another time.