valkey-glide 2.2.1rc1__cp313-cp313-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 (40) hide show
  1. glide/__init__.py +388 -0
  2. glide/async_commands/__init__.py +5 -0
  3. glide/async_commands/cluster_commands.py +1476 -0
  4. glide/async_commands/core.py +7818 -0
  5. glide/async_commands/ft.py +465 -0
  6. glide/async_commands/glide_json.py +1269 -0
  7. glide/async_commands/standalone_commands.py +1001 -0
  8. glide/glide.cpython-313-darwin.so +0 -0
  9. glide/glide.pyi +61 -0
  10. glide/glide_client.py +821 -0
  11. glide/logger.py +97 -0
  12. glide/opentelemetry.py +185 -0
  13. glide/py.typed +0 -0
  14. glide_shared/__init__.py +330 -0
  15. glide_shared/commands/__init__.py +0 -0
  16. glide_shared/commands/batch.py +5997 -0
  17. glide_shared/commands/batch_options.py +261 -0
  18. glide_shared/commands/bitmap.py +320 -0
  19. glide_shared/commands/command_args.py +103 -0
  20. glide_shared/commands/core_options.py +407 -0
  21. glide_shared/commands/server_modules/ft_options/ft_aggregate_options.py +300 -0
  22. glide_shared/commands/server_modules/ft_options/ft_constants.py +84 -0
  23. glide_shared/commands/server_modules/ft_options/ft_create_options.py +423 -0
  24. glide_shared/commands/server_modules/ft_options/ft_profile_options.py +113 -0
  25. glide_shared/commands/server_modules/ft_options/ft_search_options.py +139 -0
  26. glide_shared/commands/server_modules/json_batch.py +820 -0
  27. glide_shared/commands/server_modules/json_options.py +93 -0
  28. glide_shared/commands/sorted_set.py +412 -0
  29. glide_shared/commands/stream.py +449 -0
  30. glide_shared/config.py +975 -0
  31. glide_shared/constants.py +124 -0
  32. glide_shared/exceptions.py +88 -0
  33. glide_shared/protobuf/command_request_pb2.py +56 -0
  34. glide_shared/protobuf/connection_request_pb2.py +56 -0
  35. glide_shared/protobuf/response_pb2.py +32 -0
  36. glide_shared/protobuf_codec.py +110 -0
  37. glide_shared/routes.py +161 -0
  38. valkey_glide-2.2.1rc1.dist-info/METADATA +210 -0
  39. valkey_glide-2.2.1rc1.dist-info/RECORD +40 -0
  40. valkey_glide-2.2.1rc1.dist-info/WHEEL +4 -0
