encore-dev 2.0.0a7__py3-none-any.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. encore/__init__.py +43 -0
  2. encore/cron/__init__.py +50 -0
  3. encore/internal/__init__.py +1 -0
  4. encore/internal/_loader.py +79 -0
  5. encore/internal/_native.pyi +734 -0
  6. encore/internal/lazy.py +35 -0
  7. encore/internal/runtime.py +133 -0
  8. encore/internal/startup.py +24 -0
  9. encore/logs/__init__.py +19 -0
  10. encore/logs/_console.py +155 -0
  11. encore/logs/_runtime.py +56 -0
  12. encore/meta/__init__.py +228 -0
  13. encore/metrics/__init__.py +390 -0
  14. encore/pubsub/__init__.py +425 -0
  15. encore/py.typed +0 -0
  16. encore/secrets/__init__.py +139 -0
  17. encore/shutdown/__init__.py +164 -0
  18. encore/storage/__init__.py +5 -0
  19. encore/storage/objects/__init__.py +396 -0
  20. encore/storage/postgres/__init__.py +737 -0
  21. encore/storage/redis/__init__.py +200 -0
  22. encore/storage/redis/_base.py +42 -0
  23. encore/storage/redis/_responses.py +150 -0
  24. encore/storage/redis/_values.py +189 -0
  25. encore/storage/redis/bitmap.py +142 -0
  26. encore/storage/redis/generic.py +367 -0
  27. encore/storage/redis/geo.py +508 -0
  28. encore/storage/redis/hash.py +504 -0
  29. encore/storage/redis/json.py +614 -0
  30. encore/storage/redis/list.py +511 -0
  31. encore/storage/redis/pubsub.py +276 -0
  32. encore/storage/redis/set.py +570 -0
  33. encore/storage/redis/sorted_set.py +753 -0
  34. encore/storage/redis/stream.py +773 -0
  35. encore/storage/redis/string.py +654 -0
  36. encore/tracing/__init__.py +19 -0
  37. encore/tracing/_context.py +27 -0
  38. encore/tracing/_encode.py +351 -0
  39. encore/tracing/_provider.py +62 -0
  40. encore/tracing/_span.py +226 -0
  41. encore/tracing/_tracer.py +93 -0
  42. encore_dev-2.0.0a7.dist-info/METADATA +791 -0
  43. encore_dev-2.0.0a7.dist-info/RECORD +44 -0
  44. encore_dev-2.0.0a7.dist-info/WHEEL +4 -0
