redis 5.3.0b4__py3-none-any.whl → 6.0.0__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 (51) hide show
  1. redis/__init__.py +2 -11
  2. redis/_parsers/base.py +14 -2
  3. redis/_parsers/resp3.py +2 -2
  4. redis/asyncio/client.py +103 -83
  5. redis/asyncio/cluster.py +147 -102
  6. redis/asyncio/connection.py +77 -24
  7. redis/asyncio/lock.py +26 -5
  8. redis/asyncio/retry.py +12 -0
  9. redis/asyncio/sentinel.py +11 -1
  10. redis/asyncio/utils.py +1 -1
  11. redis/auth/token.py +6 -2
  12. redis/backoff.py +15 -0
  13. redis/client.py +160 -138
  14. redis/cluster.py +211 -82
  15. redis/commands/cluster.py +1 -11
  16. redis/commands/core.py +219 -207
  17. redis/commands/helpers.py +19 -76
  18. redis/commands/json/__init__.py +1 -1
  19. redis/commands/redismodules.py +5 -17
  20. redis/commands/search/aggregation.py +3 -1
  21. redis/commands/search/commands.py +43 -16
  22. redis/commands/search/dialect.py +3 -0
  23. redis/commands/search/profile_information.py +14 -0
  24. redis/commands/search/query.py +5 -1
  25. redis/commands/timeseries/__init__.py +1 -1
  26. redis/commands/vectorset/__init__.py +46 -0
  27. redis/commands/vectorset/commands.py +367 -0
  28. redis/commands/vectorset/utils.py +94 -0
  29. redis/connection.py +89 -33
  30. redis/exceptions.py +4 -1
  31. redis/lock.py +24 -4
  32. redis/ocsp.py +2 -1
  33. redis/retry.py +12 -0
  34. redis/sentinel.py +3 -1
  35. redis/typing.py +1 -1
  36. redis/utils.py +114 -1
  37. {redis-5.3.0b4.dist-info → redis-6.0.0.dist-info}/METADATA +57 -23
  38. redis-6.0.0.dist-info/RECORD +78 -0
  39. {redis-5.3.0b4.dist-info → redis-6.0.0.dist-info}/WHEEL +1 -2
  40. redis/commands/graph/__init__.py +0 -263
  41. redis/commands/graph/commands.py +0 -313
  42. redis/commands/graph/edge.py +0 -91
  43. redis/commands/graph/exceptions.py +0 -3
  44. redis/commands/graph/execution_plan.py +0 -211
  45. redis/commands/graph/node.py +0 -88
  46. redis/commands/graph/path.py +0 -78
  47. redis/commands/graph/query_result.py +0 -588
  48. redis-5.3.0b4.dist-info/RECORD +0 -82
  49. redis-5.3.0b4.dist-info/top_level.txt +0 -1
  50. /redis/commands/search/{indexDefinition.py → index_definition.py} +0 -0
  51. {redis-5.3.0b4.dist-info → redis-6.0.0.dist-info/licenses}/LICENSE +0 -0
@@ -1,17 +1,16 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: redis
3
- Version: 5.3.0b4
3
+ Version: 6.0.0
4
4
  Summary: Python client for Redis database and key-value store
5
- Home-page: https://github.com/redis/redis-py
6
- Author: Redis Inc.
7
- Author-email: oss@redis.com
8
- License: MIT
9
- Project-URL: Documentation, https://redis.readthedocs.io/en/latest/
10
5
  Project-URL: Changes, https://github.com/redis/redis-py/releases
11
6
  Project-URL: Code, https://github.com/redis/redis-py
7
+ Project-URL: Documentation, https://redis.readthedocs.io/en/latest/
8
+ Project-URL: Homepage, https://github.com/redis/redis-py
12
9
  Project-URL: Issue tracker, https://github.com/redis/redis-py/issues
13
- Keywords: Redis,key-value store,database
14
- Platform: UNKNOWN
10
+ Author-email: "Redis Inc." <oss@redis.com>
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: Redis,database,key-value-store
15
14
  Classifier: Development Status :: 5 - Production/Stable
16
15
  Classifier: Environment :: Console
17
16
  Classifier: Intended Audience :: Developers
@@ -25,19 +24,20 @@ Classifier: Programming Language :: Python :: 3.9
25
24
  Classifier: Programming Language :: Python :: 3.10
26
25
  Classifier: Programming Language :: Python :: 3.11
27
26
  Classifier: Programming Language :: Python :: 3.12
27
+ Classifier: Programming Language :: Python :: 3.13
28
28
  Classifier: Programming Language :: Python :: Implementation :: CPython
29
29
  Classifier: Programming Language :: Python :: Implementation :: PyPy
30
30
  Requires-Python: >=3.8
31
- Description-Content-Type: text/markdown
32
- License-File: LICENSE
33
- Requires-Dist: PyJWT~=2.9.0
34
- Requires-Dist: async-timeout>=4.0.3; python_full_version < "3.11.3"
31
+ Requires-Dist: async-timeout>=4.0.3; python_full_version < '3.11.3'
35
32
  Provides-Extra: hiredis
36
- Requires-Dist: hiredis>=3.0.0; extra == "hiredis"
33
+ Requires-Dist: hiredis>=3.0.0; extra == 'hiredis'
34
+ Provides-Extra: jwt
35
+ Requires-Dist: pyjwt~=2.9.0; extra == 'jwt'
37
36
  Provides-Extra: ocsp
38
- Requires-Dist: cryptography>=36.0.1; extra == "ocsp"
39
- Requires-Dist: pyopenssl==23.2.1; extra == "ocsp"
40
- Requires-Dist: requests>=2.31.0; extra == "ocsp"
37
+ Requires-Dist: cryptography>=36.0.1; extra == 'ocsp'
38
+ Requires-Dist: pyopenssl>=20.0.1; extra == 'ocsp'
39
+ Requires-Dist: requests>=2.31.0; extra == 'ocsp'
40
+ Description-Content-Type: text/markdown
41
41
 
42
42
  # redis-py
43
43
 
@@ -54,13 +54,13 @@ The Python interface to the Redis key-value store.
54
54
 
55
55
  ---------------------------------------------
56
56
 
57
- **Note: ** redis-py 5.0 will be the last version of redis-py to support Python 3.7, as it has reached [end of life](https://devguide.python.org/versions/). redis-py 5.1 will support Python 3.8+.
57
+ **Note:** redis-py 5.0 will be the last version of redis-py to support Python 3.7, as it has reached [end of life](https://devguide.python.org/versions/). redis-py 5.1 will support Python 3.8+.
58
58
 
59
59
  ---------------------------------------------
60
60
 
61
61
  ## How do I Redis?
62
62
 
63
- [Learn for free at Redis University](https://redis.io/university/)
63
+ [Learn for free at Redis University](https://redis.io/learn/university)
64
64
 
65
65
  [Try the Redis Cloud](https://redis.io/try-free/)
66
66
 
@@ -95,7 +95,7 @@ Looking for a high-level library to handle object mapping? See [redis-om-python]
95
95
 
96
96
  ## Supported Redis Versions
97
97
 
98
- The most recent version of this library supports redis version [5.0](https://github.com/redis/redis/blob/5.0/00-RELEASENOTES), [6.0](https://github.com/redis/redis/blob/6.0/00-RELEASENOTES), [6.2](https://github.com/redis/redis/blob/6.2/00-RELEASENOTES), [7.0](https://github.com/redis/redis/blob/7.0/00-RELEASENOTES), [7.2](https://github.com/redis/redis/blob/7.2/00-RELEASENOTES) and [7.4](https://github.com/redis/redis/blob/7.4/00-RELEASENOTES).
98
+ The most recent version of this library supports redis version [7.2](https://github.com/redis/redis/blob/7.2/00-RELEASENOTES), [7.4](https://github.com/redis/redis/blob/7.4/00-RELEASENOTES) and [8.0](https://github.com/redis/redis/blob/8.0/00-RELEASENOTES).
99
99
 
100
100
  The table below highlights version compatibility of the most-recent library versions and redis versions.
101
101
 
@@ -103,7 +103,8 @@ The table below highlights version compatibility of the most-recent library vers
103
103
  |-----------------|-------------------|
104
104
  | 3.5.3 | <= 6.2 Family of releases |
105
105
  | >= 4.5.0 | Version 5.0 to 7.0 |
106
- | >= 5.0.0 | Version 5.0 to current |
106
+ | >= 5.0.0 | Version 5.0 to 7.4 |
107
+ | >= 6.0.0 | Version 7.2 to current |
107
108
 
108
109
 
109
110
  ## Usage
@@ -193,8 +194,42 @@ The following example shows how to utilize [Redis Pub/Sub](https://redis.io/docs
193
194
  {'pattern': None, 'type': 'subscribe', 'channel': b'my-second-channel', 'data': 1}
194
195
  ```
195
196
 
197
+ ### Redis’ search and query capabilities default dialect
198
+
199
+ Release 6.0.0 introduces a client-side default dialect for Redis’ search and query capabilities.
200
+ By default, the client now overrides the server-side dialect with version 2, automatically appending *DIALECT 2* to commands like *FT.AGGREGATE* and *FT.SEARCH*.
196
201
 
197
- --------------------------
202
+ **Important**: Be aware that the query dialect may impact the results returned. If needed, you can revert to a different dialect version by configuring the client accordingly.
203
+
204
+ ``` python
205
+ >>> from redis.commands.search.field import TextField
206
+ >>> from redis.commands.search.query import Query
207
+ >>> from redis.commands.search.index_definition import IndexDefinition
208
+ >>> import redis
209
+
210
+ >>> r = redis.Redis(host='localhost', port=6379, db=0)
211
+ >>> r.ft().create_index(
212
+ >>> (TextField("name"), TextField("lastname")),
213
+ >>> definition=IndexDefinition(prefix=["test:"]),
214
+ >>> )
215
+
216
+ >>> r.hset("test:1", "name", "James")
217
+ >>> r.hset("test:1", "lastname", "Brown")
218
+
219
+ >>> # Query with default DIALECT 2
220
+ >>> query = "@name: James Brown"
221
+ >>> q = Query(query)
222
+ >>> res = r.ft().search(q)
223
+
224
+ >>> # Query with explicit DIALECT 1
225
+ >>> query = "@name: James Brown"
226
+ >>> q = Query(query).dialect(1)
227
+ >>> res = r.ft().search(q)
228
+ ```
229
+
230
+ You can find further details in the [query dialect documentation](https://redis.io/docs/latest/develop/interact/search-and-query/advanced-concepts/dialects/).
231
+
232
+ ---------------------------------------------
198
233
 
199
234
  ### Author
200
235
 
@@ -211,4 +246,3 @@ Special thanks to:
211
246
  - Paul Hubbard for initial packaging support.
212
247
 
213
248
  [![Redis](./docs/_static/logo-redis.svg)](https://redis.io)
214
-
@@ -0,0 +1,78 @@
1
+ redis/__init__.py,sha256=fT6kJp1ykDbfHxR2G9Ej4R2h3YAWKAipZGFOwX260sI,1822
2
+ redis/backoff.py,sha256=d22h74LEatJiFd_5o8HvFW3biFBotYOFZHddHt45ydc,3663
3
+ redis/cache.py,sha256=68rJDNogvNwgdgBel6zSX9QziL11qsKIMhmvQvHvznM,9549
4
+ redis/client.py,sha256=I4GSf0uwz6EAq50PBMQVeALyM6J8c13Fjy9TCatX4I4,62359
5
+ redis/cluster.py,sha256=GKVIiNpX-ZTk2HZBlTErmLRRnDjtGMbD_ebuo1tyHoU,101664
6
+ redis/connection.py,sha256=Ogs7tQT5hgO7nushUzfUqFKS4Nyj5eYdWoYQziDSF-o,66596
7
+ redis/crc.py,sha256=Z3kXFtkY2LdgefnQMud1xr4vG5UYvA9LCMqNMX1ywu4,729
8
+ redis/credentials.py,sha256=GOnO3-LSW34efHaIrUbS742Mw8l70mRzF6UrKiKZsMY,1828
9
+ redis/event.py,sha256=urOK241IdgmCQ3fq7GqXRstZ2vcXRV14bBBMdN3latk,12129
10
+ redis/exceptions.py,sha256=wWrzT28g_P7PMISyP2zUsYd4oFBUycSD1L5ln2_pD7o,5216
11
+ redis/lock.py,sha256=GrvPSxaOqKo7iAL2oi5ZUEPsOkxAXHVE_Tp1ejgO2fY,12760
12
+ redis/ocsp.py,sha256=teYSmKnCtk6B3jJLdNYbZN4OE0mxgspt2zUPbkIQzio,11452
13
+ redis/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ redis/retry.py,sha256=n-YU-pmjhaIKn3Vgh-eVf5TMu3ubsmgxD3CSn5z--m8,2469
15
+ redis/sentinel.py,sha256=DBphu6uNp6ZCSaVDSVC8nFhSxG93a12DnzgGWpyeh64,14757
16
+ redis/typing.py,sha256=k7F_3Vtsexeb7mUl6txlwrY1veGDLEhtcHe9FwIJOOo,2149
17
+ redis/utils.py,sha256=XD4ySRo9JzLIMMpQY_q9MsxUIdEPee1d7rAq7xhmSwM,8268
18
+ redis/_parsers/__init__.py,sha256=qkfgV2X9iyvQAvbLdSelwgz0dCk9SGAosCvuZC9-qDc,550
19
+ redis/_parsers/base.py,sha256=WtCbM2CaOgHk7uxwWXA2KXDlZqfYA1EJrVX_NvdOZNk,7801
20
+ redis/_parsers/commands.py,sha256=pmR4hl4u93UvCmeDgePHFc6pWDr4slrKEvCsdMmtj_M,11052
21
+ redis/_parsers/encoders.py,sha256=X0jvTp-E4TZUlZxV5LJJ88TuVrF1vly5tuC0xjxGaSc,1734
22
+ redis/_parsers/helpers.py,sha256=X5wkGDtuzseeCz23_t3FJpzy1ltIvh7zO1uD3cypiOs,29184
23
+ redis/_parsers/hiredis.py,sha256=qL1iCkWlxI63PiP99u_MY5-V6zKaesW2fD-IMNtc0QI,8189
24
+ redis/_parsers/resp2.py,sha256=f22kH-_ZP2iNtOn6xOe65MSy_fJpu8OEn1u_hgeeojI,4813
25
+ redis/_parsers/resp3.py,sha256=JgLDeryCAqx75ghM78mAvxumzWBMEWupmFpaRoL6Xqo,11129
26
+ redis/_parsers/socket.py,sha256=CKD8QW_wFSNlIZzxlbNduaGpiv0I8wBcsGuAIojDfJg,5403
27
+ redis/asyncio/__init__.py,sha256=uoDD8XYVi0Kj6mcufYwLDUTQXmBRx7a0bhKF9stZr7I,1489
28
+ redis/asyncio/client.py,sha256=xZNHB8SEWe_CrDOrNoKUEZMW4Aw_zKF0iygD7MOsujI,61954
29
+ redis/asyncio/cluster.py,sha256=ZNQiZKcC36NqnBa6wg1_O8dq4ydyVNXFBj_PCS46lsg,67772
30
+ redis/asyncio/connection.py,sha256=2z8JqBhe5CKMjYgup_02QN2B1Dzz-QHlGjNA8pR3Ow8,48874
31
+ redis/asyncio/lock.py,sha256=GxgV6EsyKpMjh74KtaOPxh4fNPuwApz6Th46qhvrAws,12801
32
+ redis/asyncio/retry.py,sha256=8carxJLme2f0frB9Z0wU3mHqKzwqzGAGb2TMEtaaMvo,2482
33
+ redis/asyncio/sentinel.py,sha256=H7N_hvdATojwY06aH1AawFV-05AImqtOSAq0xKElbbk,14636
34
+ redis/asyncio/utils.py,sha256=31xFzXczDgSRyf6hSjiwue1eDQ_XlP_OJdp5dKxW_aE,718
35
+ redis/auth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
+ redis/auth/err.py,sha256=WYkbuDIzwp1S-eAvsya6QMlO6g9QIXbzMITOsTWX0xk,694
37
+ redis/auth/idp.py,sha256=IMDIIb9q72vbIwtFN8vPdaAKZVTdh0HuC5uj5ufqmw4,631
38
+ redis/auth/token.py,sha256=qYwAgxFW3S93QDUqp1BTsj7Pj9ZohnixGeOX0s7AsjY,3317
39
+ redis/auth/token_manager.py,sha256=ShBsYXiBZBJBOMB_Y-pXfLwEOAmc9s1okaCECinNZ7g,12018
40
+ redis/commands/__init__.py,sha256=cTUH-MGvaLYS0WuoytyqtN1wniw2A1KbkUXcpvOSY3I,576
41
+ redis/commands/cluster.py,sha256=vdWdpl4mP51oqfYBZHg5CUXt6jPaNp7aCLHyTieDrt8,31248
42
+ redis/commands/core.py,sha256=dw1iVparHVoWBivdRNuEQXHNwP7_8cTJ-yj1uFZeDC4,238478
43
+ redis/commands/helpers.py,sha256=VCoPdBMCr4wxdWBw1EB9R7ZBbQM0exAG1kws4XwsCII,3318
44
+ redis/commands/redismodules.py,sha256=H3lHeyWO-KrOmNn0dilebQyiHRCflED4tgXuswWpSGs,2143
45
+ redis/commands/sentinel.py,sha256=hRcIQ9x9nEkdcCsJzo6Ves6vk-3tsfQqfJTT_v3oLY0,4110
46
+ redis/commands/bf/__init__.py,sha256=qk4DA9KsMiP4WYqYeP1T5ScBwctsVtlLyMhrYIyq1Zc,8019
47
+ redis/commands/bf/commands.py,sha256=xeKt8E7G8HB-l922J0DLg07CEIZTVNGx_2Lfyw1gIck,21283
48
+ redis/commands/bf/info.py,sha256=_OB2v_hAPI9mdVNiBx8jUtH2MhMoct9ZRm-e8In6wQo,3355
49
+ redis/commands/json/__init__.py,sha256=bznXhLYR652rfLfLp8cz0ZN0Yr8IRx4FgON_tq9_2Io,4845
50
+ redis/commands/json/_util.py,sha256=b_VQTh10FyLl8BtREfJfDagOJCyd6wTQQs8g63pi5GI,116
51
+ redis/commands/json/commands.py,sha256=8CRierNqK_VfFoaa9s0rr28uZmqs7nQaAuz4qo0UYZY,15747
52
+ redis/commands/json/decoders.py,sha256=a_IoMV_wgeJyUifD4P6HTcM9s6FhricwmzQcZRmc-Gw,1411
53
+ redis/commands/json/path.py,sha256=0zaO6_q_FVMk1Bkhkb7Wcr8AF2Tfr69VhkKy1IBVhpA,393
54
+ redis/commands/search/__init__.py,sha256=happQFVF0j7P87p7LQsUK5AK0kuem9cA-xvVRdQWpos,5744
55
+ redis/commands/search/_util.py,sha256=9Mp72OO5Ib5UbfN7uXb-iB7hQCm1jQLV90ms2P9XSGU,219
56
+ redis/commands/search/aggregation.py,sha256=CcZSZyquLWLrcSblwgt-bSyMvm-TQS9B7N8QI_ahCBU,11582
57
+ redis/commands/search/commands.py,sha256=ozyF6YgCiMArhb6ScXLPy49hnJwm4CGK4vrJRwSeB-I,38413
58
+ redis/commands/search/dialect.py,sha256=-7M6kkr33x0FkMtKmUsbeRAE6qxLUbqdJCqIo0UKIXo,105
59
+ redis/commands/search/document.py,sha256=g2R-PRgq-jN33_GLXzavvse4cpIHBMfjPfPK7tnE9Gc,413
60
+ redis/commands/search/field.py,sha256=ZWHYTtrLi-zZojohqXoidfllxP0SiadBW6hnGkBw7mM,5891
61
+ redis/commands/search/index_definition.py,sha256=VL2CMzjxN0HEIaTn88evnHX1fCEmytbik4vAmiiYSC8,2489
62
+ redis/commands/search/profile_information.py,sha256=w9SbMiHbcZ1TpsZMe8cMIyO1hGkm5GhnZ_Gqg1feLtc,249
63
+ redis/commands/search/query.py,sha256=MbSs-cY7hG1OEkO-i6LJ_Ui1D3d2VyDTXPrmb-rty7w,12199
64
+ redis/commands/search/querystring.py,sha256=dE577kOqkCErNgO-IXI4xFVHI8kQE-JiH5ZRI_CKjHE,7597
65
+ redis/commands/search/reducers.py,sha256=Scceylx8BjyqS-TJOdhNW63n6tecL9ojt4U5Sqho5UY,4220
66
+ redis/commands/search/result.py,sha256=iuqmwOeCNo_7N4a_YxxDzVdOTpbwfF1T2uuq5sTqzMo,2624
67
+ redis/commands/search/suggestion.py,sha256=V_re6suDCoNc0ETn_P1t51FeK4pCamPwxZRxCY8jscE,1612
68
+ redis/commands/timeseries/__init__.py,sha256=k492_xE_lBD0cVSX82TWBiNxOWuDDrrVZUjINi3LZSc,3450
69
+ redis/commands/timeseries/commands.py,sha256=8Z2BEyP23qTYCJR_e9zdG11yWmIDwGBMO2PJNLtK2BA,47147
70
+ redis/commands/timeseries/info.py,sha256=meZYdu7IV9KaUWMKZs9qW4vo3Q9MwhdY-EBtKQzls5o,3223
71
+ redis/commands/timeseries/utils.py,sha256=NLwSOS5Dz9N8dYQSzEyBIvrItOWwfQ0xgDj8un6x3dU,1319
72
+ redis/commands/vectorset/__init__.py,sha256=_fM0UdYjuzs8YWIUjQGH9QX5FwI0So8_D-5ALWWrWFc,1322
73
+ redis/commands/vectorset/commands.py,sha256=7CvQNFvkXuG3XPhHJ82y_oBYJwewRFz84aEi3OCH4Rw,12495
74
+ redis/commands/vectorset/utils.py,sha256=N-x0URyg76XC39CNfBym6FkFCVgm5NthzWKBnc2H0Xc,2981
75
+ redis-6.0.0.dist-info/METADATA,sha256=leo2cHlSJphUhY-yaz94tv1h1oUPN1P4mYxdHjqbZRA,10508
76
+ redis-6.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
77
+ redis-6.0.0.dist-info/licenses/LICENSE,sha256=pXslClvwPXr-VbdAYzE_Ktt7ANVGwKsUmok5gzP-PMg,1074
78
+ redis-6.0.0.dist-info/RECORD,,
@@ -1,5 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.45.1)
2
+ Generator: hatchling 1.27.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
-
@@ -1,263 +0,0 @@
1
- import warnings
2
-
3
- from ..helpers import quote_string, random_string, stringify_param_value
4
- from .commands import AsyncGraphCommands, GraphCommands
5
- from .edge import Edge # noqa
6
- from .node import Node # noqa
7
- from .path import Path # noqa
8
-
9
- DB_LABELS = "DB.LABELS"
10
- DB_RAELATIONSHIPTYPES = "DB.RELATIONSHIPTYPES"
11
- DB_PROPERTYKEYS = "DB.PROPERTYKEYS"
12
-
13
-
14
- class Graph(GraphCommands):
15
- """
16
- Graph, collection of nodes and edges.
17
- """
18
-
19
- def __init__(self, client, name=random_string()):
20
- """
21
- Create a new graph.
22
- """
23
- warnings.warn(
24
- DeprecationWarning(
25
- "RedisGraph support is deprecated as of Redis Stack 7.2 \
26
- (https://redis.com/blog/redisgraph-eol/)"
27
- )
28
- )
29
- self.NAME = name # Graph key
30
- self.client = client
31
- self.execute_command = client.execute_command
32
-
33
- self.nodes = {}
34
- self.edges = []
35
- self._labels = [] # List of node labels.
36
- self._properties = [] # List of properties.
37
- self._relationship_types = [] # List of relation types.
38
- self.version = 0 # Graph version
39
-
40
- @property
41
- def name(self):
42
- return self.NAME
43
-
44
- def _clear_schema(self):
45
- self._labels = []
46
- self._properties = []
47
- self._relationship_types = []
48
-
49
- def _refresh_schema(self):
50
- self._clear_schema()
51
- self._refresh_labels()
52
- self._refresh_relations()
53
- self._refresh_attributes()
54
-
55
- def _refresh_labels(self):
56
- lbls = self.labels()
57
-
58
- # Unpack data.
59
- self._labels = [l[0] for _, l in enumerate(lbls)]
60
-
61
- def _refresh_relations(self):
62
- rels = self.relationship_types()
63
-
64
- # Unpack data.
65
- self._relationship_types = [r[0] for _, r in enumerate(rels)]
66
-
67
- def _refresh_attributes(self):
68
- props = self.property_keys()
69
-
70
- # Unpack data.
71
- self._properties = [p[0] for _, p in enumerate(props)]
72
-
73
- def get_label(self, idx):
74
- """
75
- Returns a label by it's index
76
-
77
- Args:
78
-
79
- idx:
80
- The index of the label
81
- """
82
- try:
83
- label = self._labels[idx]
84
- except IndexError:
85
- # Refresh labels.
86
- self._refresh_labels()
87
- label = self._labels[idx]
88
- return label
89
-
90
- def get_relation(self, idx):
91
- """
92
- Returns a relationship type by it's index
93
-
94
- Args:
95
-
96
- idx:
97
- The index of the relation
98
- """
99
- try:
100
- relationship_type = self._relationship_types[idx]
101
- except IndexError:
102
- # Refresh relationship types.
103
- self._refresh_relations()
104
- relationship_type = self._relationship_types[idx]
105
- return relationship_type
106
-
107
- def get_property(self, idx):
108
- """
109
- Returns a property by it's index
110
-
111
- Args:
112
-
113
- idx:
114
- The index of the property
115
- """
116
- try:
117
- p = self._properties[idx]
118
- except IndexError:
119
- # Refresh properties.
120
- self._refresh_attributes()
121
- p = self._properties[idx]
122
- return p
123
-
124
- def add_node(self, node):
125
- """
126
- Adds a node to the graph.
127
- """
128
- if node.alias is None:
129
- node.alias = random_string()
130
- self.nodes[node.alias] = node
131
-
132
- def add_edge(self, edge):
133
- """
134
- Adds an edge to the graph.
135
- """
136
- if not (self.nodes[edge.src_node.alias] and self.nodes[edge.dest_node.alias]):
137
- raise AssertionError("Both edge's end must be in the graph")
138
-
139
- self.edges.append(edge)
140
-
141
- def _build_params_header(self, params):
142
- if params is None:
143
- return ""
144
- if not isinstance(params, dict):
145
- raise TypeError("'params' must be a dict")
146
- # Header starts with "CYPHER"
147
- params_header = "CYPHER "
148
- for key, value in params.items():
149
- params_header += str(key) + "=" + stringify_param_value(value) + " "
150
- return params_header
151
-
152
- # Procedures.
153
- def call_procedure(self, procedure, *args, read_only=False, **kwagrs):
154
- args = [quote_string(arg) for arg in args]
155
- q = f"CALL {procedure}({','.join(args)})"
156
-
157
- y = kwagrs.get("y", None)
158
- if y is not None:
159
- q += f"YIELD {','.join(y)}"
160
-
161
- return self.query(q, read_only=read_only)
162
-
163
- def labels(self):
164
- return self.call_procedure(DB_LABELS, read_only=True).result_set
165
-
166
- def relationship_types(self):
167
- return self.call_procedure(DB_RAELATIONSHIPTYPES, read_only=True).result_set
168
-
169
- def property_keys(self):
170
- return self.call_procedure(DB_PROPERTYKEYS, read_only=True).result_set
171
-
172
-
173
- class AsyncGraph(Graph, AsyncGraphCommands):
174
- """Async version for Graph"""
175
-
176
- async def _refresh_labels(self):
177
- lbls = await self.labels()
178
-
179
- # Unpack data.
180
- self._labels = [l[0] for _, l in enumerate(lbls)]
181
-
182
- async def _refresh_attributes(self):
183
- props = await self.property_keys()
184
-
185
- # Unpack data.
186
- self._properties = [p[0] for _, p in enumerate(props)]
187
-
188
- async def _refresh_relations(self):
189
- rels = await self.relationship_types()
190
-
191
- # Unpack data.
192
- self._relationship_types = [r[0] for _, r in enumerate(rels)]
193
-
194
- async def get_label(self, idx):
195
- """
196
- Returns a label by it's index
197
-
198
- Args:
199
-
200
- idx:
201
- The index of the label
202
- """
203
- try:
204
- label = self._labels[idx]
205
- except IndexError:
206
- # Refresh labels.
207
- await self._refresh_labels()
208
- label = self._labels[idx]
209
- return label
210
-
211
- async def get_property(self, idx):
212
- """
213
- Returns a property by it's index
214
-
215
- Args:
216
-
217
- idx:
218
- The index of the property
219
- """
220
- try:
221
- p = self._properties[idx]
222
- except IndexError:
223
- # Refresh properties.
224
- await self._refresh_attributes()
225
- p = self._properties[idx]
226
- return p
227
-
228
- async def get_relation(self, idx):
229
- """
230
- Returns a relationship type by it's index
231
-
232
- Args:
233
-
234
- idx:
235
- The index of the relation
236
- """
237
- try:
238
- relationship_type = self._relationship_types[idx]
239
- except IndexError:
240
- # Refresh relationship types.
241
- await self._refresh_relations()
242
- relationship_type = self._relationship_types[idx]
243
- return relationship_type
244
-
245
- async def call_procedure(self, procedure, *args, read_only=False, **kwagrs):
246
- args = [quote_string(arg) for arg in args]
247
- q = f"CALL {procedure}({','.join(args)})"
248
-
249
- y = kwagrs.get("y", None)
250
- if y is not None:
251
- f"YIELD {','.join(y)}"
252
- return await self.query(q, read_only=read_only)
253
-
254
- async def labels(self):
255
- return (await self.call_procedure(DB_LABELS, read_only=True)).result_set
256
-
257
- async def property_keys(self):
258
- return (await self.call_procedure(DB_PROPERTYKEYS, read_only=True)).result_set
259
-
260
- async def relationship_types(self):
261
- return (
262
- await self.call_procedure(DB_RAELATIONSHIPTYPES, read_only=True)
263
- ).result_set