valkey-glide 1.3.5__pp39-pypy39_pp73-macosx_10_7_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of valkey-glide might be problematic. Click here for more details.

Files changed (37) hide show
  1. glide/__init__.py +330 -0
  2. glide/async_commands/__init__.py +5 -0
  3. glide/async_commands/bitmap.py +311 -0
  4. glide/async_commands/cluster_commands.py +1294 -0
  5. glide/async_commands/command_args.py +102 -0
  6. glide/async_commands/core.py +7040 -0
  7. glide/async_commands/server_modules/ft.py +395 -0
  8. glide/async_commands/server_modules/ft_options/ft_aggregate_options.py +293 -0
  9. glide/async_commands/server_modules/ft_options/ft_constants.py +84 -0
  10. glide/async_commands/server_modules/ft_options/ft_create_options.py +409 -0
  11. glide/async_commands/server_modules/ft_options/ft_profile_options.py +108 -0
  12. glide/async_commands/server_modules/ft_options/ft_search_options.py +131 -0
  13. glide/async_commands/server_modules/glide_json.py +1255 -0
  14. glide/async_commands/server_modules/json_batch.py +790 -0
  15. glide/async_commands/sorted_set.py +402 -0
  16. glide/async_commands/standalone_commands.py +935 -0
  17. glide/async_commands/stream.py +442 -0
  18. glide/async_commands/transaction.py +5175 -0
  19. glide/config.py +590 -0
  20. glide/constants.py +120 -0
  21. glide/exceptions.py +62 -0
  22. glide/glide.pyi +36 -0
  23. glide/glide.pypy39-pp73-darwin.so +0 -0
  24. glide/glide_client.py +604 -0
  25. glide/logger.py +85 -0
  26. glide/protobuf/command_request_pb2.py +54 -0
  27. glide/protobuf/command_request_pb2.pyi +1164 -0
  28. glide/protobuf/connection_request_pb2.py +52 -0
  29. glide/protobuf/connection_request_pb2.pyi +292 -0
  30. glide/protobuf/response_pb2.py +32 -0
  31. glide/protobuf/response_pb2.pyi +101 -0
  32. glide/protobuf_codec.py +109 -0
  33. glide/py.typed +0 -0
  34. glide/routes.py +114 -0
  35. valkey_glide-1.3.5.dist-info/METADATA +125 -0
  36. valkey_glide-1.3.5.dist-info/RECORD +37 -0
  37. valkey_glide-1.3.5.dist-info/WHEEL +4 -0
