-
Notifications
You must be signed in to change notification settings - Fork 4
add support for async methods #15
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |||
| SDK for interacting with Basalt datasets | ||||
| """ | ||||
| from typing import Dict, List, Optional, Tuple, Any | ||||
| import asyncio | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove unused asyncio import. The -import asyncio📝 Committable suggestion
Suggested change
🧰 Tools🪛 Flake8 (7.2.0)[error] 5-5: 'asyncio' imported but unused (F401) 🪛 Ruff (0.11.9)5-5: Remove unused import: (F401) 🤖 Prompt for AI Agents |
||||
|
|
||||
| from ..utils.dtos import ( | ||||
| ListDatasetsDTO, GetDatasetDTO, CreateDatasetItemDTO, | ||||
|
|
@@ -46,6 +47,26 @@ def list(self) -> ListDatasetsResult: | |||
| name=dataset.name, | ||||
| columns=dataset.columns | ||||
| ) for dataset in result.datasets] | ||||
|
|
||||
| async def async_list(self) -> ListDatasetsResult: | ||||
| """ | ||||
| Asynchronously list all datasets available in the workspace. | ||||
|
|
||||
| Returns: | ||||
| Tuple[Optional[Exception], Optional[List[DatasetDTO]]]: A tuple containing an optional | ||||
| exception and an optional list of DatasetDTO objects. | ||||
| """ | ||||
| dto = ListDatasetsDTO() | ||||
| err, result = await self._api.async_invoke(ListDatasetsEndpoint, dto) | ||||
|
|
||||
| if err is not None: | ||||
| return err, None | ||||
|
|
||||
| return None, [DatasetDTO( | ||||
| slug=dataset.slug, | ||||
| name=dataset.name, | ||||
| columns=dataset.columns | ||||
| ) for dataset in result.datasets] | ||||
|
|
||||
| def get(self, slug: str) -> GetDatasetResult: | ||||
| """ | ||||
|
|
@@ -68,6 +89,28 @@ def get(self, slug: str) -> GetDatasetResult: | |||
| return Exception(result.error), None | ||||
|
|
||||
| return None, result.dataset | ||||
|
|
||||
| async def async_get(self, slug: str) -> GetDatasetResult: | ||||
| """ | ||||
| Asynchronously get a dataset by its slug. | ||||
|
|
||||
| Args: | ||||
| slug (str): The slug identifier for the dataset. | ||||
|
|
||||
| Returns: | ||||
| Tuple[Optional[Exception], Optional[DatasetDTO]]: A tuple containing an optional | ||||
| exception and an optional DatasetDTO. | ||||
| """ | ||||
| dto = GetDatasetDTO(slug=slug) | ||||
| err, result = await self._api.async_invoke(GetDatasetEndpoint, dto) | ||||
|
|
||||
| if err is not None: | ||||
| return err, None | ||||
|
|
||||
| if result.error: | ||||
| return Exception(result.error), None | ||||
|
|
||||
| return None, result.dataset | ||||
|
|
||||
| def addRow( | ||||
| self, | ||||
|
|
@@ -108,3 +151,43 @@ def addRow( | |||
| return Exception(result.error), None, None | ||||
|
|
||||
| return None, result.datasetRow, result.warning | ||||
|
|
||||
| async def async_addRow( | ||||
| self, | ||||
| slug: str, | ||||
| values: Dict[str, str], | ||||
| name: Optional[str] = None, | ||||
| ideal_output: Optional[str] = None, | ||||
| metadata: Optional[Dict[str, Any]] = None | ||||
| ) -> CreateDatasetItemResult: | ||||
| """ | ||||
| Asynchronously create a new item in a dataset. | ||||
|
|
||||
| Args: | ||||
| slug (str): The slug identifier for the dataset. | ||||
| values (Dict[str, str]): A dictionary of column values for the dataset item. | ||||
| name (Optional[str]): An optional name for the dataset item. | ||||
| ideal_output (Optional[str]): An optional ideal output for the dataset item. | ||||
| metadata (Optional[Dict[str, Any]]): An optional metadata dictionary. | ||||
|
|
||||
| Returns: | ||||
| Tuple[Optional[Exception], Optional[DatasetRowDTO], Optional[str]]: A tuple containing | ||||
| an optional exception, an optional DatasetRowDTO, and an optional warning message. | ||||
| """ | ||||
| dto = CreateDatasetItemDTO( | ||||
| slug=slug, | ||||
| values=values, | ||||
| name=name, | ||||
| idealOutput=ideal_output, | ||||
| metadata=metadata | ||||
| ) | ||||
|
|
||||
| err, result = await self._api.async_invoke(CreateDatasetItemEndpoint, dto) | ||||
|
|
||||
| if err is not None: | ||||
| return err, None, None | ||||
|
|
||||
| if result.error: | ||||
| return Exception(result.error), None, None | ||||
|
|
||||
| return None, result.datasetRow, result.warning | ||||
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.
Fix indentation issues with mixed spaces and tabs.
The indentation on these lines contains mixed spaces and tabs, and the continuation line is misaligned. This violates Python coding standards and will cause formatting issues.
Apply this diff to fix the indentation:
📝 Committable suggestion
🧰 Tools
🪛 Flake8 (7.2.0)
[error] 24-24: indentation contains mixed spaces and tabs
(E101)
[error] 24-24: continuation line unaligned for hanging indent
(E131)
[error] 25-25: indentation contains mixed spaces and tabs
(E101)
🤖 Prompt for AI Agents