Skip to content

Commit f480b4e

Browse files
authored
Merge pull request #179 from fastlabel/feature/dataset-api
feat: public api for dataset
2 parents cafcf7b + c06a66b commit f480b4e

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2393,6 +2393,8 @@ Create a new dataset.
23932393
```python
23942394
dataset = client.create_dataset(
23952395
name="object-detection", # Only lowercase alphanumeric characters + hyphen is available
2396+
tags=["cat", "dog"], # max 5 tags per dataset.
2397+
visibility="workspace", # visibility can be 'workspace' or 'public'. workspace is only visible to your workspace members. public is visible to all users.
23962398
license="The MIT License" # Optional
23972399
)
23982400
```
@@ -2405,6 +2407,8 @@ See API docs for details.
24052407
{
24062408
'id': 'YOUR_DATASET_ID',
24072409
'name': 'object-detection',
2410+
'tags': ['cat', 'dog'],
2411+
'visibility': 'workspace',
24082412
'license': 'The MIT License',
24092413
'createdAt': '2022-10-31T02:20:00.248Z',
24102414
'updatedAt': '2022-10-31T02:20:00.248Z'
@@ -2431,11 +2435,13 @@ datasets = client.get_datasets()
24312435

24322436
The success response is the same as when created, but it is an array.
24332437

2434-
You can filter by type and keywords.
2438+
You can filter by keywords and visibility, tags.
24352439

24362440
```python
24372441
datasets = client.get_datasets(
2438-
keyword="dog"
2442+
keyword="dog",
2443+
tags=["cat", "dog"], # max 5 tags per dataset.
2444+
visibility="workspace", # visibility can be 'workspace' or 'public'.
24392445
)
24402446
```
24412447

@@ -2447,7 +2453,7 @@ Update a single dataset.
24472453

24482454
```python
24492455
dataset = client.update_dataset(
2450-
dataset_id="YOUR_DATASET_ID", name="object-detection"
2456+
dataset_id="YOUR_DATASET_ID", name="object-detection", tags=["cat", "dog"]
24512457
)
24522458
```
24532459

fastlabel/__init__.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,59 +3831,62 @@ def find_dataset(self, dataset_id: str) -> dict:
38313831
def get_datasets(
38323832
self,
38333833
keyword: str = None,
3834-
offset: int = None,
3835-
limit: int = 100,
3834+
tags: List[str] = [],
3835+
visibility: str = None,
38363836
) -> list:
38373837
"""
3838-
Returns a list of datasets with latest version.
3839-
3840-
Returns up to 1000 at a time, to get more, set offset as the starting position
3841-
to fetch.
3838+
Returns a list of datasets.
38423839
38433840
keyword are search terms in the dataset slug (Optional).
3844-
offset is the starting position number to fetch (Optional).
3845-
limit is the max number to fetch (Optional).
3841+
tags are search terms in the dataset tags (Optional).
3842+
visibility are search terms in the dataset visibility.(Optional).
38463843
"""
3847-
if limit > 1000:
3848-
raise FastLabelInvalidException(
3849-
"Limit must be less than or equal to 1000.", 422
3850-
)
38513844
endpoint = "datasets"
38523845
params = {}
38533846
if keyword:
38543847
params["keyword"] = keyword
3855-
if type:
3856-
params["type"] = type
3857-
if offset:
3858-
params["offset"] = offset
3859-
if limit:
3860-
params["limit"] = limit
3848+
if tags:
3849+
params["tags"] = tags
3850+
if visibility:
3851+
params["visibility"] = visibility
38613852
return self.api.get_request(endpoint, params=params)
38623853

3863-
def create_dataset(self, name: str, license: str = "") -> dict:
3854+
def create_dataset(
3855+
self, name: str, tags: List[str] = [], visibility: str = None, license: str = ""
3856+
) -> dict:
38643857
"""
38653858
Create a dataset.
38663859
38673860
name is name of your dataset. Only lowercase alphanumeric characters + hyphen is available (Required).
3861+
tags is a list of tag (Optional).
3862+
visibility are search terms in the dataset visibility.(Optional).
38683863
license is a license name of your dataset. (Optional)
38693864
"""
38703865
endpoint = "datasets"
38713866
payload = {"name": name, "license": license}
3867+
if tags:
3868+
payload["tags"] = tags
3869+
if visibility:
3870+
payload["visibility"] = visibility
38723871
return self.api.post_request(endpoint, payload=payload)
38733872

38743873
def update_dataset(
38753874
self,
38763875
dataset_id: str,
38773876
name: str = None,
3877+
tags: List[str] = [],
38783878
) -> dict:
38793879
"""
38803880
Update a dataset.
38813881
38823882
dataset_id is an id of the dataset (Required).
38833883
name is name of your dataset (Required).
3884+
tags is a list of tag (Optional).
38843885
"""
38853886
endpoint = "datasets/" + dataset_id
38863887
payload = {"name": name}
3888+
if tags:
3889+
payload["tags"] = tags
38873890
return self.api.put_request(endpoint, payload=payload)
38883891

38893892
def delete_dataset(self, dataset_id: str) -> None:

0 commit comments

Comments
 (0)