@@ -0,0 +1,508 @@
1
+ """Redis geo commands.
2
+
3
+ Keys are strings without Encore prefixes. Values accept bytes, str, int, float,
4
+ or
5
+ RedisValue implementations; value reads default to bytes. Use command[T](...) to
6
+ decode values as T. Custom encoding and decoding errors propagate to the caller.
7
+ Repeated arguments are variadic. Individual commands document their reply
8
+ shapes and any option-dependent behavior.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ from typing import Any, Optional
14
+
15
+ from ...tracing._context import active_ctx_bytes
16
+ from ._base import CommandInterface, TypedCommand
17
+ from ._values import Value, encode, T, U
18
+ from . import _responses
19
+
20
+
21
+ class _GeosearchCommand(TypedCommand[T]):
22
+ """A callable GEOSEARCH command with selectable value decoding."""
23
+
24
+ def __getitem__(self, value_type: type[U]) -> _GeosearchCommand[U]:
25
+ """Select the value type for this command.
26
+
27
+ Use geosearch[T](...) to decode stored values as T. Selecting a type
28
+ does not open a connection or change the decoder of an existing command.
29
+
30
+ Args:
31
+ value_type: bytes, str, int, float, or a class implementing
32
+ RedisValue.
33
+
34
+ Returns:
35
+ An independent command with the same arguments and the selected
36
+ decoder. Keys and other command metadata retain their existing
37
+ types.
38
+ """
39
+ return _GeosearchCommand(self._get_handle, value_type)
40
+
41
+ async def __call__(
42
+ self,
43
+ key: str,
44
+ *,
45
+ member: Value | None = None,
46
+ longitude: float | None = None,
47
+ latitude: float | None = None,
48
+ radius: float | None = None,
49
+ width: float | None = None,
50
+ height: float | None = None,
51
+ unit: str = "m",
52
+ count: int | None = None,
53
+ any: bool = False,
54
+ order: str | None = None,
55
+ withcoord: bool = False,
56
+ withdist: bool = False,
57
+ withhash: bool = False,
58
+ ) -> Any:
59
+ """Find geospatial members inside a circle or rectangle.
60
+
61
+ Args:
62
+ key: The database key, without an Encore key prefix.
63
+ member: The member to use as the center, instead of longitude and
64
+ latitude.
65
+ longitude: The center longitude in degrees; supply together with
66
+ latitude instead of member.
67
+ latitude: The center latitude in degrees; supply together with
68
+ longitude instead of member.
69
+ radius: The circle radius in the selected unit, instead of width and
70
+ height.
71
+ width: The box width in the selected unit; supply with height
72
+ instead of radius.
73
+ height: The box height in the selected unit; supply with width
74
+ instead of radius.
75
+ unit: The case-insensitive distance unit: m, km, mi, or ft.
76
+ count: The maximum number of results, or None for the server
77
+ default.
78
+ any: Whether to stop after finding count matches, without
79
+ guaranteeing the nearest matches. Requires count.
80
+ order: ASC for nearest first or DESC for farthest first,
81
+ case-insensitively; None leaves results unordered.
82
+ withcoord: Whether to include [longitude, latitude] coordinates in
83
+ each row.
84
+ withdist: Whether to include distance from the search center in each
85
+ row.
86
+ withhash: Whether to include the integer geospatial hash in each
87
+ row.
88
+
89
+ Returns:
90
+ A list of decoded members, or rows containing a member followed by
91
+ requested distance, hash, and coordinates in that order. Distances
92
+ and coordinates are bytes in RESP2 or floats in RESP3; hashes are
93
+ integers.
94
+
95
+ Raises:
96
+ UnicodeDecodeError: A value is not valid UTF-8 when the type
97
+ argument is str.
98
+ ValueError: A stored value cannot be parsed as int or float.
99
+ EncoreError: Redis rejects the command or the request fails.
100
+ """
101
+ result = await self._get_handle().geo_geosearch(
102
+ key,
103
+ member=None if member is None else encode(member),
104
+ longitude=longitude,
105
+ latitude=latitude,
106
+ radius=radius,
107
+ width=width,
108
+ height=height,
109
+ unit=unit,
110
+ count=count,
111
+ any=any,
112
+ order=order,
113
+ withcoord=withcoord,
114
+ withdist=withdist,
115
+ withhash=withhash,
116
+ source=active_ctx_bytes(),
117
+ )
118
+ return _responses.geo_members(result, self._value_type)
119
+
120
+
121
+ class _GeoradiusCommand(TypedCommand[T]):
122
+ """A callable GEORADIUS command with selectable value decoding."""
123
+
124
+ def __getitem__(self, value_type: type[U]) -> _GeoradiusCommand[U]:
125
+ """Select the value type for this command.
126
+
127
+ Use georadius[T](...) to decode stored values as T. Selecting a type
128
+ does not open a connection or change the decoder of an existing command.
129
+
130
+ Args:
131
+ value_type: bytes, str, int, float, or a class implementing
132
+ RedisValue.
133
+
134
+ Returns:
135
+ An independent command with the same arguments and the selected
136
+ decoder. Keys and other command metadata retain their existing
137
+ types.
138
+ """
139
+ return _GeoradiusCommand(self._get_handle, value_type)
140
+
141
+ async def __call__(
142
+ self,
143
+ key: str,
144
+ longitude: float,
145
+ latitude: float,
146
+ radius: float,
147
+ *,
148
+ unit: str = "m",
149
+ count: int | None = None,
150
+ any: bool = False,
151
+ order: str | None = None,
152
+ withcoord: bool = False,
153
+ withdist: bool = False,
154
+ withhash: bool = False,
155
+ store: str | None = None,
156
+ storedist: str | None = None,
157
+ ) -> Any:
158
+ """Find geospatial members within a radius of coordinates.
159
+
160
+ Args:
161
+ key: The database key, without an Encore key prefix.
162
+ longitude: The longitude in degrees, between -180 and 180.
163
+ latitude: The latitude in degrees, between approximately
164
+ -85.05112878 and 85.05112878.
165
+ radius: The search radius in the selected unit.
166
+ unit: The case-insensitive distance unit: m, km, mi, or ft.
167
+ count: The maximum number of results, or None for the server
168
+ default.
169
+ any: Whether to stop after finding count matches, without
170
+ guaranteeing the nearest matches. Requires count.
171
+ order: ASC for nearest first or DESC for farthest first,
172
+ case-insensitively; None leaves results unordered.
173
+ withcoord: Whether to include [longitude, latitude] coordinates in
174
+ each row.
175
+ withdist: Whether to include distance from the search center in each
176
+ row.
177
+ withhash: Whether to include the integer geospatial hash in each
178
+ row.
179
+ store: A destination key for results with geospatial scores.
180
+ Incompatible with storedist and reply options.
181
+ storedist: A destination key for results scored by distance in the
182
+ selected unit. Incompatible with store and reply options.
183
+
184
+ Returns:
185
+ A list of decoded members, or rows containing a member followed by
186
+ requested distance, hash, and coordinates in that order. Distances
187
+ and coordinates are bytes in RESP2 or floats in RESP3; hashes are
188
+ integers. With store or storedist, the number of members stored.
189
+
190
+ Raises:
191
+ UnicodeDecodeError: A value is not valid UTF-8 when the type
192
+ argument is str.
193
+ ValueError: A stored value cannot be parsed as int or float.
194
+ EncoreError: Redis rejects the command or the request fails.
195
+ """
196
+ result = await self._get_handle().geo_georadius(
197
+ key,
198
+ longitude,
199
+ latitude,
200
+ radius,
201
+ unit=unit,
202
+ count=count,
203
+ any=any,
204
+ order=order,
205
+ withcoord=withcoord,
206
+ withdist=withdist,
207
+ withhash=withhash,
208
+ store=store,
209
+ storedist=storedist,
210
+ source=active_ctx_bytes(),
211
+ )
212
+ return _responses.geo_members(result, self._value_type)
213
+
214
+
215
+ class _GeoradiusbymemberCommand(TypedCommand[T]):
216
+ """A callable GEORADIUSBYMEMBER command with selectable value decoding."""
217
+
218
+ def __getitem__(self, value_type: type[U]) -> _GeoradiusbymemberCommand[U]:
219
+ """Select the value type for this command.
220
+
221
+ Use georadiusbymember[T](...) to decode stored values as T. Selecting a
222
+ type does not open a connection or change the decoder of an existing
223
+ command.
224
+
225
+ Args:
226
+ value_type: bytes, str, int, float, or a class implementing
227
+ RedisValue.
228
+
229
+ Returns:
230
+ An independent command with the same arguments and the selected
231
+ decoder. Keys and other command metadata retain their existing
232
+ types.
233
+ """
234
+ return _GeoradiusbymemberCommand(self._get_handle, value_type)
235
+
236
+ async def __call__(
237
+ self,
238
+ key: str,
239
+ member: Value,
240
+ radius: float,
241
+ *,
242
+ unit: str = "m",
243
+ count: int | None = None,
244
+ any: bool = False,
245
+ order: str | None = None,
246
+ withcoord: bool = False,
247
+ withdist: bool = False,
248
+ withhash: bool = False,
249
+ store: str | None = None,
250
+ storedist: str | None = None,
251
+ ) -> Any:
252
+ """Find geospatial members within a radius of another member.
253
+
254
+ Args:
255
+ key: The database key, without an Encore key prefix.
256
+ member: The member to encode.
257
+ radius: The search radius in the selected unit.
258
+ unit: The case-insensitive distance unit: m, km, mi, or ft.
259
+ count: The maximum number of results, or None for the server
260
+ default.
261
+ any: Whether to stop after finding count matches, without
262
+ guaranteeing the nearest matches. Requires count.
263
+ order: ASC for nearest first or DESC for farthest first,
264
+ case-insensitively; None leaves results unordered.
265
+ withcoord: Whether to include [longitude, latitude] coordinates in
266
+ each row.
267
+ withdist: Whether to include distance from the search center in each
268
+ row.
269
+ withhash: Whether to include the integer geospatial hash in each
270
+ row.
271
+ store: A destination key for results with geospatial scores.
272
+ Incompatible with storedist and reply options.
273
+ storedist: A destination key for results scored by distance in the
274
+ selected unit. Incompatible with store and reply options.
275
+
276
+ Returns:
277
+ A list of decoded members, or rows containing a member followed by
278
+ requested distance, hash, and coordinates in that order. Distances
279
+ and coordinates are bytes in RESP2 or floats in RESP3; hashes are
280
+ integers. With store or storedist, the number of members stored.
281
+
282
+ Raises:
283
+ UnicodeDecodeError: A value is not valid UTF-8 when the type
284
+ argument is str.
285
+ ValueError: A stored value cannot be parsed as int or float.
286
+ EncoreError: Redis rejects the command or the request fails.
287
+ """
288
+ result = await self._get_handle().geo_georadiusbymember(
289
+ key,
290
+ encode(member),
291
+ radius,
292
+ unit=unit,
293
+ count=count,
294
+ any=any,
295
+ order=order,
296
+ withcoord=withcoord,
297
+ withdist=withdist,
298
+ withhash=withhash,
299
+ store=store,
300
+ storedist=storedist,
301
+ source=active_ctx_bytes(),
302
+ )
303
+ return _responses.geo_members(result, self._value_type)
304
+
305
+
306
+ class ReadOnlyInterface(CommandInterface):
307
+ """Commands available through a read-only database handle."""
308
+
309
+ async def geodist(
310
+ self, key: str, member1: Value, member2: Value, *, unit: str = "m"
311
+ ) -> Optional[float]:
312
+ """Return the distance between two geospatial members.
313
+
314
+ Args:
315
+ key: The database key, without an Encore key prefix.
316
+ member1: The first member to encode.
317
+ member2: The second member to encode.
318
+ unit: The case-insensitive distance unit: m, km, mi, or ft.
319
+
320
+ Returns:
321
+ The distance in the requested unit, or None if either member is
322
+ missing.
323
+
324
+ Raises:
325
+ EncoreError: Redis rejects the command or the request fails.
326
+ """
327
+ return await self._get_handle().geo_geodist(
328
+ key, encode(member1), encode(member2), unit=unit, source=active_ctx_bytes()
329
+ )
330
+
331
+ async def geohash(self, key: str, *members: Value) -> list[Optional[bytes]]:
332
+ """Return geohash strings for geospatial members.
333
+
334
+ Args:
335
+ key: The database key, without an Encore key prefix.
336
+ *members: Members to encode; may be empty.
337
+
338
+ Returns:
339
+ One geohash as bytes per member, with None for missing members.
340
+ Returns an empty list if no members are supplied.
341
+
342
+ Raises:
343
+ EncoreError: Redis rejects the command or the request fails.
344
+ """
345
+ return await self._get_handle().geo_geohash(
346
+ key, [encode(value) for value in members], source=active_ctx_bytes()
347
+ )
348
+
349
+ async def geopos(self, key: str, *members: Value) -> Any:
350
+ """Return coordinates for geospatial members.
351
+
352
+ Args:
353
+ key: The database key, without an Encore key prefix.
354
+ *members: Members to encode; may be empty.
355
+
356
+ Returns:
357
+ One [longitude, latitude] pair per member, or None for missing
358
+ members. Coordinates retain their raw reply type: bytes in RESP2 or
359
+ floats in RESP3. Returns an empty list if no members are supplied.
360
+
361
+ Raises:
362
+ EncoreError: Redis rejects the command or the request fails.
363
+ """
364
+ return await self._get_handle().geo_geopos(
365
+ key, [encode(value) for value in members], source=active_ctx_bytes()
366
+ )
367
+
368
+ @property
369
+ def geosearch(self) -> _GeosearchCommand[bytes]:
370
+ """The callable GEOSEARCH command.
371
+
372
+ Use geosearch[T](...) to select the decoded value type. Plain calls keep
373
+ stored values as bytes; keys and command metadata are unchanged.
374
+ """
375
+ return _GeosearchCommand(self._get_handle, bytes)
376
+
377
+
378
+ class Interface(ReadOnlyInterface):
379
+ """Read and write commands."""
380
+
381
+ async def geoadd(
382
+ self,
383
+ key: str,
384
+ item: tuple[float, float, Value],
385
+ *items: tuple[float, float, Value],
386
+ nx: bool = False,
387
+ xx: bool = False,
388
+ ch: bool = False,
389
+ ) -> int:
390
+ """Add geospatial members or update their coordinates.
391
+
392
+ Args:
393
+ key: The database key, without an Encore key prefix.
394
+ item: The first (longitude, latitude, member) tuple. Coordinates
395
+ are in degrees; longitude must be within [-180, 180] and
396
+ latitude within approximately [-85.05112878, 85.05112878].
397
+ *items: Additional tuples of the same shape, in order.
398
+ nx: Only add new entries; mutually exclusive with xx.
399
+ xx: Only update existing entries; mutually exclusive with nx.
400
+ ch: Whether to count changed existing members as well as new
401
+ members.
402
+
403
+ Returns:
404
+ The number of new members, or added and changed members when
405
+ ch=True.
406
+
407
+ Raises:
408
+ EncoreError: Redis rejects the command or the request fails.
409
+ """
410
+ items = (item, *items)
411
+ return await self._get_handle().geo_geoadd(
412
+ key,
413
+ [
414
+ (longitude, latitude, encode(member))
415
+ for longitude, latitude, member in items
416
+ ],
417
+ nx=nx,
418
+ xx=xx,
419
+ ch=ch,
420
+ source=active_ctx_bytes(),
421
+ )
422
+
423
+ @property
424
+ def georadius(self) -> _GeoradiusCommand[bytes]:
425
+ """The callable GEORADIUS command.
426
+
427
+ Use georadius[T](...) to select the decoded value type. Plain calls keep
428
+ stored values as bytes; keys and command metadata are unchanged.
429
+ """
430
+ return _GeoradiusCommand(self._get_handle, bytes)
431
+
432
+ @property
433
+ def georadiusbymember(self) -> _GeoradiusbymemberCommand[bytes]:
434
+ """The callable GEORADIUSBYMEMBER command.
435
+
436
+ Use georadiusbymember[T](...) to select the decoded value type. Plain
437
+ calls keep stored values as bytes; keys and command metadata are
438
+ unchanged.
439
+ """
440
+ return _GeoradiusbymemberCommand(self._get_handle, bytes)
441
+
442
+ async def geosearchstore(
443
+ self,
444
+ destination: str,
445
+ key: str,
446
+ *,
447
+ member: Value | None = None,
448
+ longitude: float | None = None,
449
+ latitude: float | None = None,
450
+ radius: float | None = None,
451
+ width: float | None = None,
452
+ height: float | None = None,
453
+ unit: str = "m",
454
+ count: int | None = None,
455
+ any: bool = False,
456
+ order: str | None = None,
457
+ storedist: bool = False,
458
+ ) -> int:
459
+ """Store geospatial search results in a destination sorted set.
460
+
461
+ Args:
462
+ destination: The destination key, without an Encore key prefix.
463
+ key: The database key, without an Encore key prefix.
464
+ member: The member to use as the center, instead of longitude and
465
+ latitude.
466
+ longitude: The center longitude in degrees; supply together with
467
+ latitude instead of member.
468
+ latitude: The center latitude in degrees; supply together with
469
+ longitude instead of member.
470
+ radius: The circle radius in the selected unit, instead of width and
471
+ height.
472
+ width: The box width in the selected unit; supply with height
473
+ instead of radius.
474
+ height: The box height in the selected unit; supply with width
475
+ instead of radius.
476
+ unit: The case-insensitive distance unit: m, km, mi, or ft.
477
+ count: The maximum number of results, or None for the server
478
+ default.
479
+ any: Whether to stop after finding count matches, without
480
+ guaranteeing the nearest matches. Requires count.
481
+ order: ASC for nearest first or DESC for farthest first,
482
+ case-insensitively; None leaves results unordered.
483
+ storedist: Whether to store distances as scores instead of
484
+ geospatial hashes.
485
+
486
+ Returns:
487
+ The number of members stored, replacing the destination's previous
488
+ value.
489
+
490
+ Raises:
491
+ EncoreError: Redis rejects the command or the request fails.
492
+ """
493
+ return await self._get_handle().geo_geosearchstore(
494
+ destination,
495
+ key,
496
+ member=None if member is None else encode(member),
497
+ longitude=longitude,
498
+ latitude=latitude,
499
+ radius=radius,
500
+ width=width,
501
+ height=height,
502
+ unit=unit,
503
+ count=count,
504
+ any=any,
505
+ order=order,
506
+ storedist=storedist,
507
+ source=active_ctx_bytes(),
508
+ )