valkey-glide 2.0.0rc7__cp39-cp39-macosx_11_0_arm64.whl → 2.1.0rc1__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.

Potentially problematic release.


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

Files changed (45) hide show
  1. glide/__init__.py +103 -107
  2. glide/async_commands/cluster_commands.py +83 -101
  3. glide/async_commands/core.py +554 -424
  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 +18 -17
  7. glide/glide.cpython-39-darwin.so +0 -0
  8. glide/glide.pyi +26 -1
  9. glide/glide_client.py +70 -45
  10. glide/logger.py +33 -21
  11. glide/opentelemetry.py +185 -0
  12. glide_shared/__init__.py +326 -0
  13. {glide/async_commands → glide_shared/commands}/batch.py +411 -18
  14. glide_shared/commands/batch_options.py +261 -0
  15. glide_shared/commands/core_options.py +407 -0
  16. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_aggregate_options.py +3 -3
  17. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_create_options.py +4 -2
  18. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_profile_options.py +4 -4
  19. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_search_options.py +4 -2
  20. {glide/async_commands → glide_shared/commands}/server_modules/json_batch.py +4 -4
  21. glide_shared/commands/server_modules/json_options.py +93 -0
  22. {glide/async_commands → glide_shared/commands}/sorted_set.py +2 -2
  23. {glide/async_commands → glide_shared/commands}/stream.py +1 -1
  24. {glide → glide_shared}/config.py +120 -32
  25. {glide → glide_shared}/constants.py +3 -3
  26. {glide → glide_shared}/exceptions.py +27 -1
  27. glide_shared/protobuf/command_request_pb2.py +54 -0
  28. glide_shared/protobuf/connection_request_pb2.py +52 -0
  29. {glide → glide_shared}/protobuf/response_pb2.py +6 -6
  30. {glide → glide_shared}/routes.py +29 -15
  31. valkey_glide-2.1.0rc1.dist-info/METADATA +210 -0
  32. valkey_glide-2.1.0rc1.dist-info/RECORD +39 -0
  33. glide/protobuf/command_request_pb2.py +0 -54
  34. glide/protobuf/command_request_pb2.pyi +0 -1187
  35. glide/protobuf/connection_request_pb2.py +0 -54
  36. glide/protobuf/connection_request_pb2.pyi +0 -320
  37. glide/protobuf/response_pb2.pyi +0 -100
  38. valkey_glide-2.0.0rc7.dist-info/METADATA +0 -144
  39. valkey_glide-2.0.0rc7.dist-info/RECORD +0 -37
  40. /glide/py.typed → /glide_shared/commands/__init__.py +0 -0
  41. {glide/async_commands → glide_shared/commands}/bitmap.py +0 -0
  42. {glide/async_commands → glide_shared/commands}/command_args.py +0 -0
  43. {glide/async_commands → glide_shared/commands}/server_modules/ft_options/ft_constants.py +0 -0
  44. {glide → glide_shared}/protobuf_codec.py +0 -0
  45. {valkey_glide-2.0.0rc7.dist-info → valkey_glide-2.1.0rc1.dist-info}/WHEEL +0 -0
