valkey-glide 2.0.0__cp39-cp39-macosx_11_0_arm64.whl → 2.2.5rc1__cp39-cp39-macosx_11_0_arm64.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.
Files changed (44) hide show
  1. glide/__init__.py +152 -118
  2. glide/async_commands/cluster_commands.py +29 -14
  3. glide/async_commands/core.py +600 -414
  4. glide/async_commands/{server_modules/ft.py → ft.py} +8 -7
  5. glide/async_commands/{server_modules/glide_json.py → glide_json.py} +15 -92
  6. glide/async_commands/standalone_commands.py +10 -51
  7. glide/glide.cpython-39-darwin.so +0 -0
  8. glide/glide.pyi +1 -1
  9. glide/glide_client.py +54 -48
  10. glide/logger.py +3 -3
  11. glide/opentelemetry.py +8 -4
  12. glide_shared/__init__.py +330 -0
  13. glide_shared/commands/__init__.py +0 -0
  14. {glide/async_commands → glide_shared/commands}/batch.py +426 -32
  15. {glide/async_commands → glide_shared/commands}/batch_options.py +1 -1
  16. glide_shared/commands/core_options.py +407 -0
  17. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_aggregate_options.py +3 -3
  18. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_create_options.py +4 -2
  19. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_profile_options.py +4 -4
  20. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_search_options.py +4 -2
  21. {glide/async_commands → glide_shared/commands}/server_modules/json_batch.py +4 -4
  22. glide_shared/commands/server_modules/json_options.py +93 -0
  23. {glide/async_commands → glide_shared/commands}/sorted_set.py +2 -2
  24. {glide/async_commands → glide_shared/commands}/stream.py +1 -1
  25. {glide → glide_shared}/config.py +315 -60
  26. {glide → glide_shared}/constants.py +3 -3
  27. {glide → glide_shared}/exceptions.py +27 -1
  28. glide_shared/protobuf/command_request_pb2.py +56 -0
  29. glide_shared/protobuf/connection_request_pb2.py +56 -0
  30. {glide → glide_shared}/routes.py +29 -15
  31. {valkey_glide-2.0.0.dist-info → valkey_glide-2.2.5rc1.dist-info}/METADATA +120 -58
  32. valkey_glide-2.2.5rc1.dist-info/RECORD +40 -0
  33. glide/protobuf/command_request_pb2.py +0 -54
  34. glide/protobuf/command_request_pb2.pyi +0 -1193
  35. glide/protobuf/connection_request_pb2.py +0 -52
  36. glide/protobuf/connection_request_pb2.pyi +0 -299
  37. glide/protobuf/response_pb2.pyi +0 -106
  38. valkey_glide-2.0.0.dist-info/RECORD +0 -39
  39. {glide/async_commands → glide_shared/commands}/bitmap.py +0 -0
  40. {glide/async_commands → glide_shared/commands}/command_args.py +0 -0
  41. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_constants.py +0 -0
  42. {glide → glide_shared}/protobuf/response_pb2.py +0 -0
  43. {glide → glide_shared}/protobuf_codec.py +0 -0
  44. {valkey_glide-2.0.0.dist-info → valkey_glide-2.2.5rc1.dist-info}/WHEEL +0 -0
@@ -5,24 +5,24 @@ module for `vector search` commands.
5
5
 
6
6
  from typing import List, Mapping, Optional, cast
7
7
 