@@ -0,0 +1,402 @@
1
+ # Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2
+
3
+ from enum import Enum
4
+ from typing import List, Optional, Tuple, Union, cast
5
+
6
+ from glide.async_commands.command_args import Limit, OrderBy
7
+ from glide.constants import TEncodable
8
+
9
+
10
+ class InfBound(Enum):
11
+ """
12
+ Enumeration representing numeric and lexicographic positive and negative infinity bounds for sorted set.
13
+ """
14
+
15
+ POS_INF = {"score_arg": "+inf", "lex_arg": "+"}
16
+ """
17
+ Positive infinity bound for sorted set.
18
+ score_arg: represents numeric positive infinity (+inf).
19
+ lex_arg: represents lexicographic positive infinity (+).
20
+ """
21
+ NEG_INF = {"score_arg": "-inf", "lex_arg": "-"}
22
+ """
23
+ Negative infinity bound for sorted set.
24
+ score_arg: represents numeric negative infinity (-inf).
25
+ lex_arg: represents lexicographic negative infinity (-).
26
+ """
27
+
28
+
29
+ class AggregationType(Enum):
30
+ """
31
+ Enumeration representing aggregation types for `ZINTERSTORE` and `ZUNIONSTORE` sorted set commands.
32
+ """
33
+
34
+ SUM = "SUM"
35
+ """
36
+ Represents aggregation by summing the scores of elements across inputs where they exist.
37
+ """
38
+ MIN = "MIN"
39
+ """
40
+ Represents aggregation by selecting the minimum score of an element across inputs where it exists.
41
+ """
42
+ MAX = "MAX"
43
+ """
44
+ Represents aggregation by selecting the maximum score of an element across inputs where it exists.
45
+ """
46
+
47
+
48
+ class ScoreFilter(Enum):
49
+ """
50
+ Defines which elements to pop from a sorted set.
51
+
52
+ ScoreFilter is a mandatory option for ZMPOP (https://valkey.io/commands/zmpop)
53
+ and BZMPOP (https://valkey.io/commands/bzmpop).
54
+ """
55
+
56
+ MIN = "MIN"
57
+ """
58
+ Pop elements with the lowest scores.
59
+ """
60
+ MAX = "MAX"
61
+ """
62
+ Pop elements with the highest scores.
63
+ """
64
+
65
+
66
+ class ScoreBoundary:
67
+ """
68
+ Represents a specific numeric score boundary in a sorted set.
69
+
70
+ Args:
71
+ value (float): The score value.
72
+ is_inclusive (bool): Whether the score value is inclusive. Defaults to True.
73
+ """
74
+
75
+ def __init__(self, value: float, is_inclusive: bool = True):
76
+ # Convert the score boundary to Valkey protocol format
77
+ self.value = str(value) if is_inclusive else f"({value}"
78
+
79
+
80
+ class LexBoundary:
81
+ """
82
+ Represents a specific lexicographic boundary in a sorted set.
83
+
84
+ Args:
85
+ value (str): The lex value.
86
+ is_inclusive (bool): Whether the score value is inclusive. Defaults to True.
87
+ """
88
+
89
+ def __init__(self, value: str, is_inclusive: bool = True):
90
+ # Convert the lexicographic boundary to Valkey protocol format
91
+ self.value = f"[{value}" if is_inclusive else f"({value}"
92
+
93
+
94
+ class RangeByIndex:
95
+ """
96
+ Represents a range by index (rank) in a sorted set.
97
+
98
+ The `start` and `end` arguments represent zero-based indexes.
99
+
100
+ Args:
101
+ start (int): The start index of the range.
102
+ end (int): The end index of the range.
103
+ """
104
+
105
+ def __init__(self, start: int, end: int):
106
+ self.start = start
107
+ self.end = end
108
+
109
+
110
+ class RangeByScore:
111
+ """
112
+ Represents a range by score in a sorted set.
113
+
114
+ The `start` and `end` arguments represent score boundaries.
115
+
116
+ Args:
117
+ start (Union[InfBound, ScoreBoundary]): The start score boundary.
118
+ end (Union[InfBound, ScoreBoundary]): The end score boundary.
119
+ limit (Optional[Limit]): The limit argument for a range query. Defaults to None. See `Limit` class for more information.
120
+ """
121
+
122
+ def __init__(
123
+ self,
124
+ start: Union[InfBound, ScoreBoundary],
125
+ end: Union[InfBound, ScoreBoundary],
126
+ limit: Optional[Limit] = None,
127
+ ):
128
+ self.start = (
129
+ start.value["score_arg"] if type(start) == InfBound else start.value
130
+ )
131
+ self.end = end.value["score_arg"] if type(end) == InfBound else end.value
132
+ self.limit = limit
133
+
134
+
135
+ class RangeByLex:
136
+ """
137
+ Represents a range by lexicographical order in a sorted set.
138
+
139
+ The `start` and `end` arguments represent lexicographical boundaries.
140
+
141
+ Args:
142
+ start (Union[InfBound, LexBoundary]): The start lexicographic boundary.
143
+ end (Union[InfBound, LexBoundary]): The end lexicographic boundary.
144
+ limit (Optional[Limit]): The limit argument for a range query. Defaults to None. See `Limit` class for more information.
145
+ """
146
+
147
+ def __init__(
148
+ self,
149
+ start: Union[InfBound, LexBoundary],
150
+ end: Union[InfBound, LexBoundary],
151
+ limit: Optional[Limit] = None,
152
+ ):
153
+ self.start = start.value["lex_arg"] if type(start) == InfBound else start.value
154
+ self.end = end.value["lex_arg"] if type(end) == InfBound else end.value
155
+ self.limit = limit
156
+
157
+
158
+ class GeospatialData:
159
+ def __init__(self, longitude: float, latitude: float):
160
+ """
161
+ Represents a geographic position defined by longitude and latitude.
162
+
163
+ The exact limits, as specified by EPSG:900913 / EPSG:3785 / OSGEO:41001 are the following:
164
+ - Valid longitudes are from -180 to 180 degrees.
165
+ - Valid latitudes are from -85.05112878 to 85.05112878 degrees.
166
+
167
+ Args:
168
+ longitude (float): The longitude coordinate.
169
+ latitude (float): The latitude coordinate.
170
+ """
171
+ self.longitude = longitude
172
+ self.latitude = latitude
173
+
174
+
175
+ class GeoUnit(Enum):
176
+ """
177
+ Enumeration representing distance units options for the `GEODIST` command.
178
+ """
179
+
180
+ METERS = "m"
181
+ """
182
+ Represents distance in meters.
183
+ """
184
+ KILOMETERS = "km"
185
+ """
186
+ Represents distance in kilometers.
187
+ """
188
+ MILES = "mi"
189
+ """
190
+ Represents distance in miles.
191
+ """
192
+ FEET = "ft"
193
+ """
194
+ Represents distance in feet.
195
+ """
196
+
197
+
198
+ class GeoSearchByRadius:
199
+ """
200
+ Represents search criteria of searching within a certain radius from a specified point.
201
+
202
+ Args:
203
+ radius (float): Radius of the search area.
204
+ unit (GeoUnit): Unit of the radius. See `GeoUnit`.
205
+ """
206
+
207
+ def __init__(self, radius: float, unit: GeoUnit):
208
+ """
209
+ Initialize the search criteria.
210
+ """
211
+ self.radius = radius
212
+ self.unit = unit
213
+
214
+ def to_args(self) -> List[str]:
215
+ """
216
+ Convert the search criteria to the corresponding part of the command.
217
+
218
+ Returns:
219
+ List[str]: List representation of the search criteria.
220
+ """
221
+ return ["BYRADIUS", str(self.radius), self.unit.value]
222
+
223
+
224
+ class GeoSearchByBox:
225
+ """
226
+ Represents search criteria of searching within a specified rectangular area.
227
+
228
+ Args:
229
+ width (float): Width of the bounding box.
230
+ height (float): Height of the bounding box
231
+ unit (GeoUnit): Unit of the radius. See `GeoUnit`.
232
+ """
233
+
234
+ def __init__(self, width: float, height: float, unit: GeoUnit):
235
+ """
236
+ Initialize the search criteria.
237
+ """
238
+ self.width = width
239
+ self.height = height
240
+ self.unit = unit
241
+
242
+ def to_args(self) -> List[str]:
243
+ """
244
+ Convert the search criteria to the corresponding part of the command.
245
+
246
+ Returns:
247
+ List[str]: List representation of the search criteria.
248
+ """
249
+ return ["BYBOX", str(self.width), str(self.height), self.unit.value]
250
+
251
+
252
+ class GeoSearchCount:
253
+ """
254
+ Represents the count option for limiting the number of results in a GeoSearch.
255
+
256
+ Args:
257
+ count (int): The maximum number of results to return.
258
+ any_option (bool): Whether to allow returning as enough matches are found.
259
+ This means that the results returned may not be the ones closest to the specified point. Default to False.
260
+ """
261
+
262
+ def __init__(self, count: int, any_option: bool = False):
263
+ """
264
+ Initialize the count option.
265
+ """
266
+ self.count = count
267
+ self.any_option = any_option
268
+
269
+ def to_args(self) -> List[str]:
270
+ """
271
+ Convert the count option to the corresponding part of the command.
272
+
273
+ Returns:
274
+ List[str]: List representation of the count option.
275
+ """
276
+ if self.any_option:
277
+ return ["COUNT", str(self.count), "ANY"]
278
+ return ["COUNT", str(self.count)]
279
+
280
+
281
+ def _create_zrange_args(
282
+ key: TEncodable,
283
+ range_query: Union[RangeByLex, RangeByScore, RangeByIndex],
284
+ reverse: bool,
285
+ with_scores: bool,
286
+ destination: Optional[TEncodable] = None,
287
+ ) -> List[TEncodable]:
288
+ args = [destination] if destination else []
289
+ args += [key, str(range_query.start), str(range_query.end)]
290
+
291
+ if isinstance(range_query, RangeByScore):
292
+ args.append("BYSCORE")
293
+ elif isinstance(range_query, RangeByLex):
294
+ args.append("BYLEX")
295
+ if reverse:
296
+ args.append("REV")
297
+ if hasattr(range_query, "limit") and range_query.limit is not None:
298
+ args.extend(
299
+ [
300
+ "LIMIT",
301
+ str(range_query.limit.offset),
302
+ str(range_query.limit.count),
303
+ ]
304
+ )
305
+ if with_scores:
306
+ args.append("WITHSCORES")
307
+
308
+ return args
309
+
310
+
311
+ def separate_keys(
312
+ keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
313
+ ) -> Tuple[List[TEncodable], List[TEncodable]]:
314
+ """
315
+ Returns separate lists of keys and weights in case of weighted keys.
316
+ """
317
+ if not keys:
318
+ return [], []
319
+
320
+ key_list: List[TEncodable] = []
321
+ weight_list: List[TEncodable] = []
322
+
323
+ if isinstance(keys[0], tuple):
324
+ for item in keys:
325
+ key = item[0]
326
+ weight = item[1]
327
+ key_list.append(cast(TEncodable, key))
328
+ weight_list.append(cast(TEncodable, str(weight)))
329
+ else:
330
+ key_list.extend(cast(List[TEncodable], keys))
331
+
332
+ return key_list, weight_list
333
+
334
+
335
+ def _create_zinter_zunion_cmd_args(
336
+ keys: Union[List[TEncodable], List[Tuple[TEncodable, float]]],
337
+ aggregation_type: Optional[AggregationType] = None,
338
+ destination: Optional[TEncodable] = None,
339
+ ) -> List[TEncodable]:
340
+ args: List[TEncodable] = []
341
+
342
+ if destination:
343
+ args.append(destination)
344
+
345
+ args.append(str(len(keys)))
346
+
347
+ only_keys, weights = separate_keys(keys)
348
+
349
+ args.extend(only_keys)
350
+
351
+ if weights:
352
+ args.append("WEIGHTS")
353
+ args.extend(weights)
354
+
355
+ if aggregation_type:
356
+ args.append("AGGREGATE")
357
+ args.append(aggregation_type.value)
358
+
359
+ return args
360
+
361
+
362
+ def _create_geosearch_args(
363
+ keys: List[TEncodable],
364
+ search_from: Union[str, bytes, GeospatialData],
365
+ search_by: Union[GeoSearchByRadius, GeoSearchByBox],
366
+ order_by: Optional[OrderBy] = None,
367
+ count: Optional[GeoSearchCount] = None,
368
+ with_coord: bool = False,
369
+ with_dist: bool = False,
370
+ with_hash: bool = False,
371
+ store_dist: bool = False,
372
+ ) -> List[TEncodable]:
373
+ args: List[TEncodable] = keys
374
+ if isinstance(search_from, (str, bytes)):
375
+ args.extend(["FROMMEMBER", search_from])
376
+ else:
377
+ args.extend(
378
+ [
379
+ "FROMLONLAT",
380
+ str(search_from.longitude),
381
+ str(search_from.latitude),
382
+ ]
383
+ )
384
+
385
+ args.extend(search_by.to_args())
386
+
387
+ if order_by:
388
+ args.append(order_by.value)
389
+ if count:
390
+ args.extend(count.to_args())
391
+
392
+ if with_coord:
393
+ args.append("WITHCOORD")
394
+ if with_dist:
395
+ args.append("WITHDIST")
396
+ if with_hash:
397
+ args.append("WITHHASH")
398
+
399
+ if store_dist:
400
+ args.append("STOREDIST")
401
+
402
+ return args