glide/opentelemetry.py ADDED
@@ -0,0 +1,185 @@
1
+ # Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2
+
3
+ """
4
+ ⚠️ OpenTelemetry can only be initialized once per process. Calling `OpenTelemetry.init()` more than once will be ignored.
5
+ If you need to change configuration, restart the process with new settings.
6
+
7
+ ### OpenTelemetry
8
+
9
+ - **openTelemetryConfig**: Use this object to configure OpenTelemetry exporters and options.
10
+ - **traces**: (optional) Configure trace exporting.
11
+ - **endpoint**: The collector endpoint for traces. Supported protocols:
12
+ - `http://` or `https://` for HTTP/HTTPS
13
+ - `grpc://` for gRPC
14
+ - `file://` for local file export (see below)
15
+ - **sample_percentage**: (optional) The percentage of requests to sample and create a span for, used to measure command duration. Must be between 0 and 100. Defaults to 1 if not specified.
16
+ Note: There is a tradeoff between sampling percentage and performance. Higher sampling percentages will provide more detailed telemetry data but will impact performance.
17
+ It is recommended to keep this number low (1-5%) in production environments unless you have specific needs for higher sampling rates.
18
+ - **metrics**: (optional) Configure metrics exporting.
19
+ - **endpoint**: The collector endpoint for metrics. Same protocol rules as above.
20
+ - **flush_interval_ms**: (optional) Interval in milliseconds for flushing data to the collector. Must be a positive integer. Defaults to 5000ms if not specified.
21
+
22
+ #### File Exporter Details
23
+ - For `file://` endpoints:
24
+ - The path must start with `file://` (e.g., `file:///tmp/otel` or `file:///tmp/otel/traces.json`).
25
+ - If the path is a directory or lacks a file extension, data is written to `signals.json` in that directory.
26
+ - If the path includes a filename with an extension, that file is used as-is.
27
+ - The parent directory must already exist; otherwise, initialization will fail with an InvalidInput error.
28
+ - If the target file exists, new data is appended (not overwritten).
29
+
30
+ #### Validation Rules
31
+ - `flush_interval_ms` must be a positive integer.
32
+ - `sample_percentage` must be between 0 and 100.
33
+ - File exporter paths must start with `file://` and have an existing parent directory.
34
+ - Invalid configuration will throw an error synchronously when calling `OpenTelemetry.init()`.
35
+ """
36
+
37
+ import random
38
+ from typing import Optional
39
+
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
48
+
49
+
50
+ class OpenTelemetry:
51
+ """
52
+ Singleton class for managing OpenTelemetry configuration and operations.
53
+
54
+ This class provides a centralized way to initialize OpenTelemetry and control
55
+ sampling behavior at runtime.
56
+
57
+ Example usage:
58
+ ```python
59
+ from glide import OpenTelemetry, OpenTelemetryConfig, OpenTelemetryTracesConfig, OpenTelemetryMetricsConfig
60
+
61
+ OpenTelemetry.init(OpenTelemetryConfig(
62
+ traces=OpenTelemetryTracesConfig(
63
+ endpoint="http://localhost:4318/v1/traces",
64
+ sample_percentage=10 # Optional, defaults to 1. Can also be changed at runtime via set_sample_percentage().
65
+ ),
66
+ metrics=OpenTelemetryMetricsConfig(
67
+ endpoint="http://localhost:4318/v1/metrics"
68
+ ),
69
+ flush_interval_ms=1000 # Optional, defaults to 5000
70
+ ))
71
+ ```
72
+
73
+ Note:
74
+ OpenTelemetry can only be initialized once per process. Subsequent calls to
75
+ init() will be ignored. This is by design, as OpenTelemetry is a global
76
+ resource that should be configured once at application startup.
77
+ """
78
+
79
+ _instance: Optional["OpenTelemetry"] = None
80
+ _config: Optional[OpenTelemetryConfig] = None
81
+
82
+ @classmethod
83
+ def init(cls, config: OpenTelemetryConfig) -> None:
84
+ """
85
+ Initialize the OpenTelemetry instance.
86
+
87
+ Args:
88
+ config: The OpenTelemetry configuration
89
+
90
+ Note:
91
+ OpenTelemetry can only be initialized once per process.
92
+ Subsequent calls will be ignored and a warning will be logged.
93
+ """
94
+ if not cls._instance:
95
+ cls._config = config
96
+ # Initialize the underlying OpenTelemetry implementation
97
+ init_opentelemetry(config)
98
+ cls._instance = OpenTelemetry()
99
+ Logger.log(
100
+ Level.INFO,
101
+ "GlideOpenTelemetry",
102
+ "OpenTelemetry initialized successfully",
103
+ )
104
+ return
105
+
106
+ Logger.log(
107
+ Level.WARN,
108
+ "GlideOpenTelemetry",
109
+ "OpenTelemetry already initialized - ignoring new configuration",
110
+ )
111
+
112
+ @classmethod
113
+ def is_initialized(cls) -> bool:
114
+ """
115
+ Check if the OpenTelemetry instance is initialized.
116
+
117
+ Returns:
118
+ bool: True if the OpenTelemetry instance is initialized, False otherwise
119
+ """
120
+ return cls._instance is not None
121
+
122
+ @classmethod
123
+ def get_sample_percentage(cls) -> Optional[int]:
124
+ """
125
+ Get the sample percentage for traces.
126
+
127
+ Returns:
128
+ Optional[int]: The sample percentage for traces only if OpenTelemetry is initialized
129
+ and the traces config is set, otherwise None.
130
+ """
131
+ if cls._config:
132
+ traces_config = cls._config.get_traces()
133
+ if traces_config:
134
+ return traces_config.get_sample_percentage()
135
+ return None
136
+
137
+ @classmethod
138
+ def should_sample(cls) -> bool:
139
+ """
140
+ Determines if the current request should be sampled for OpenTelemetry tracing.
141
+ Uses the configured sample percentage to randomly decide whether to create a span for this request.
142
+
143
+ Returns:
144
+ bool: True if the request should be sampled, False otherwise
145
+ """
146
+ percentage = cls.get_sample_percentage()
147
+ return (
148
+ cls.is_initialized()
149
+ and percentage is not None
150
+ and random.random() * 100 < percentage
151
+ )
152
+
153
+ @classmethod
154
+ def set_sample_percentage(cls, percentage: int) -> None:
155
+ """
156
+ Set the percentage of requests to be sampled and traced. Must be a value between 0 and 100.
157
+ This setting only affects traces, not metrics.
158
+
159
+ Args:
160
+ percentage: The sample percentage 0-100
161
+
162
+ Raises:
163
+ ConfigurationError: If OpenTelemetry is not initialized or traces config is not set
164
+
165
+ Remarks:
166
+ This method can be called at runtime to change the sampling percentage
167
+ without reinitializing OpenTelemetry.
168
+ """
169
+ if not cls._config or not cls._config.get_traces():
170
+ raise ConfigurationError("OpenTelemetry config traces not initialized")
171
+
172
+ if percentage < 0 or percentage > 100:
173
+ raise ConfigurationError("Sample percentage must be between 0 and 100")
174
+
175
+ # Create a new traces config with the updated sample_percentage
176
+ # This is necessary because the PyO3 binding doesn't properly handle direct assignment to Option<u32>
177
+ traces_config = cls._config.get_traces()
178
+ if traces_config:
179
+ endpoint = traces_config.get_endpoint()
180
+ new_traces_config = OpenTelemetryTracesConfig(
181
+ endpoint=endpoint, sample_percentage=percentage
182
+ )
183
+
184
+ # Replace the traces config
185
+ cls._config.set_traces(new_traces_config)
@@ -0,0 +1,326 @@
1
+ # Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
2
+
3
+ from .commands.batch import Batch, ClusterBatch, ClusterTransaction, TBatch, Transaction
4
+ from .commands.batch_options import (
5
+ BatchOptions,
6
+ BatchRetryStrategy,
7
+ ClusterBatchOptions,
8
+ )
9
+ from .commands.bitmap import (
10
+ BitEncoding,
11
+ BitFieldGet,
12
+ BitFieldIncrBy,
13
+ BitFieldOffset,
14
+ BitFieldOverflow,
15
+ BitFieldSet,
16
+ BitFieldSubCommands,
17
+ BitmapIndexType,
18
+ BitOffset,
19
+ BitOffsetMultiplier,
20
+ BitOverflowControl,
21
+ BitwiseOperation,
22
+ OffsetOptions,
23
+ SignedEncoding,
24
+ UnsignedEncoding,
25
+ )
26
+ from .commands.command_args import Limit, ListDirection, ObjectType, OrderBy
27
+ from .commands.core_options import (
28
+ ConditionalChange,
29
+ ExpireOptions,
30
+ ExpiryGetEx,
31
+ ExpirySet,
32
+ ExpiryType,
33
+ ExpiryTypeGetEx,
34
+ FlushMode,
35
+ FunctionRestorePolicy,
36
+ HashFieldConditionalChange,
37
+ InfoSection,
38
+ InsertPosition,
39
+ OnlyIfEqual,
40
+ PubSubMsg,
41
+ UpdateOptions,
42
+ )
43
+ from .commands.server_modules import json_batch
44
+ from .commands.server_modules.ft_options.ft_aggregate_options import (
45
+ FtAggregateApply,
46
+ FtAggregateClause,
47
+ FtAggregateFilter,
48
+ FtAggregateGroupBy,
49
+ FtAggregateLimit,
50
+ FtAggregateOptions,
51
+ FtAggregateReducer,
52
+ FtAggregateSortBy,
53
+ FtAggregateSortProperty,
54
+ )
55
+ from .commands.server_modules.ft_options.ft_create_options import (
56
+ DataType,
57
+ DistanceMetricType,
58
+ Field,
59
+ FieldType,
60
+ FtCreateOptions,
61
+ NumericField,
62
+ TagField,
63
+ TextField,
64
+ VectorAlgorithm,
65
+ VectorField,
66
+ VectorFieldAttributes,
67
+ VectorFieldAttributesFlat,
68
+ VectorFieldAttributesHnsw,
69
+ VectorType,
70
+ )
71
+ from .commands.server_modules.ft_options.ft_profile_options import (
72
+ FtProfileOptions,
73
+ QueryType,
74
+ )
75
+ from .commands.server_modules.ft_options.ft_search_options import (
76
+ FtSearchLimit,
77
+ FtSearchOptions,
78
+ ReturnField,
79
+ )
80
+ from .commands.server_modules.json_options import (
81
+ JsonArrIndexOptions,
82
+ JsonArrPopOptions,
83
+ JsonGetOptions,
84
+ )
85
+ from .commands.sorted_set import (
86
+ AggregationType,
87
+ GeoSearchByBox,
88
+ GeoSearchByRadius,
89
+ GeoSearchCount,
90
+ GeospatialData,
91
+ GeoUnit,
92
+ InfBound,
93
+ LexBoundary,
94
+ RangeByIndex,
95
+ RangeByLex,
96
+ RangeByScore,
97
+ ScoreBoundary,
98
+ ScoreFilter,
99
+ )
100
+ from .commands.stream import (
101
+ ExclusiveIdBound,
102
+ IdBound,
103
+ MaxId,
104
+ MinId,
105
+ StreamAddOptions,
106
+ StreamClaimOptions,
107
+ StreamGroupOptions,
108
+ StreamPendingOptions,
109
+ StreamRangeBound,
110
+ StreamReadGroupOptions,
111
+ StreamReadOptions,
112
+ StreamTrimOptions,
113
+ TrimByMaxLen,
114
+ TrimByMinId,
115
+ )
116
+ from .config import (
117
+ AdvancedGlideClientConfiguration,
118
+ AdvancedGlideClusterClientConfiguration,
119
+ BackoffStrategy,
120
+ GlideClientConfiguration,
121
+ GlideClusterClientConfiguration,
122
+ NodeAddress,
123
+ PeriodicChecksManualInterval,
124
+ PeriodicChecksStatus,
125
+ ProtocolVersion,
126
+ ReadFrom,
127
+ ServerCredentials,
128
+ TlsAdvancedConfiguration,
129
+ )
130
+ from .constants import (
131
+ OK,
132
+ TOK,
133
+ FtAggregateResponse,
134
+ FtInfoResponse,
135
+ FtProfileResponse,
136
+ FtSearchResponse,
137
+ TClusterResponse,
138
+ TEncodable,
139
+ TFunctionListResponse,
140
+ TFunctionStatsFullResponse,
141
+ TFunctionStatsSingleNodeResponse,
142
+ TJsonResponse,
143
+ TJsonUniversalResponse,
144
+ TResult,
145
+ TSingleNodeRoute,
146
+ TXInfoStreamFullResponse,
147
+ TXInfoStreamResponse,
148
+ )
149
+ from .exceptions import (
150
+ ClosingError,
151
+ ConfigurationError,
152
+ ConnectionError,
153
+ ExecAbortError,
154
+ GlideError,
155
+ LoggerError,
156
+ RequestError,
157
+ TimeoutError,
158
+ )
159
+ from .routes import (
160
+ AllNodes,
161
+ AllPrimaries,
162
+ ByAddressRoute,
163
+ RandomNode,
164
+ Route,
165
+ SlotIdRoute,
166
+ SlotKeyRoute,
167
+ SlotType,
168
+ )
169
+
170
+ __all__ = [
171
+ # Client
172
+ "Batch",
173
+ "ClusterBatch",
174
+ "ClusterTransaction",
175
+ "Transaction",
176
+ "TBatch",
177
+ # Batch Options
178
+ "BatchOptions",
179
+ "BatchRetryStrategy",
180
+ "ClusterBatchOptions",
181
+ # Config
182
+ "AdvancedGlideClientConfiguration",
183
+ "AdvancedGlideClusterClientConfiguration",
184
+ "GlideClientConfiguration",
185
+ "GlideClusterClientConfiguration",
186
+ "BackoffStrategy",
187
+ "ReadFrom",
188
+ "ServerCredentials",
189
+ "NodeAddress",
190
+ "ProtocolVersion",
191
+ "PeriodicChecksManualInterval",
192
+ "PeriodicChecksStatus",
193
+ "TlsAdvancedConfiguration",
194
+ # Response
195
+ "OK",
196
+ "TClusterResponse",
197
+ "TEncodable",
198
+ "TFunctionListResponse",
199
+ "TFunctionStatsFullResponse",
200
+ "TFunctionStatsSingleNodeResponse",
201
+ "TJsonResponse",
202
+ "TJsonUniversalResponse",
203
+ "TOK",
204
+ "TResult",
205
+ "TXInfoStreamFullResponse",
206
+ "TXInfoStreamResponse",
207
+ "FtAggregateResponse",
208
+ "FtInfoResponse",
209
+ "FtProfileResponse",
210
+ "FtSearchResponse",
211
+ # Commands
212
+ "BitEncoding",
213
+ "BitFieldGet",
214
+ "BitFieldIncrBy",
215
+ "BitFieldOffset",
216
+ "BitFieldOverflow",
217
+ "BitFieldSet",
218
+ "BitFieldSubCommands",
219
+ "BitmapIndexType",
220
+ "BitOffset",
221
+ "BitOffsetMultiplier",
222
+ "BitOverflowControl",
223
+ "BitwiseOperation",
224
+ "OffsetOptions",
225
+ "SignedEncoding",
226
+ "UnsignedEncoding",
227
+ "ScoreBoundary",
228
+ "ConditionalChange",
229
+ "HashFieldConditionalChange",
230
+ "OnlyIfEqual",
231
+ "ExpireOptions",
232
+ "ExpiryGetEx",
233
+ "ExpirySet",
234
+ "ExpiryType",
235
+ "ExpiryTypeGetEx",
236
+ "FlushMode",
237
+ "FunctionRestorePolicy",
238
+ "GeoSearchByBox",
239
+ "GeoSearchByRadius",
240
+ "GeoSearchCount",
241
+ "GeoUnit",
242
+ "GeospatialData",
243
+ "AggregationType",
244
+ "InfBound",
245
+ "InfoSection",
246
+ "InsertPosition",
247
+ "LexBoundary",
248
+ "Limit",
249
+ "ListDirection",
250
+ "RangeByIndex",
251
+ "RangeByLex",
252
+ "RangeByScore",
253
+ "ScoreFilter",
254
+ "ObjectType",
255
+ "OrderBy",
256
+ "ExclusiveIdBound",
257
+ "IdBound",
258
+ "MaxId",
259
+ "MinId",
260
+ "StreamAddOptions",
261
+ "StreamClaimOptions",
262
+ "StreamGroupOptions",
263
+ "StreamPendingOptions",
264
+ "StreamReadGroupOptions",
265
+ "StreamRangeBound",
266
+ "StreamReadOptions",
267
+ "StreamTrimOptions",
268
+ "TrimByMaxLen",
269
+ "TrimByMinId",
270
+ "UpdateOptions",
271
+ # PubSub
272
+ "PubSubMsg",
273
+ # Json
274
+ "json_batch",
275
+ "JsonGetOptions",
276
+ "JsonArrIndexOptions",
277
+ "JsonArrPopOptions",
278
+ # Routes
279
+ "Route",
280
+ "SlotType",
281
+ "AllNodes",
282
+ "AllPrimaries",
283
+ "ByAddressRoute",
284
+ "RandomNode",
285
+ "SlotKeyRoute",
286
+ "SlotIdRoute",
287
+ "TSingleNodeRoute",
288
+ # Exceptions
289
+ "ClosingError",
290
+ "ConfigurationError",
291
+ "ConnectionError",
292
+ "ExecAbortError",
293
+ "GlideError",
294
+ "RequestError",
295
+ "TimeoutError",
296
+ "LoggerError",
297
+ # Ft
298
+ "DataType",
299
+ "DistanceMetricType",
300
+ "Field",
301
+ "FieldType",
302
+ "FtCreateOptions",
303
+ "NumericField",
304
+ "TagField",
305
+ "TextField",
306
+ "VectorAlgorithm",
307
+ "VectorField",
308
+ "VectorFieldAttributes",
309
+ "VectorFieldAttributesFlat",
310
+ "VectorFieldAttributesHnsw",
311
+ "VectorType",
312
+ "FtSearchLimit",
313
+ "ReturnField",
314
+ "FtSearchOptions",
315
+ "FtAggregateApply",
316
+ "FtAggregateFilter",
317
+ "FtAggregateClause",
318
+ "FtAggregateLimit",
319
+ "FtAggregateOptions",
320
+ "FtAggregateGroupBy",
321
+ "FtAggregateReducer",
322
+ "FtAggregateSortBy",
323
+ "FtAggregateSortProperty",
324
+ "FtProfileOptions",
325
+ "QueryType",
326
+ ]