@@ -0,0 +1,465 @@
1
+ # Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2
+ """
3
+ module for `vector search` commands.
4
+ """
5
+
6
+ from typing import List, Mapping, Optional, cast
7
+
8
+ from glide_shared.commands.server_modules.ft_options.ft_aggregate_options import (
9
+ FtAggregateOptions,
10
+ )
11
+ from glide_shared.commands.server_modules.ft_options.ft_constants import (
12
+ CommandNames,
13
+ FtCreateKeywords,
14
+ )
15
+ from glide_shared.commands.server_modules.ft_options.ft_create_options import (
16
+ Field,
17
+ FtCreateOptions,
18
+ )
19
+ from glide_shared.commands.server_modules.ft_options.ft_profile_options import (
20
+ FtProfileOptions,
21
+ )
22
+ from glide_shared.commands.server_modules.ft_options.ft_search_options import (
23
+ FtSearchOptions,
24
+ )
25
+ from glide_shared.constants import (
26
+ TOK,
27
+ FtAggregateResponse,
28
+ FtInfoResponse,
29
+ FtProfileResponse,
30
+ FtSearchResponse,
31
+ TEncodable,
32
+ )
33
+
34
+ from ..glide_client import TGlideClient
35
+
36
+
37
+ async def create(
38
+ client: TGlideClient,
39
+ index_name: TEncodable,
40
+ schema: List[Field],
41
+ options: Optional[FtCreateOptions] = None,
42
+ ) -> TOK:
43
+ """
44
+ Creates an index and initiates a backfill of that index.
45
+
46
+ Args:
47
+ client (TGlideClient): The client to execute the command.
48
+ index_name (TEncodable): The index name.
49
+ schema (List[Field]): Fields to populate into the index. Equivalent to `SCHEMA` block in the module API.
50
+ options (Optional[FtCreateOptions]): Optional arguments for the FT.CREATE command.
51
+
52
+ Returns:
53
+ TOK: A simple "OK" response.
54
+
55
+ Examples:
56
+ >>> from glide import ft
57
+ >>> schema: List[Field] = [TextField("title")]
58
+ >>> prefixes: List[str] = ["blog:post:"]
59
+ >>> await ft.create(glide_client, "my_idx1", schema, FtCreateOptions(DataType.HASH, prefixes))
60
+ 'OK' # Indicates successful creation of index named 'idx'
61
+ """
62
+ args: List[TEncodable] = [CommandNames.FT_CREATE, index_name]
63
+ if options:
64
+ args.extend(options.to_args())
65
+ if schema:
66
+ args.append(FtCreateKeywords.SCHEMA)
67
+ for field in schema:
68
+ args.extend(field.to_args())
69
+ return cast(TOK, await client.custom_command(args))
70
+
71
+
72
+ async def dropindex(client: TGlideClient, index_name: TEncodable) -> TOK:
73
+ """
74
+ Drops an index. The index definition and associated content are deleted. Keys are unaffected.
75
+
76
+ Args:
77
+ client (TGlideClient): The client to execute the command.
78
+ index_name (TEncodable): The index name for the index to be dropped.
79
+
80
+ Returns:
81
+ TOK: A simple "OK" response.
82
+
83
+ Examples:
84
+ For the following example to work, an index named 'idx' must be already created. If not created, you will get an error.
85
+ >>> from glide import ft
86
+ >>> index_name = "idx"
87
+ >>> await ft.dropindex(glide_client, index_name)
88
+ 'OK' # Indicates successful deletion/dropping of index named 'idx'
89
+ """
90
+ args: List[TEncodable] = [CommandNames.FT_DROPINDEX, index_name]
91
+ return cast(TOK, await client.custom_command(args))
92
+
93
+
94
+ async def list(client: TGlideClient) -> List[TEncodable]:
95
+ """
96
+ Lists all indexes.
97
+
98
+ Args:
99
+ client (TGlideClient): The client to execute the command.
100
+
101
+ Returns:
102
+ List[TEncodable]: An array of index names.
103
+
104
+ Examples:
105
+ >>> from glide import ft
106
+ >>> await ft.list(glide_client)
107
+ [b"index1", b"index2"]
108
+ """
109
+ return cast(List[TEncodable], await client.custom_command([CommandNames.FT_LIST]))
110
+
111
+
112
+ async def search(
113
+ client: TGlideClient,
114
+ index_name: TEncodable,
115
+ query: TEncodable,
116
+ options: Optional[FtSearchOptions],
117
+ ) -> FtSearchResponse:
118
+ """
119
+ Uses the provided query expression to locate keys within an index. Once located, the count and/or the content of indexed
120
+ fields within those keys can be returned.
121
+
122
+ Args:
123
+ client (TGlideClient): The client to execute the command.
124
+ index_name (TEncodable): The index name to search into.
125
+ query (TEncodable): The text query to search.
126
+ options (Optional[FtSearchOptions]): The search options.
127
+
128
+ Returns:
129
+ FtSearchResponse: A two element array, where first element is count of documents in result set, and the second
130
+ element, which has the format Mapping[TEncodable, Mapping[TEncodable, TEncodable]] is a mapping between document
131
+ names and map of their attributes.
132
+ If count(option in `FtSearchOptions`) is set to true or limit(option in `FtSearchOptions`) is set to
133
+ FtSearchLimit(0, 0), the command returns array with only one element - the count of the documents.
134
+
135
+ Examples:
136
+ For the following example to work the following must already exist:
137
+ - An index named "idx", with fields having identifiers as "a" and "b" and prefix as "{json:}"
138
+ - A key named {json:}1 with value {"a":1, "b":2}
139
+
140
+ >>> from glide import ft
141
+ >>> await ft.search(
142
+ ... glide_client,
143
+ ... "idx",
144
+ ... "*",
145
+ ... options=FtSeachOptions(
146
+ ... return_fields=[
147
+ ... ReturnField(field_identifier="first"),
148
+ ... ReturnField(field_identifier="second")
149
+ ... ]
150
+ ... )
151
+ ... )
152
+ [1, { b'json:1': { b'first': b'42', b'second': b'33' } }]
153
+ # The first element, 1 is the number of keys returned in the search result. The second element is a map of
154
+ # data queried per key.
155
+ """
156
+ args: List[TEncodable] = [CommandNames.FT_SEARCH, index_name, query]
157
+ if options:
158
+ args.extend(options.to_args())
159
+ return cast(FtSearchResponse, await client.custom_command(args))
160
+
161
+
162
+ async def aliasadd(
163
+ client: TGlideClient, alias: TEncodable, index_name: TEncodable
164
+ ) -> TOK:
165
+ """
166
+ Adds an alias for an index. The new alias name can be used anywhere that an index name is required.
167
+
168
+ Args:
169
+ client (TGlideClient): The client to execute the command.
170
+ alias (TEncodable): The alias to be added to an index.
171
+ index_name (TEncodable): The index name for which the alias has to be added.
172
+
173
+ Returns:
174
+ TOK: A simple "OK" response.
175
+
176
+ Examples:
177
+ >>> from glide import ft
178
+ >>> await ft.aliasadd(glide_client, "myalias", "myindex")
179
+ 'OK' # Indicates the successful addition of the alias named "myalias" for the index.
180
+ """
181
+ args: List[TEncodable] = [CommandNames.FT_ALIASADD, alias, index_name]
182
+ return cast(TOK, await client.custom_command(args))
183
+
184
+
185
+ async def aliasdel(client: TGlideClient, alias: TEncodable) -> TOK:
186
+ """
187
+ Deletes an existing alias for an index.
188
+
189
+ Args:
190
+ client (TGlideClient): The client to execute the command.
191
+ alias (TEncodable): The existing alias to be deleted for an index.
192
+
193
+ Returns:
194
+ TOK: A simple "OK" response.
195
+
196
+ Examples:
197
+ >>> from glide import ft
198
+ >>> await ft.aliasdel(glide_client, "myalias")
199
+ 'OK' # Indicates the successful deletion of the alias named "myalias"
200
+ """
201
+ args: List[TEncodable] = [CommandNames.FT_ALIASDEL, alias]
202
+ return cast(TOK, await client.custom_command(args))
203
+
204
+
205
+ async def aliasupdate(
206
+ client: TGlideClient, alias: TEncodable, index_name: TEncodable
207
+ ) -> TOK:
208
+ """
209
+ Updates an existing alias to point to a different physical index. This command only affects future references to the alias.
210
+
211
+ Args:
212
+ client (TGlideClient): The client to execute the command.
213
+ alias (TEncodable): The alias name. This alias will now be pointed to a different index.
214
+ index_name (TEncodable): The index name for which an existing alias has to updated.
215
+
216
+ Returns:
217
+ TOK: A simple "OK" response.
218
+
219
+ Examples:
220
+ >>> from glide import ft
221
+ >>> await ft.aliasupdate(glide_client, "myalias", "myindex")
222
+ 'OK' # Indicates the successful update of the alias to point to the index named "myindex"
223
+ """
224
+ args: List[TEncodable] = [CommandNames.FT_ALIASUPDATE, alias, index_name]
225
+ return cast(TOK, await client.custom_command(args))
226
+
227
+
228
+ async def info(client: TGlideClient, index_name: TEncodable) -> FtInfoResponse:
229
+ """
230
+ Returns information about a given index.
231
+
232
+ Args:
233
+ client (TGlideClient): The client to execute the command.
234
+ index_name (TEncodable): The index name for which the information has to be returned.
235
+
236
+ Returns:
237
+ FtInfoResponse: Nested maps with info about the index. See example for more details.
238
+
239
+ Examples:
240
+ An index with name 'myIndex', 1 text field and 1 vector field is already created for gettting the output of this
241
+ example.
242
+ >>> from glide import ft
243
+ >>> await ft.info(glide_client, "myIndex")
244
+ [
245
+ b'index_name',
246
+ b'myIndex',
247
+ b'creation_timestamp', 1729531116945240,
248
+ b'key_type', b'JSON',
249
+ b'key_prefixes', [b'key-prefix'],
250
+ b'fields', [
251
+ [
252
+ b'identifier', b'$.vec',
253
+ b'field_name', b'VEC',
254
+ b'type', b'VECTOR',
255
+ b'option', b'',
256
+ b'vector_params', [
257
+ b'algorithm',
258
+ b'HNSW',
259
+ b'data_type',
260
+ b'FLOAT32',
261
+ b'dimension',
262
+ 2,
263
+ b'distance_metric',
264
+ b'L2',
265
+ b'initial_capacity',
266
+ 1000,
267
+ b'current_capacity',
268
+ 1000,
269
+ b'maximum_edges',
270
+ 16,
271
+ b'ef_construction',
272
+ 200,
273
+ b'ef_runtime',
274
+ 10,
275
+ b'epsilon',
276
+ b'0.01'
277
+ ]
278
+ ],
279
+ [
280
+ b'identifier', b'$.text-field',
281
+ b'field_name', b'text-field',
282
+ b'type', b'TEXT',
283
+ b'option', b''
284
+ ]
285
+ ],
286
+ b'space_usage', 653351,
287
+ b'fulltext_space_usage', 0,
288
+ b'vector_space_usage', 653351,
289
+ b'num_docs', 0,
290
+ b'num_indexed_vectors', 0,
291
+ b'current_lag', 0,
292
+ b'index_status', b'AVAILABLE',
293
+ b'index_degradation_percentage', 0
294
+ ]
295
+ """
296
+ args: List[TEncodable] = [CommandNames.FT_INFO, index_name]
297
+ return cast(FtInfoResponse, await client.custom_command(args))
298
+
299
+
300
+ async def explain(
301
+ client: TGlideClient, index_name: TEncodable, query: TEncodable
302
+ ) -> TEncodable:
303
+ """
304
+ Parse a query and return information about how that query was parsed.
305
+
306
+ Args:
307
+ client (TGlideClient): The client to execute the command.
308
+ index_name (TEncodable): The index name for which the query is written.
309
+ query (TEncodable): The search query, same as the query passed as an argument to FT.SEARCH.
310
+
311
+ Returns:
312
+ TEncodable: A string containing the parsed results representing the execution plan.
313
+
314
+ Examples:
315
+ >>> from glide import ft
316
+ >>> await ft.explain(glide_client, indexName="myIndex", query="@price:[0 10]")
317
+ b'Field {\n price\n 0\n 10\n}\n' # Parsed results.
318
+ """
319
+ args: List[TEncodable] = [CommandNames.FT_EXPLAIN, index_name, query]
320
+ return cast(TEncodable, await client.custom_command(args))
321
+
322
+
323
+ async def explaincli(
324
+ client: TGlideClient, index_name: TEncodable, query: TEncodable
325
+ ) -> List[TEncodable]:
326
+ """
327
+ Same as the FT.EXPLAIN command except that the results are displayed in a different format. More useful with cli.
328
+
329
+ Args:
330
+ client (TGlideClient): The client to execute the command.
331
+ index_name (TEncodable): The index name for which the query is written.
332
+ query (TEncodable): The search query, same as the query passed as an argument to FT.SEARCH.
333
+
334
+ Returns:
335
+ List[TEncodable]: An array containing the execution plan.
336
+
337
+ Examples:
338
+ >>> from glide import ft
339
+ >>> await ft.explaincli(glide_client, indexName="myIndex", query="@price:[0 10]")
340
+ [b'Field {', b' price', b' 0', b' 10', b'}', b''] # Parsed results.
341
+ """
342
+ args: List[TEncodable] = [CommandNames.FT_EXPLAINCLI, index_name, query]
343
+ return cast(List[TEncodable], await client.custom_command(args))
344
+
345
+
346
+ async def aggregate(
347
+ client: TGlideClient,
348
+ index_name: TEncodable,
349
+ query: TEncodable,
350
+ options: Optional[FtAggregateOptions],
351
+ ) -> FtAggregateResponse:
352
+ """
353
+ A superset of the FT.SEARCH command, it allows substantial additional processing of the keys selected by the query
354
+ expression.
355
+
356
+ Args:
357
+ client (TGlideClient): The client to execute the command.
358
+ index_name (TEncodable): The index name for which the query is written.
359
+ query (TEncodable): The search query, same as the query passed as an argument to FT.SEARCH.
360
+ options (Optional[FtAggregateOptions]): The optional arguments for the command.
361
+
362
+ Returns:
363
+ FtAggregateResponse: An array containing a mapping of field name and associated value as returned after the last stage
364
+ of the command.
365
+
366
+ Examples:
367
+ >>> from glide import ft
368
+ >>> await ft.aggregate(
369
+ ... glide_client,
370
+ ... "myIndex",
371
+ ... "*",
372
+ ... FtAggregateOptions(
373
+ ... loadFields=["__key"],
374
+ ... clauses=[GroupBy(["@condition"], [Reducer("COUNT", [], "bicycles")])]
375
+ ... )
376
+ ... )
377
+ [
378
+ {
379
+ b'condition': b'refurbished',
380
+ b'bicycles': b'1'
381
+ },
382
+ {
383
+ b'condition': b'new',
384
+ b'bicycles': b'5'
385
+ },
386
+ {
387
+ b'condition': b'used',
388
+ b'bicycles': b'4'
389
+ }
390
+ ]
391
+ """
392
+ args: List[TEncodable] = [CommandNames.FT_AGGREGATE, index_name, query]
393
+ if options:
394
+ args.extend(options.to_args())
395
+ return cast(FtAggregateResponse, await client.custom_command(args))
396
+
397
+
398
+ async def profile(
399
+ client: TGlideClient, index_name: TEncodable, options: FtProfileOptions
400
+ ) -> FtProfileResponse:
401
+ """
402
+ Runs a search or aggregation query and collects performance profiling information.
403
+
404
+ Args:
405
+ client (TGlideClient): The client to execute the command.
406
+ index_name (TEncodable): The index name
407
+ options (FtProfileOptions): Options for the command.
408
+
409
+ Returns:
410
+ FtProfileResponse: A two-element array. The first element contains results of query being profiled, the second element
411
+ stores profiling information.
412
+
413
+ Examples:
414
+ >>> ftSearchOptions = FtSeachOptions(
415
+ ... return_fields=[
416
+ ... ReturnField(field_identifier="a", alias="a_new"),
417
+ ... ReturnField(field_identifier="b", alias="b_new")
418
+ ... ]
419
+ ... )
420
+ >>> await ft.profile(
421
+ ... glide_client,
422
+ ... "myIndex",
423
+ ... FtProfileOptions.from_query_options(query="*", queryOptions=ftSearchOptions)
424
+ ... )
425
+ [
426
+ [
427
+ 2,
428
+ {
429
+ b'key1': {
430
+ b'a': b'11111',
431
+ b'b': b'2'
432
+ },
433
+ b'key2': {
434
+ b'a': b'22222',
435
+ b'b': b'2'
436
+ }
437
+ }
438
+ ],
439
+ {
440
+ b'all.count': 2,
441
+ b'sync.time': 1,
442
+ b'query.time': 7,
443
+ b'result.count': 2,
444
+ b'result.time': 0
445
+ }
446
+ ]
447
+ """
448
+ args: List[TEncodable] = [CommandNames.FT_PROFILE, index_name] + options.to_args()
449
+ return cast(FtProfileResponse, await client.custom_command(args))
450
+
451
+
452
+ async def aliaslist(client: TGlideClient) -> Mapping[TEncodable, TEncodable]:
453
+ """
454
+ List the index aliases.
455
+ Args:
456
+ client (TGlideClient): The client to execute the command.
457
+ Returns:
458
+ Mapping[TEncodable, TEncodable]: A map of index aliases for indices being aliased.
459
+ Examples:
460
+ >>> from glide import ft
461
+ >>> await ft._aliaslist(glide_client)
462
+ {b'alias': b'index1', b'alias-bytes': b'index2'}
463
+ """
464
+ args: List[TEncodable] = [CommandNames.FT_ALIASLIST]
465
+ return cast(Mapping, await client.custom_command(args))