@@ -38,6 +38,7 @@ __all__ = [
38
38
"DimensionsMismatch" ,
39
39
"DtypeMismatch" ,
40
40
"EmbeddingSizeMismatch" ,
41
+ "Executor" ,
41
42
"ExpiredTokenError" ,
42
43
"FormatNotSupportedError" ,
43
44
"Future" ,
@@ -113,6 +114,7 @@ __all__ = [
113
114
"UnsupportedPythonType" ,
114
115
"UnsupportedSampleCompression" ,
115
116
"Version" ,
117
+ "VersionNotFoundError" ,
116
118
"WriteFailedError" ,
117
119
"WrongChunkCompression" ,
118
120
"WrongSampleCompression" ,
@@ -134,6 +136,7 @@ __all__ = [
134
136
"open_async" ,
135
137
"open_read_only" ,
136
138
"open_read_only_async" ,
139
+ "prepare_query" ,
137
140
"query" ,
138
141
"query_async" ,
139
142
"schemas" ,
@@ -160,6 +163,9 @@ class Future:
160
163
__await__() -> typing.Any:
161
164
Enables using the Future in async/await syntax.
162
165
166
+ cancel() -> None:
167
+ Cancels the Future if it is still pending.
168
+
163
169
is_completed() -> bool:
164
170
Checks if the Future has resolved without blocking.
165
171
<!-- test-context
@@ -274,6 +280,11 @@ class Future:
274
280
"""
275
281
...
276
282
283
+ def cancel (self ) -> None :
284
+ """
285
+ Cancels the Future if it is still pending.
286
+ """
287
+
277
288
class FutureVoid :
278
289
"""
279
290
A Future representing a void async operation in ML pipelines.
@@ -291,6 +302,9 @@ class FutureVoid:
291
302
is_completed() -> bool:
292
303
Checks completion status without blocking.
293
304
305
+ cancel() -> None:
306
+ Cancels the Future if still pending.
307
+
294
308
<!-- test-context
295
309
```python
296
310
import deeplake
@@ -362,6 +376,11 @@ class FutureVoid:
362
376
"""
363
377
...
364
378
379
+ def cancel (self ) -> None :
380
+ """
381
+ Cancels the Future if it is still pending.
382
+ """
383
+
365
384
def is_completed (self ) -> bool :
366
385
"""
367
386
Checks if the operation has completed without blocking.
@@ -540,6 +559,38 @@ class Metadata(ReadOnlyMetadata):
540
559
"""
541
560
...
542
561
562
+ def prepare_query (query : str , token : str | None = None , creds : dict [str , str ] | None = None ) -> Executor :
563
+ """
564
+ Prepares a TQL query for execution with optional authentication.
565
+
566
+ Args:
567
+ query: TQL query string to execute
568
+ token: Optional Activeloop authentication token
569
+ creds (dict, optional): Dictionary containing credentials used to access the dataset at the path.
570
+
571
+ Returns:
572
+ Executor: An executor object to run the query.
573
+
574
+ <!-- test-context
575
+ ```python
576
+ import deeplake
577
+ ds = deeplake.create("mem://parametriized")
578
+ ds.add_column("category", "text")
579
+ ds.append({"category": ["active", "inactive", "not sure"]})
580
+ ds.commit()
581
+ ```
582
+ -->
583
+
584
+ Examples:
585
+ Running a parametrized batch query:
586
+ ```python
587
+ ex = deeplake.prepare_query('SELECT * FROM "mem://parametriized" WHERE category = ?')
588
+ results = ex.run_batch([["active"], ["inactive"]])
589
+ assert len(results) == 2
590
+ ```
591
+ """
592
+ ...
593
+
543
594
def query (query : str , token : str | None = None , creds : dict [str , str ] | None = None ) -> DatasetView :
544
595
"""
545
596
Executes TQL queries optimized for ML data filtering and search.
@@ -1627,6 +1678,11 @@ class Row:
1627
1678
or await the FutureVoid object in an asynchronous context.
1628
1679
"""
1629
1680
1681
+ def to_dict (self ) -> dict :
1682
+ """
1683
+ Converts the row to a dictionary.
1684
+ """
1685
+
1630
1686
def __str__ (self ) -> str : ...
1631
1687
@property
1632
1688
def row_id (self ) -> int :
@@ -1832,6 +1888,11 @@ class RowView:
1832
1888
or use the Future in an `await` expression.
1833
1889
"""
1834
1890
1891
+ def to_dict (self ) -> dict :
1892
+ """
1893
+ Converts the row to a dictionary.
1894
+ """
1895
+
1835
1896
def __str__ (self ) -> str : ...
1836
1897
@property
1837
1898
def row_id (self ) -> int :
@@ -1942,6 +2003,35 @@ class DatasetView:
1942
2003
"""
1943
2004
...
1944
2005
2006
+ def prepare_query (self , query : str ) -> Executor :
2007
+ """
2008
+ Prepares a query for execution.
2009
+
2010
+ Parameters:
2011
+ query: The query to prepare
2012
+
2013
+ Returns:
2014
+ Executor: The prepared query
2015
+
2016
+ <!-- test-context
2017
+ ```python
2018
+ import deeplake
2019
+ ds = deeplake.create("tmp://")
2020
+ ds.add_column("category", "text")
2021
+ ds.append({"category": ["active", "inactive", "not sure"]})
2022
+ ```
2023
+ -->
2024
+
2025
+ Examples:
2026
+ ```python
2027
+ executor = ds.prepare_query("select * where category == ?")
2028
+ results = executor.run_batch([['active'], ['inactive'], ['not sure']])
2029
+ for row in results:
2030
+ print("Id is: ", row["category"])
2031
+ ```
2032
+ """
2033
+ ...
2034
+
1945
2035
def query (self , query : str ) -> DatasetView :
1946
2036
"""
1947
2037
Executes the given TQL query against the dataset and return the results as a [deeplake.DatasetView][].
@@ -2675,6 +2765,26 @@ class Dataset(DatasetView):
2675
2765
"""
2676
2766
...
2677
2767
2768
+ def refresh (
2769
+ self
2770
+ ) -> None :
2771
+ """
2772
+ Refreshes any new info from the dataset.
2773
+
2774
+ Similar to [deeplake.Dataset.open_read_only][] but the lightweight way.
2775
+ """
2776
+ ...
2777
+
2778
+ def refresh_async (
2779
+ self
2780
+ ) -> FutureVoid :
2781
+ """
2782
+ Asynchronously refreshes any new info from the dataset.
2783
+
2784
+ Similar to [deeplake.Dataset.open_read_only_async][] but the lightweight way.
2785
+ """
2786
+ ...
2787
+
2678
2788
@property
2679
2789
def history (self ) -> History :
2680
2790
"""
@@ -2816,6 +2926,26 @@ class ReadOnlyDataset(DatasetView):
2816
2926
"""
2817
2927
...
2818
2928
2929
+ def refresh (
2930
+ self
2931
+ ) -> None :
2932
+ """
2933
+ Refreshes any new info from the dataset.
2934
+
2935
+ Similar to [deeplake.Dataset.open_read_only][] but the lightweight way.
2936
+ """
2937
+ ...
2938
+
2939
+ def refresh_async (
2940
+ self
2941
+ ) -> FutureVoid :
2942
+ """
2943
+ Asynchronously refreshes any new info from the dataset.
2944
+
2945
+ Similar to [deeplake.Dataset.open_read_only_async][] but the lightweight way.
2946
+ """
2947
+ ...
2948
+
2819
2949
def __getstate__ (self ) -> tuple :
2820
2950
"""Returns a dict that can be pickled and used to restore this dataset.
2821
2951
@@ -2830,6 +2960,14 @@ class ReadOnlyDataset(DatasetView):
2830
2960
state (dict): The pickled state used to restore the dataset.
2831
2961
"""
2832
2962
2963
+ class Executor :
2964
+ def get_query_string (self ) -> str :
2965
+ ...
2966
+ def run_single (self ) -> DatasetView :
2967
+ ...
2968
+ def run_batch (self , parameters : list = None ) -> list :
2969
+ ...
2970
+
2833
2971
class ExpiredTokenError (Exception ):
2834
2972
pass
2835
2973
@@ -3132,6 +3270,9 @@ class StorageNetworkConnectionError(Exception):
3132
3270
class StorageInternalError (Exception ):
3133
3271
pass
3134
3272
3273
+ class VersionNotFoundError (Exception ):
3274
+ pass
3275
+
3135
3276
class WriteFailedError (Exception ):
3136
3277
pass
3137
3278
@@ -3703,4 +3844,4 @@ class TelemetryClient:
3703
3844
Client for logging deeplake messages to telemetry.
3704
3845
"""
3705
3846
endpoint : str
3706
- api_key : str
3847
+ api_key : str
0 commit comments