__init__.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. import typing as _t
  16. from logging import getLogger as _getLogger
  17. from ._api import ( # noqa: F401 dynamic attributes
  18. NotificationCategory,
  19. NotificationDisabledCategory,
  20. NotificationDisabledClassification as _NotificationDisabledClassification,
  21. NotificationMinimumSeverity,
  22. NotificationSeverity,
  23. RoutingControl,
  24. )
  25. from ._async.driver import (
  26. AsyncBoltDriver,
  27. AsyncDriver,
  28. AsyncGraphDatabase,
  29. AsyncNeo4jDriver,
  30. )
  31. from ._async.work import (
  32. AsyncManagedTransaction,
  33. AsyncResult,
  34. AsyncSession,
  35. AsyncTransaction,
  36. )
  37. from ._conf import ( # noqa: F401 dynamic attribute
  38. Config as _Config,
  39. SessionConfig as _SessionConfig,
  40. TrustAll,
  41. TrustCustomCAs,
  42. TrustSystemCAs,
  43. WorkspaceConfig as _WorkspaceConfig,
  44. )
  45. from ._data import Record
  46. from ._meta import (
  47. deprecated_package as _deprecated_package,
  48. deprecation_warn as _deprecation_warn,
  49. ExperimentalWarning,
  50. get_user_agent,
  51. preview_warn as _preview_warn,
  52. PreviewWarning,
  53. version as __version__,
  54. )
  55. from ._sync.config import ( # noqa: F401 dynamic attribute
  56. PoolConfig as _PoolConfig,
  57. )
  58. from ._sync.driver import (
  59. BoltDriver,
  60. Driver,
  61. GraphDatabase,
  62. Neo4jDriver,
  63. )
  64. from ._sync.work import (
  65. ManagedTransaction,
  66. Result,
  67. Session,
  68. Transaction,
  69. )
  70. from ._work import ( # noqa: F401 dynamic attribute
  71. EagerResult,
  72. GqlStatusObject as _GqlStatusObject,
  73. NotificationClassification as _NotificationClassification,
  74. Query,
  75. ResultSummary,
  76. SummaryCounters,
  77. SummaryInputPosition,
  78. SummaryNotification,
  79. unit_of_work,
  80. )
  81. if _t.TYPE_CHECKING:
  82. from ._api import NotificationDisabledClassification # noqa: TCH004 false positive (dynamic attribute)
  83. from ._work import (
  84. GqlStatusObject, # noqa: TCH004 false positive (dynamic attribute)
  85. NotificationClassification, # noqa: TCH004 false positive (dynamic attribute)
  86. SummaryInputPosition as SummaryNotificationPosition, # noqa: TCH004 false positive (dynamic attribute)
  87. )
  88. from .addressing import (
  89. Address,
  90. IPv4Address,
  91. IPv6Address,
  92. )
  93. from .api import (
  94. Auth, # TODO: Validate naming for Auth compared to other drivers.
  95. )
  96. from .api import (
  97. AuthToken,
  98. basic_auth,
  99. bearer_auth,
  100. Bookmark,
  101. Bookmarks,
  102. custom_auth,
  103. DEFAULT_DATABASE,
  104. kerberos_auth,
  105. READ_ACCESS,
  106. ServerInfo,
  107. SYSTEM_DATABASE,
  108. TRUST_ALL_CERTIFICATES,
  109. TRUST_SYSTEM_CA_SIGNED_CERTIFICATES,
  110. Version,
  111. WRITE_ACCESS,
  112. )
  113. __all__ = [
  114. "DEFAULT_DATABASE",
  115. "READ_ACCESS",
  116. "SYSTEM_DATABASE",
  117. "TRUST_ALL_CERTIFICATES",
  118. "TRUST_SYSTEM_CA_SIGNED_CERTIFICATES",
  119. "WRITE_ACCESS",
  120. "Address",
  121. "AsyncBoltDriver",
  122. "AsyncDriver",
  123. "AsyncGraphDatabase",
  124. "AsyncManagedTransaction",
  125. "AsyncNeo4jDriver",
  126. "AsyncResult",
  127. "AsyncSession",
  128. "AsyncTransaction",
  129. "Auth",
  130. "AuthToken",
  131. "BoltDriver",
  132. "Bookmark",
  133. "Bookmarks",
  134. "Config", # noqa: F822 dynamic attribute
  135. "Driver",
  136. "EagerResult",
  137. "ExperimentalWarning",
  138. "GqlStatusObject",
  139. "GraphDatabase",
  140. "IPv4Address",
  141. "IPv6Address",
  142. "ManagedTransaction",
  143. "Neo4jDriver",
  144. "NotificationCategory",
  145. "NotificationClassification",
  146. "NotificationDisabledCategory",
  147. "NotificationDisabledClassification",
  148. "NotificationMinimumSeverity",
  149. "NotificationSeverity",
  150. "PoolConfig", # noqa: F822 dynamic attribute
  151. "PreviewWarning",
  152. "Query",
  153. "Record",
  154. "Result",
  155. "ResultSummary",
  156. "RoutingControl",
  157. "ServerInfo",
  158. "Session",
  159. "SessionConfig", # noqa: F822 dynamic attribute
  160. "SummaryCounters",
  161. "SummaryInputPosition",
  162. "SummaryNotification",
  163. "SummaryNotificationPosition",
  164. "Transaction",
  165. "TrustAll",
  166. "TrustCustomCAs",
  167. "TrustSystemCAs",
  168. "Version",
  169. "WorkspaceConfig", # noqa: F822 dynamic attribute
  170. "__version__",
  171. "basic_auth",
  172. "bearer_auth",
  173. "custom_auth",
  174. "get_user_agent",
  175. "kerberos_auth",
  176. "log", # noqa: F822 dynamic attribute
  177. "unit_of_work",
  178. ]
  179. _log = _getLogger("neo4j")
  180. def __getattr__(name) -> _t.Any:
  181. # TODO: 6.0 - remove this
  182. if name in {
  183. "log",
  184. "Config",
  185. "PoolConfig",
  186. "SessionConfig",
  187. "WorkspaceConfig",
  188. }:
  189. _deprecation_warn(
  190. f"Importing {name} from neo4j is deprecated without replacement. "
  191. "It's internal and will be removed in a future version.",
  192. stack_level=2,
  193. )
  194. return globals()[f"_{name}"]
  195. if name == "SummaryNotificationPosition":
  196. _deprecation_warn(
  197. "SummaryNotificationPosition is deprecated. "
  198. "Use SummaryInputPosition instead.",
  199. stack_level=2,
  200. )
  201. return SummaryInputPosition
  202. if name in {
  203. "NotificationClassification",
  204. "GqlStatusObject",
  205. "NotificationDisabledClassification",
  206. }:
  207. _preview_warn(
  208. f"{name} is part of GQLSTATUS support, "
  209. "which is a preview feature.",
  210. stack_level=2,
  211. )
  212. return globals()[f"_{name}"]
  213. raise AttributeError(f"module {__name__} has no attribute {name}")
  214. def __dir__() -> _t.List[str]:
  215. return __all__
  216. if _deprecated_package:
  217. _deprecation_warn(
  218. "The neo4j driver was installed under the package name `noe4j-driver` "
  219. "which is deprecated and will stop receiving updates starting with "
  220. "version 6.0.0. Please install `neo4j` instead (which is an alias, "
  221. "i.e., a drop-in replacement). See https://pypi.org/project/neo4j/ ."
  222. )