Skip to content

Commit 22a2659

Browse files
author
waddahAldrobi
authored
Merge pull request #119 from duneanalytics/support-delete-table-endpoint
Add `delete` table endpoint to sdk
2 parents 3eab3fb + 1978a84 commit 22a2659

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ _version.py
77
venv/
88
tmp/
99
.vscode/
10+
build/
11+
.DS_Store

dune_client/api/base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,14 @@ def _patch(self, route: str, params: Any) -> Any:
209209
timeout=self.request_timeout,
210210
)
211211
return self._handle_response(response)
212+
213+
def _delete(self, route: str) -> Any:
214+
"""Generic interface for the DELETE method of a Dune API request"""
215+
url = self._route_url(route)
216+
self.logger.debug(f"DELETE received input url={url}")
217+
response = self.http.delete(
218+
url=url,
219+
headers=self.default_headers(),
220+
timeout=self.request_timeout,
221+
)
222+
return self._handle_response(response)

dune_client/api/table.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
from typing import List, Dict, IO
88

99
from dune_client.api.base import BaseRouter
10-
from dune_client.models import DuneError, InsertTableResult, CreateTableResult
10+
from dune_client.models import (
11+
DuneError,
12+
InsertTableResult,
13+
CreateTableResult,
14+
DeleteTableResult,
15+
)
1116

1217

1318
class TableAPI(BaseRouter):
@@ -99,3 +104,12 @@ def insert_table(
99104
data=data,
100105
)
101106
return InsertTableResult.from_dict(result_json)
107+
108+
def delete_table(self, namespace: str, table_name: str) -> DeleteTableResult:
109+
"""
110+
https://docs.dune.com/api-reference/tables/endpoint/delete
111+
The delete table endpoint allows you to delete an existing table in Dune.
112+
"""
113+
114+
response_json = self._delete(route=f"/table/{namespace}/{table_name}")
115+
return DeleteTableResult.from_dict(response_json)

dune_client/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,12 @@ class InsertTableResult(DataClassJsonMixin):
375375
"""
376376

377377
rows_written: int
378+
379+
380+
@dataclass
381+
class DeleteTableResult(DataClassJsonMixin):
382+
"""
383+
Data type returned by table/delete operation
384+
"""
385+
386+
message: str

tests/e2e/test_client.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
DuneError,
1414
InsertTableResult,
1515
CreateTableResult,
16+
DeleteTableResult,
1617
)
1718
from dune_client.types import QueryParameter
1819
from dune_client.client import DuneClient
@@ -226,7 +227,7 @@ def test_get_latest_result_with_query_id(self):
226227
results = dune.get_latest_result(self.query.query_id).get_rows()
227228
self.assertGreater(len(results), 0)
228229

229-
@unittest.skip("This is a plus subscription endpoint.")
230+
@unittest.skip("Requires custom namespace and table_name input.")
230231
def test_upload_csv_success(self):
231232
client = DuneClient(self.valid_api_key)
232233
self.assertEqual(
@@ -238,7 +239,7 @@ def test_upload_csv_success(self):
238239
True,
239240
)
240241

241-
@unittest.skip("This is a plus subscription endpoint.")
242+
@unittest.skip("Requires custom namespace and table_name input.")
242243
def test_create_table_success(self):
243244
# Make sure the table doesn't already exist.
244245
# You will need to change the namespace to your own.
@@ -268,7 +269,7 @@ def test_create_table_success(self):
268269
),
269270
)
270271

271-
@unittest.skip("This is a plus subscription endpoint.")
272+
@unittest.skip("Requires custom namespace and table_name input.")
272273
def test_insert_table_csv_success(self):
273274
# Make sure the table already exists and csv matches table schema.
274275
# You will need to change the namespace to your own.
@@ -284,7 +285,7 @@ def test_insert_table_csv_success(self):
284285
InsertTableResult(rows_written=1),
285286
)
286287

287-
@unittest.skip("This is a plus subscription endpoint.")
288+
@unittest.skip("Requires custom namespace and table_name input.")
288289
def test_insert_table_json_success(self):
289290
# Make sure the table already exists and json matches table schema.
290291
# You will need to change the namespace to your own.
@@ -300,6 +301,27 @@ def test_insert_table_json_success(self):
300301
InsertTableResult(rows_written=1),
301302
)
302303

304+
@unittest.skip("Requires custom namespace and table_name input.")
305+
def test_delete_table_success(self):
306+
# Make sure the table doesn't already exist.
307+
# You will need to change the namespace to your own.
308+
client = DuneClient(self.valid_api_key)
309+
310+
namespace = "test"
311+
table_name = "dataset_e2e_test"
312+
313+
self.assertEqual(
314+
client.delete_table(
315+
namespace=namespace,
316+
table_name=table_name,
317+
),
318+
DeleteTableResult.from_dict(
319+
{
320+
"message": "Table teamwaddah.waddah_test3 successfully deleted",
321+
}
322+
),
323+
)
324+
303325
def test_download_csv_with_pagination(self):
304326
# Arrange
305327
client = DuneClient(self.valid_api_key)

0 commit comments

Comments
 (0)