8
- from glide.async_commands.server_modules.ft_options.ft_aggregate_options import (
8
+ from glide_shared.commands.server_modules.ft_options.ft_aggregate_options import (
9
9
  FtAggregateOptions,
10
10
  )
11
- from glide.async_commands.server_modules.ft_options.ft_constants import (
11
+ from glide_shared.commands.server_modules.ft_options.ft_constants import (
12
12
  CommandNames,
13
13
  FtCreateKeywords,
14
14
  )
15
- from glide.async_commands.server_modules.ft_options.ft_create_options import (
15
+ from glide_shared.commands.server_modules.ft_options.ft_create_options import (
16
16
  Field,
17
17
  FtCreateOptions,
18
18
  )
19
- from glide.async_commands.server_modules.ft_options.ft_profile_options import (
19
+ from glide_shared.commands.server_modules.ft_options.ft_profile_options import (
20
20
  FtProfileOptions,
21
21
  )
22
- from glide.async_commands.server_modules.ft_options.ft_search_options import (
22
+ from glide_shared.commands.server_modules.ft_options.ft_search_options import (
23
23
  FtSearchOptions,
24
24
  )
25
- from glide.constants import (
25
+ from glide_shared.constants import (
26
26
  TOK,
27
27
  FtAggregateResponse,
28
28
  FtInfoResponse,
@@ -30,7 +30,8 @@ from glide.constants import (
30
30
  FtSearchResponse,
31
31
  TEncodable,
32
32
  )
33
- from glide.glide_client import TGlideClient
33
+
34
+ from ..glide_client import TGlideClient
34
35
 
35
36
 
36
37
  async def create(
@@ -7,7 +7,7 @@ Examples:
7
7
  >>> import json
8
8
  >>> value = {'a': 1.0, 'b': 2}
9
9
  >>> json_str = json.dumps(value) # Convert Python dictionary to JSON string using json.dumps()
10
- >>> await json.set(client, "doc", "$", json_str)
10
+ >>> await glide_json.set(client, "doc", "$", json_str)
11
11
  'OK' # Indicates successful setting of the value at path '$' in the key stored at `doc`.
12
12
  >>> json_get = await glide_json.get(client, "doc", "$") # Returns the value at path '$' in the JSON document stored at
13
13
  # `doc` as JSON string.
@@ -19,97 +19,20 @@ Examples:
19
19
  """
20
20
  from typing import List, Optional, Union, cast
21
21
 
22
- from glide.async_commands.core import ConditionalChange
23
- from glide.constants import TOK, TEncodable, TJsonResponse, TJsonUniversalResponse
24
- from glide.glide_client import TGlideClient
25
-
26
-
27
- class JsonGetOptions:
28
- """
29
- Represents options for formatting JSON data, to be used in the [JSON.GET](https://valkey.io/commands/json.get/) command.
30
-
31
- Args:
32
- indent (Optional[str]): Sets an indentation string for nested levels. Defaults to None.
33
- newline (Optional[str]): Sets a string that's printed at the end of each line. Defaults to None.
34
- space (Optional[str]): Sets a string that's put between a key and a value. Defaults to None.
35
- """
36
-
37
- def __init__(
38
- self,
39
- indent: Optional[str] = None,
40
- newline: Optional[str] = None,
41
- space: Optional[str] = None,
42
- ):
43
- self.indent = indent
44
- self.new_line = newline
45
- self.space = space
46
-
47
- def get_options(self) -> List[str]:
48
- args = []
49
- if self.indent:
50
- args.extend(["INDENT", self.indent])
51
- if self.new_line:
52
- args.extend(["NEWLINE", self.new_line])
53
- if self.space:
54
- args.extend(["SPACE", self.space])
55
- return args
56
-
57
-
58
- class JsonArrIndexOptions:
59
- """
60
- Options for the `JSON.ARRINDEX` command.
61
-
62
- Args:
63
- start (int): The inclusive start index from which the search begins. Defaults to None.
64
- end (Optional[int]): The exclusive end index where the search stops. Defaults to None.
65
-
66
- Note:
67
- - If `start` is greater than `end`, the command returns `-1` to indicate that the value was not found.
68
- - Indices that exceed the array bounds are automatically adjusted to the nearest valid position.
69
- """
70
-
71
- def __init__(self, start: int, end: Optional[int] = None):
72
- self.start = start
73
- self.end = end
74
-
75
- def to_args(self) -> List[str]:
76
- """
77
- Get the options as a list of arguments for the JSON.ARRINDEX command.
78
-
79
- Returns:
80
- List[str]: A list containing the start and end indices if specified.
81
- """
82
- args = [str(self.start)]
83
- if self.end is not None:
84
- args.append(str(self.end))
85
- return args
86
-
87
-
88
- class JsonArrPopOptions:
89
- """
90
- Options for the JSON.ARRPOP command.
91
-
92
- Args:
93
- path (TEncodable): The path within the JSON document.
94
- index (Optional[int]): The index of the element to pop. If not specified, will pop the last element.
95
- Out of boundary indexes are rounded to their respective array boundaries. Defaults to None.
96
- """
97
-
98
- def __init__(self, path: TEncodable, index: Optional[int] = None):
99
- self.path = path
100
- self.index = index
101
-
102
- def to_args(self) -> List[TEncodable]:
103
- """
104
- Get the options as a list of arguments for the `JSON.ARRPOP` command.
105
-
106
- Returns:
107
- List[TEncodable]: A list containing the path and, if specified, the index.
108
- """
109
- args = [self.path]
110
- if self.index is not None:
111
- args.append(str(self.index))
112
- return args
22
+ from glide_shared.commands.core_options import ConditionalChange
23
+ from glide_shared.commands.server_modules.json_options import (
24
+ JsonArrIndexOptions,
25
+ JsonArrPopOptions,
26
+ JsonGetOptions,
27
+ )
28
+ from glide_shared.constants import (
29
+ TOK,
30
+ TEncodable,
31
+ TJsonResponse,
32
+ TJsonUniversalResponse,
33
+ )
34
+
35
+ from ..glide_client import TGlideClient
113
36
 
114
37
 
115
38
  async def set(
@@ -4,25 +4,25 @@ from __future__ import annotations
4
4
 
5
5
  from typing import Dict, List, Mapping, Optional, Union, cast
6
6
 
7
- from glide.async_commands.batch import Batch
8
- from glide.async_commands.batch_options import BatchOptions
9
- from glide.async_commands.command_args import ObjectType
10
- from glide.async_commands.core import (
11
- CoreCommands,
7
+ from glide.glide import Script
8
+ from glide_shared.commands.batch import Batch
9
+ from glide_shared.commands.batch_options import BatchOptions
10
+ from glide_shared.commands.command_args import ObjectType
11
+ from glide_shared.commands.core_options import (
12
12
  FlushMode,
13
13
  FunctionRestorePolicy,
14
14
  InfoSection,
15
15
  )
16
- from glide.constants import (
16
+ from glide_shared.constants import (
17
17
  TOK,
18
18
  TEncodable,
19
19
  TFunctionListResponse,
20
20
  TFunctionStatsFullResponse,
21
21
  TResult,
22
22
  )
23
- from glide.protobuf.command_request_pb2 import RequestType
23
+ from glide_shared.protobuf.command_request_pb2 import RequestType
24
24
 
25
- from ..glide import Script
25
+ from .core import CoreCommands
26
26
 
27
27
 
28
28
  class StandaloneCommands(CoreCommands):
@@ -162,20 +162,6 @@ class StandaloneCommands(CoreCommands):
162
162
  timeout=timeout,
163
163
  )
164
164
 
165
- async def select(self, index: int) -> TOK:
166
- """
167
- Change the currently selected database.
168
-
169
- See [valkey.io](https://valkey.io/commands/select/) for details.
170
-
171
- Args:
172
- index (int): The index of the database to select.
173
-
174
- Returns:
175
- A simple OK response.
176
- """
177
- return cast(TOK, await self._execute_command(RequestType.Select, [str(index)]))
178
-
179
165
  async def config_resetstat(self) -> TOK:
180
166
  """
181
167
  Resets the statistics reported by the server using the INFO and LATENCY HISTOGRAM commands.
@@ -629,31 +615,6 @@ class StandaloneCommands(CoreCommands):
629
615
  await self._execute_command(RequestType.LastSave, []),
630
616
  )
631
617
 
632
- async def move(self, key: TEncodable, db_index: int) -> bool:
633
- """
634
- Move `key` from the currently selected database to the database specified by `db_index`.
635
-
636
- See [valkey.io](https://valkey.io/commands/move/) for more details.
637
-
638
- Args:
639
- key (TEncodable): The key to move.
640
- db_index (int): The index of the database to move `key` to.
641
-
642
- Returns:
643
- bool: `True` if `key` was moved.
644
-
645
- `False` if the `key` already exists in the destination database
646
- or does not exist in the source database.
647
-
648
- Example:
649
- >>> await client.move("some_key", 1)
650
- True
651
- """
652
- return cast(
653
- bool,
654
- await self._execute_command(RequestType.Move, [key, str(db_index)]),
655
- )
656
-
657
618
  async def publish(self, message: TEncodable, channel: TEncodable) -> int:
658
619
  """
659
620
  Publish a message on pubsub channel.
@@ -806,7 +767,7 @@ class StandaloneCommands(CoreCommands):
806
767
  args.extend(["VERSION", str(version)])
807
768
  if parameters:
808
769
  for var in parameters:
809
- args.extend(str(var))
770
+ args.append(str(var))
810
771
  return cast(
811
772
  bytes,
812
773
  await self._execute_command(RequestType.Lolwut, args),
@@ -871,8 +832,6 @@ class StandaloneCommands(CoreCommands):
871
832
  TOK: A simple "OK" response.
872
833
 
873
834
  Examples:
874
- >>> await client.watch("sampleKey")
875
- 'OK'
876
835
  >>> await client.unwatch()
877
836
  'OK'
878
837
  """
@@ -1036,7 +995,7 @@ class StandaloneCommands(CoreCommands):
1036
995
 
1037
996
  Examples:
1038
997
  >>> lua_script = Script("return { KEYS[1], ARGV[1] }")
1039
- >>> await client.invoke_script(lua_script, keys=["foo"], args=["bar"] );
998
+ >>> await client.invoke_script(lua_script, keys=["foo"], args=["bar"])
1040
999
  [b"foo", b"bar"]
1041
1000
  """
1042
1001
  return await self._execute_script(script.get_hash(), keys, args)
Binary file
glide/glide.pyi CHANGED
@@ -2,7 +2,7 @@ from collections.abc import Callable
2
2
  from enum import Enum
3
3
  from typing import List, Optional, Union
4
4
 
5
- from glide.constants import TResult
5
+ from glide_shared.constants import TResult
6
6
 
7
7
  DEFAULT_TIMEOUT_IN_MILLISECONDS: int = ...
8
8
  MAX_REQUEST_ARGS_LEN: int = ...
glide/glide_client.py CHANGED
@@ -11,7 +11,6 @@ from typing import (
11
11
  Optional,
12
12
  Set,
13
13
  Tuple,
14
- Type,
15
14
  Union,
16
15
  cast,
17
16
  )
@@ -19,31 +18,7 @@ from typing import (
19
18
  import anyio
20
19
  import sniffio
21
20
  from anyio import to_thread
22
-
23
- from glide.async_commands.cluster_commands import ClusterCommands
24
- from glide.async_commands.command_args import ObjectType
25
- from glide.async_commands.core import CoreCommands
26
- from glide.async_commands.standalone_commands import StandaloneCommands
27
- from glide.config import BaseClientConfiguration, ServerCredentials
28
- from glide.constants import DEFAULT_READ_BYTES_SIZE, OK, TEncodable, TRequest, TResult
29
- from glide.exceptions import (
30
- ClosingError,
31
- ConfigurationError,
32
- ConnectionError,
33
- ExecAbortError,
34
- RequestError,
35
- TimeoutError,
36
- )
37
- from glide.logger import Level as LogLevel
38
- from glide.logger import Logger as ClientLogger
39
- from glide.opentelemetry import OpenTelemetry
40
- from glide.protobuf.command_request_pb2 import Command, CommandRequest, RequestType
41
- from glide.protobuf.connection_request_pb2 import ConnectionRequest
42
- from glide.protobuf.response_pb2 import RequestErrorType, Response
43
- from glide.protobuf_codec import PartialMessageException, ProtobufCodec
44
- from glide.routes import Route, set_protobuf_route
45
-
46
- from .glide import (
21
+ from glide.glide import (
47
22
  DEFAULT_TIMEOUT_IN_MILLISECONDS,
48
23
  MAX_REQUEST_ARGS_LEN,
49
24
  ClusterScanCursor,
@@ -54,6 +29,39 @@ from .glide import (
54
29
  start_socket_listener_external,
55
30
  value_from_pointer,
56
31
  )
32
+ from glide_shared.commands.command_args import ObjectType
33
+ from glide_shared.commands.core_options import PubSubMsg
34
+ from glide_shared.config import BaseClientConfiguration, ServerCredentials
35
+ from glide_shared.constants import (
36
+ DEFAULT_READ_BYTES_SIZE,
37
+ OK,
38
+ TEncodable,
39
+ TRequest,
40
+ TResult,
41
+ )
42
+ from glide_shared.exceptions import (
43
+ ClosingError,
44
+ ConfigurationError,
45
+ ConnectionError,
46
+ get_request_error_class,
47
+ )
48
+ from glide_shared.protobuf.command_request_pb2 import (
49
+ Command,
50
+ CommandRequest,
51
+ RefreshIamToken,
52
+ RequestType,
53
+ )
54
+ from glide_shared.protobuf.connection_request_pb2 import ConnectionRequest
55
+ from glide_shared.protobuf.response_pb2 import Response
56
+ from glide_shared.protobuf_codec import PartialMessageException, ProtobufCodec
57
+ from glide_shared.routes import Route, set_protobuf_route
58
+
59
+ from .async_commands.cluster_commands import ClusterCommands
60
+ from .async_commands.core import CoreCommands
61
+ from .async_commands.standalone_commands import StandaloneCommands
62
+ from .logger import Level as LogLevel
63
+ from .logger import Logger as ClientLogger
64
+ from .opentelemetry import OpenTelemetry
57
65
 
58
66
  if sys.version_info >= (3, 11):
59
67
  from typing import Self
@@ -69,20 +77,6 @@ if TYPE_CHECKING:
69
77
  TFuture = Union[asyncio.Future[Any], "_CompatFuture"]
70
78
 
71
79
 
72
- def get_request_error_class(
73
- error_type: Optional[RequestErrorType.ValueType],
74
- ) -> Type[RequestError]:
75
- if error_type == RequestErrorType.Disconnect:
76
- return ConnectionError
77
- if error_type == RequestErrorType.ExecAbort:
78
- return ExecAbortError
79
- if error_type == RequestErrorType.Timeout:
80
- return TimeoutError
81
- if error_type == RequestErrorType.Unspecified:
82
- return RequestError
83
- return RequestError
84
-
85
-
86
80
  class _CompatFuture:
87
81
  """anyio shim for asyncio.Future-like functionality"""
88
82
 
@@ -345,7 +339,7 @@ class BaseClient(CoreCommands):
345
339
  request.callback_idx if isinstance(request, CommandRequest) else 0
346
340
  )
347
341
  res_future = self._available_futures.pop(callback_idx, None)
348
- if res_future:
342
+ if res_future and not res_future.done():
349
343
  res_future.set_exception(e)
350
344
  else:
351
345
  ClientLogger.log(
@@ -362,7 +356,10 @@ class BaseClient(CoreCommands):
362
356
  b_arr = bytearray()
363
357
  for request in requests:
364
358
  ProtobufCodec.encode_delimited(b_arr, request)
365
- await self._stream.send(b_arr)
359
+ try:
360
+ await self._stream.send(b_arr)
361
+ except (anyio.ClosedResourceError, anyio.EndOfStream):
362
+ raise ClosingError("The communication layer was unexpectedly closed.")
366
363
 
367
364
  def _encode_arg(self, arg: TEncodable) -> bytes:
368
365
  """
@@ -524,7 +521,7 @@ class BaseClient(CoreCommands):
524
521
  set_protobuf_route(request, route)
525
522
  return await self._write_request_await_response(request)
526
523
 
527
- async def get_pubsub_message(self) -> CoreCommands.PubSubMsg:
524
+ async def get_pubsub_message(self) -> PubSubMsg:
528
525
  if self._is_closed:
529
526
  raise ClosingError(
530
527
  "Unable to execute requests; the client is closed. Please create a new client."
@@ -551,7 +548,7 @@ class BaseClient(CoreCommands):
551
548
  await response_future
552
549
  return response_future.result()
553
550
 
554
- def try_get_pubsub_message(self) -> Optional[CoreCommands.PubSubMsg]:
551
+ def try_get_pubsub_message(self) -> Optional[PubSubMsg]:
555
552
  if self._is_closed:
556
553
  raise ClosingError(
557
554
  "Unable to execute requests; the client is closed. Please create a new client."
@@ -568,7 +565,7 @@ class BaseClient(CoreCommands):
568
565
  )
569
566
 
570
567
  # locking might not be required
571
- msg: Optional[CoreCommands.PubSubMsg] = None
568
+ msg: Optional[PubSubMsg] = None
572
569
  try:
573
570
  self._pubsub_lock.acquire()
574
571
  self._complete_pubsub_futures_safe()
@@ -586,7 +583,7 @@ class BaseClient(CoreCommands):
586
583
 
587
584
  def _notification_to_pubsub_message_safe(
588
585
  self, response: Response
589
- ) -> Optional[CoreCommands.PubSubMsg]:
586
+ ) -> Optional[PubSubMsg]:
590
587
  pubsub_message = None
591
588
  push_notification = cast(
592
589
  Dict[str, Any], value_from_pointer(response.resp_pointer)
@@ -605,11 +602,11 @@ class BaseClient(CoreCommands):
605
602
  ):
606
603
  values: List = push_notification["values"]
607
604
  if message_kind == "PMessage":
608
- pubsub_message = BaseClient.PubSubMsg(
605
+ pubsub_message = PubSubMsg(
609
606
  message=values[2], channel=values[1], pattern=values[0]
610
607
  )
611
608
  else:
612
- pubsub_message = BaseClient.PubSubMsg(
609
+ pubsub_message = PubSubMsg(
613
610
  message=values[1], channel=values[0], pattern=None
614
611
  )
615
612
  elif (
@@ -761,6 +758,15 @@ class BaseClient(CoreCommands):
761
758
  self.config.credentials.password = password or ""
762
759
  return response
763
760
 
761
+ async def _refresh_iam_token(self) -> TResult:
762
+ request = CommandRequest()
763
+ request.callback_idx = self._get_callback_index()
764
+ request.refresh_iam_token.CopyFrom(
765
+ RefreshIamToken()
766
+ ) # Empty message, just triggers the refresh
767
+ response = await self._write_request_await_response(request)
768
+ return response
769
+
764
770
 
765
771
  class GlideClusterClient(BaseClient, ClusterCommands):
766
772
  """
glide/logger.py CHANGED
@@ -6,8 +6,8 @@ import traceback
6
6
  from enum import Enum
7
7
  from typing import Optional
8
8
 
9
- from .glide import Level as internalLevel
10
- from .glide import py_init, py_log
9
+ from glide.glide import Level as internalLevel
10
+ from glide.glide import py_init, py_log
11
11
 
12
12
 
13
13
  class Level(Enum):
@@ -40,7 +40,7 @@ class Logger:
40
40
  def init(cls, level: Optional[Level] = None, file_name: Optional[str] = None):
41
41
  """
42
42
  Initialize a logger if it wasn't initialized before - this method is meant to be used when there is no intention to
43
- replace an existing logger.
43
+ replace an existing logger. Otherwise, use `set_logger_config` for overriding the existing logger configs.
44
44
  The logger will filter all logs with a level lower than the given level.
45
45
  If given a file_name argument, will write the logs to files postfixed with file_name. If file_name isn't provided,
46
46
  the logs will be written to the console.
glide/opentelemetry.py CHANGED
@@ -37,10 +37,14 @@ If you need to change configuration, restart the process with new settings.
37
37
  import random
38
38
  from typing import Optional
39
39
 
40
- from glide.exceptions import ConfigurationError
41
- from glide.logger import Level, Logger
42
-
43
- from .glide import OpenTelemetryConfig, OpenTelemetryTracesConfig, init_opentelemetry
40
+ from glide.glide import (
41
+ OpenTelemetryConfig,
42
+ OpenTelemetryTracesConfig,
43
+ init_opentelemetry,
44
+ )
45
+ from glide_shared.exceptions import ConfigurationError
46
+
47
+ from .logger import Level, Logger
44
48
 
45
49
 
46
50
  class OpenTelemetry: