_api.py 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. # Copyright (c) "Neo4j"
  2. # Neo4j Sweden AB [https://neo4j.com]
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # https://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from __future__ import annotations
  16. import typing as t
  17. from enum import Enum
  18. if t.TYPE_CHECKING:
  19. import typing_extensions as te
  20. __all__ = [
  21. "NotificationCategory",
  22. "NotificationClassification",
  23. "NotificationDisabledCategory",
  24. "NotificationDisabledClassification",
  25. "NotificationMinimumSeverity",
  26. "NotificationSeverity",
  27. "RoutingControl",
  28. "TelemetryAPI",
  29. ]
  30. class NotificationMinimumSeverity(str, Enum):
  31. """
  32. Filter notifications returned by the server by minimum severity.
  33. For GQL-aware servers, notifications are a subset of GqlStatusObjects.
  34. See also :attr:`.GqlStatusObject.is_notification`.
  35. Inherits from :class:`str` and :class:`enum.Enum`.
  36. Every driver API accepting a :class:`.NotificationMinimumSeverity` value
  37. will also accept a string::
  38. >>> NotificationMinimumSeverity.OFF == "OFF"
  39. True
  40. >>> NotificationMinimumSeverity.WARNING == "WARNING"
  41. True
  42. >>> NotificationMinimumSeverity.INFORMATION == "INFORMATION"
  43. True
  44. .. seealso::
  45. driver config :ref:`driver-notifications-min-severity-ref`,
  46. session config :ref:`session-notifications-min-severity-ref`
  47. .. versionadded:: 5.7
  48. """
  49. OFF = "OFF"
  50. WARNING = "WARNING"
  51. INFORMATION = "INFORMATION"
  52. if t.TYPE_CHECKING:
  53. T_NotificationMinimumSeverity = t.Union[
  54. NotificationMinimumSeverity,
  55. te.Literal[
  56. "OFF",
  57. "WARNING",
  58. "INFORMATION",
  59. ],
  60. ]
  61. __all__.append("T_NotificationMinimumSeverity")
  62. class NotificationSeverity(str, Enum):
  63. """
  64. Server-side notification severity.
  65. Inherits from :class:`str` and :class:`enum.Enum`.
  66. Hence, can also be compared to its string value::
  67. >>> NotificationSeverity.WARNING == "WARNING"
  68. True
  69. >>> NotificationSeverity.INFORMATION == "INFORMATION"
  70. True
  71. >>> NotificationSeverity.UNKNOWN == "UNKNOWN"
  72. True
  73. Example::
  74. import logging
  75. from neo4j import NotificationSeverity
  76. log = logging.getLogger(__name__)
  77. ...
  78. summary = session.run("RETURN 1").consume()
  79. for notification in summary.summary_notifications:
  80. severity = notification.severity_level
  81. if severity == NotificationSeverity.WARNING:
  82. # or severity == "WARNING"
  83. log.warning("%r", notification)
  84. elif severity == NotificationSeverity.INFORMATION:
  85. # or severity == "INFORMATION"
  86. log.info("%r", notification)
  87. else:
  88. # assert severity == NotificationSeverity.UNKNOWN
  89. # or severity == "UNKNOWN"
  90. log.debug("%r", notification)
  91. .. seealso:: :attr:`.SummaryNotification.severity_level`
  92. .. versionadded:: 5.7
  93. """
  94. WARNING = "WARNING"
  95. INFORMATION = "INFORMATION"
  96. #: Used when the server provides a Severity which the driver is unaware of.
  97. #: This can happen when connecting to a server newer than the driver.
  98. UNKNOWN = "UNKNOWN"
  99. class NotificationDisabledCategory(str, Enum):
  100. """
  101. Filter notifications returned by the server by category.
  102. For GQL-aware servers, notifications are a subset of GqlStatusObjects.
  103. See also :attr:`.GqlStatusObject.is_notification`.
  104. Inherits from :class:`str` and :class:`enum.Enum`.
  105. Every driver API accepting a :class:`.NotificationDisabledCategory` value
  106. will also accept a string::
  107. >>> NotificationDisabledCategory.UNRECOGNIZED == "UNRECOGNIZED"
  108. True
  109. >>> NotificationDisabledCategory.PERFORMANCE == "PERFORMANCE"
  110. True
  111. >>> NotificationDisabledCategory.DEPRECATION == "DEPRECATION"
  112. True
  113. .. seealso::
  114. driver config :ref:`driver-notifications-disabled-categories-ref`,
  115. session config :ref:`session-notifications-disabled-categories-ref`
  116. .. versionadded:: 5.7
  117. .. versionchanged:: 5.14
  118. Added categories :attr:`.SECURITY` and :attr:`.TOPOLOGY`.
  119. .. versionchanged:: 5.24
  120. Added category :attr:`.SCHEMA`.
  121. """
  122. HINT = "HINT"
  123. UNRECOGNIZED = "UNRECOGNIZED"
  124. UNSUPPORTED = "UNSUPPORTED"
  125. PERFORMANCE = "PERFORMANCE"
  126. DEPRECATION = "DEPRECATION"
  127. GENERIC = "GENERIC"
  128. SECURITY = "SECURITY"
  129. #: Requires server version 5.13 or newer.
  130. TOPOLOGY = "TOPOLOGY"
  131. #: Requires server version 5.17 or newer.
  132. SCHEMA = "SCHEMA"
  133. class NotificationDisabledClassification(str, Enum):
  134. """
  135. Identical to :class:`.NotificationDisabledCategory`.
  136. This alternative is provided for a consistent naming with
  137. :attr:`.GqlStatusObject.classification`.
  138. **This is a preview**.
  139. It might be changed without following the deprecation policy.
  140. See also
  141. https://github.com/neo4j/neo4j-python-driver/wiki/preview-features
  142. .. seealso::
  143. driver config
  144. :ref:`driver-notifications-disabled-classifications-ref`,
  145. session config
  146. :ref:`session-notifications-disabled-classifications-ref`
  147. .. versionadded:: 5.22
  148. .. versionchanged:: 5.24
  149. Added classification :attr:`.SCHEMA`.
  150. """
  151. HINT = "HINT"
  152. UNRECOGNIZED = "UNRECOGNIZED"
  153. UNSUPPORTED = "UNSUPPORTED"
  154. PERFORMANCE = "PERFORMANCE"
  155. DEPRECATION = "DEPRECATION"
  156. GENERIC = "GENERIC"
  157. SECURITY = "SECURITY"
  158. #: Requires server version 5.13 or newer.
  159. TOPOLOGY = "TOPOLOGY"
  160. #: Requires server version 5.17 or newer.
  161. SCHEMA = "SCHEMA"
  162. if t.TYPE_CHECKING:
  163. T_NotificationDisabledCategory = t.Union[
  164. NotificationDisabledCategory,
  165. NotificationDisabledClassification,
  166. te.Literal[
  167. "HINT",
  168. "UNRECOGNIZED",
  169. "UNSUPPORTED",
  170. "PERFORMANCE",
  171. "DEPRECATION",
  172. "GENERIC",
  173. "SECURITY",
  174. "TOPOLOGY",
  175. "SCHEMA",
  176. ],
  177. ]
  178. __all__.append("T_NotificationDisabledCategory")
  179. class NotificationCategory(str, Enum):
  180. """
  181. Server-side notification category.
  182. Inherits from :class:`str` and :class:`enum.Enum`.
  183. Hence, can also be compared to its string value::
  184. >>> NotificationCategory.DEPRECATION == "DEPRECATION"
  185. True
  186. >>> NotificationCategory.GENERIC == "GENERIC"
  187. True
  188. >>> NotificationCategory.UNKNOWN == "UNKNOWN"
  189. True
  190. .. seealso:: :attr:`.SummaryNotification.category`
  191. .. versionadded:: 5.7
  192. .. versionchanged:: 5.14
  193. Added categories :attr:`.SECURITY` and :attr:`.TOPOLOGY`.
  194. .. versionchanged:: 5.24
  195. Added category :attr:`.SCHEMA`.
  196. """
  197. HINT = "HINT"
  198. UNRECOGNIZED = "UNRECOGNIZED"
  199. UNSUPPORTED = "UNSUPPORTED"
  200. PERFORMANCE = "PERFORMANCE"
  201. DEPRECATION = "DEPRECATION"
  202. GENERIC = "GENERIC"
  203. SECURITY = "SECURITY"
  204. TOPOLOGY = "TOPOLOGY"
  205. SCHEMA = "SCHEMA"
  206. #: Used when the server provides a Category which the driver is unaware of.
  207. #: This can happen when connecting to a server newer than the driver or
  208. #: before notification categories were introduced.
  209. UNKNOWN = "UNKNOWN"
  210. class NotificationClassification(str, Enum):
  211. """
  212. Identical to :class:`.NotificationCategory`.
  213. This alternative is provided for a consistent naming with
  214. :attr:`.GqlStatusObject.classification`.
  215. **This is a preview**.
  216. It might be changed without following the deprecation policy.
  217. See also
  218. https://github.com/neo4j/neo4j-python-driver/wiki/preview-features
  219. .. seealso:: :attr:`.GqlStatusObject.classification`
  220. .. versionadded:: 5.22
  221. .. versionchanged:: 5.24
  222. Added classification :attr:`.SCHEMA`.
  223. """
  224. HINT = "HINT"
  225. UNRECOGNIZED = "UNRECOGNIZED"
  226. UNSUPPORTED = "UNSUPPORTED"
  227. PERFORMANCE = "PERFORMANCE"
  228. DEPRECATION = "DEPRECATION"
  229. GENERIC = "GENERIC"
  230. SECURITY = "SECURITY"
  231. TOPOLOGY = "TOPOLOGY"
  232. SCHEMA = "SCHEMA"
  233. #: Used when the server provides a Category which the driver is unaware of.
  234. #: This can happen when connecting to a server newer than the driver or
  235. #: before notification categories were introduced.
  236. UNKNOWN = "UNKNOWN"
  237. class RoutingControl(str, Enum):
  238. """
  239. Selection which cluster members to route a query connect to.
  240. Inherits from :class:`str` and :class:`enum.Enum`.
  241. Every driver API accepting a :class:`.RoutingControl` value will also
  242. accept a string::
  243. >>> RoutingControl.READ == "r"
  244. True
  245. >>> RoutingControl.WRITE == "w"
  246. True
  247. .. seealso::
  248. :meth:`.AsyncDriver.execute_query`, :meth:`.Driver.execute_query`
  249. .. versionadded:: 5.5
  250. .. versionchanged:: 5.8
  251. * Renamed ``READERS`` to ``READ`` and ``WRITERS`` to ``WRITE``.
  252. * Stabilized from experimental.
  253. """
  254. READ = "r"
  255. WRITE = "w"
  256. class TelemetryAPI(int, Enum):
  257. TX_FUNC = 0
  258. TX = 1
  259. AUTO_COMMIT = 2
  260. DRIVER = 3
  261. if t.TYPE_CHECKING:
  262. T_RoutingControl = t.Union[
  263. RoutingControl,
  264. te.Literal["r", "w"],
  265. ]
  266. __all__.append("T_RoutingControl")