Skip to content

Commit 721a0f2

Browse files
authored
Notifications api (#847)
* Make `neo4j.work` internal * ADR 009: Implement notification filters (Bolt 5.2) * Add tests to make sure credentials aren't logged * Add basic Bolt 5.1 (LOGON after HELLO) support
1 parent 6e8457b commit 721a0f2

File tree

87 files changed

+6115
-723
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+6115
-723
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
See also https://github.com/neo4j/neo4j-python-driver/wiki for more details.
44

55
## NEXT RELEASE
6+
- Deprecated importing from `neo4j.work` and its submodules. Everything should be imported directly from `neo4j` instead.
67
- ...
78

89

bin/make-unasync

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def apply_unasync(files):
223223
"assert_awaited_once": "assert_called_once",
224224
"assert_awaited_once_with": "assert_called_once_with",
225225
"await_count": "call_count",
226+
"AsyncMock": "MagicMock",
226227
}
227228
additional_testkit_backend_replacements = {}
228229
rules = [

docs/source/api.rst

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ Additional configuration can be provided via the :class:`neo4j.Driver` construct
377377
+ :ref:`ssl-context-ref`
378378
+ :ref:`trusted-certificates-ref`
379379
+ :ref:`user-agent-ref`
380+
+ :ref:`driver-notifications-min-severity-ref`
381+
+ :ref:`driver-notifications-disabled-categories-ref`
380382

381383

382384
.. _connection-acquisition-timeout-ref:
@@ -596,6 +598,49 @@ Specify the client agent name.
596598
:Default: *The Python Driver will generate a user agent name.*
597599

598600

601+
.. _driver-notifications-min-severity-ref:
602+
603+
``notifications_min_severity``
604+
------------------------------
605+
Set the minimum severity for notifications the server should send to the client.
606+
607+
Notifications are available via :attr:`.ResultSummary.notifications` and :attr:`.ResultSummary.summary_notifications`.
608+
609+
:data:`None` will apply the server's default setting.
610+
611+
.. Note::
612+
If configured, the server or all servers of the cluster need to support notifications filtering.
613+
Otherwise, the driver will raise a :exc:`.ConfigurationError` as soon as it encounters a server that does not.
614+
615+
:Type: :data:`None`, :class:`.NotificationMinimumSeverity`, or :class:`str`
616+
:Default: :data:`None`
617+
618+
.. versionadded:: 5.7
619+
620+
.. seealso:: :class:`.NotificationMinimumSeverity`, session config :ref:`session-notifications-min-severity-ref`
621+
622+
623+
.. _driver-notifications-disabled-categories-ref:
624+
625+
``notifications_disabled_categories``
626+
-------------------------------------
627+
Set categories of notifications the server should not send to the client.
628+
629+
Notifications are available via :attr:`.ResultSummary.notifications` and :attr:`.ResultSummary.summary_notifications`.
630+
631+
:data:`None` will apply the server's default setting.
632+
633+
.. Note::
634+
If configured, the server or all servers of the cluster need to support notifications filtering.
635+
Otherwise, the driver will raise a :exc:`.ConfigurationError` as soon as it encounters a server that does not.
636+
637+
:Type: :data:`None`, :term:`iterable` of :class:`.NotificationDisabledCategory` and/or :class:`str`
638+
:Default: :data:`None`
639+
640+
.. versionadded:: 5.7
641+
642+
.. seealso:: :class:`.NotificationDisabledCategory`, session config :ref:`session-notifications-disabled-categories-ref`
643+
599644

600645
Driver Object Lifetime
601646
======================
@@ -759,6 +804,8 @@ To construct a :class:`neo4j.Session` use the :meth:`neo4j.Driver.session` metho
759804
+ :ref:`default-access-mode-ref`
760805
+ :ref:`fetch-size-ref`
761806
+ :ref:`bookmark-manager-ref`
807+
+ :ref:`session-notifications-min-severity-ref`
808+
+ :ref:`session-notifications-disabled-categories-ref`
762809

763810

764811
.. _bookmarks-ref:
@@ -858,7 +905,7 @@ context of the impersonated user. For this, the user for which the
858905

859906
.. Note::
860907

861-
The server or all servers of the cluster need to support impersonation.
908+
If configured, the server or all servers of the cluster need to support impersonation.
862909
Otherwise, the driver will raise :exc:`.ConfigurationError`
863910
as soon as it encounters a server that does not.
864911

@@ -952,6 +999,49 @@ See :class:`.BookmarkManager` for more information.
952999
It might be changed or removed any time even without prior notice.
9531000

9541001

1002+
.. _session-notifications-min-severity-ref:
1003+
1004+
``notifications_min_severity``
1005+
------------------------------
1006+
Set the minimum severity for notifications the server should send to the client.
1007+
1008+
Notifications are available via :attr:`.ResultSummary.notifications` and :attr:`.ResultSummary.summary_notifications`.
1009+
1010+
:data:`None` will apply the driver's configuration setting (:ref:`driver-notifications-min-severity-ref`).
1011+
1012+
.. Note::
1013+
If configured, the server or all servers of the cluster need to support notifications filtering.
1014+
Otherwise, the driver will raise a :exc:`.ConfigurationError` as soon as it encounters a server that does not.
1015+
1016+
:Type: :data:`None`, :class:`.NotificationMinimumSeverity`, or :class:`str`
1017+
:Default: :data:`None`
1018+
1019+
.. versionadded:: 5.7
1020+
1021+
.. seealso:: :class:`.NotificationMinimumSeverity`
1022+
1023+
1024+
.. _session-notifications-disabled-categories-ref:
1025+
1026+
``notifications_disabled_categories``
1027+
-------------------------------------
1028+
Set categories of notifications the server should not send to the client.
1029+
1030+
Notifications are available via :attr:`.ResultSummary.notifications` and :attr:`.ResultSummary.summary_notifications`.
1031+
1032+
:data:`None` will apply the driver's configuration setting (:ref:`driver-notifications-min-severity-ref`).
1033+
1034+
.. Note::
1035+
If configured, the server or all servers of the cluster need to support notifications filtering.
1036+
Otherwise, the driver will raise a :exc:`.ConfigurationError` as soon as it encounters a server that does not.
1037+
1038+
:Type: :data:`None`, :term:`iterable` of :class:`.NotificationDisabledCategory` and/or :class:`str`
1039+
:Default: :data:`None`
1040+
1041+
.. versionadded:: 5.7
1042+
1043+
.. seealso:: :class:`.NotificationDisabledCategory`
1044+
9551045

9561046

9571047
***********
@@ -1288,6 +1378,34 @@ ServerInfo
12881378
:members:
12891379

12901380

1381+
SummaryNotification
1382+
===================
1383+
1384+
.. autoclass:: neo4j.SummaryNotification()
1385+
:members:
1386+
1387+
1388+
NotificationSeverity
1389+
--------------------
1390+
1391+
.. autoclass:: neo4j.NotificationSeverity()
1392+
:members:
1393+
1394+
1395+
NotificationCategory
1396+
--------------------
1397+
1398+
.. autoclass:: neo4j.NotificationCategory()
1399+
:members:
1400+
1401+
1402+
SummaryNotificationPosition
1403+
---------------------------
1404+
1405+
.. autoclass:: neo4j.SummaryNotificationPosition()
1406+
:members:
1407+
1408+
12911409

12921410
***************
12931411
Core Data Types
@@ -1583,6 +1701,14 @@ BookmarkManager
15831701
Constants, Enums, Helpers
15841702
*************************
15851703

1704+
.. autoclass:: neo4j.NotificationMinimumSeverity
1705+
:show-inheritance:
1706+
:members:
1707+
1708+
.. autoclass:: neo4j.NotificationDisabledCategory
1709+
:show-inheritance:
1710+
:members:
1711+
15861712
.. autoclass:: neo4j.RoutingControl
15871713
:show-inheritance:
15881714
:members:

src/neo4j/__init__.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818

1919
from logging import getLogger as _getLogger
2020

21-
from ._api import RoutingControl
21+
from ._api import (
22+
NotificationCategory,
23+
NotificationDisabledCategory,
24+
NotificationMinimumSeverity,
25+
NotificationSeverity,
26+
RoutingControl,
27+
)
2228
from ._async.driver import (
2329
AsyncBoltDriver,
2430
AsyncDriver,
@@ -60,7 +66,15 @@
6066
Session,
6167
Transaction,
6268
)
63-
from ._work import EagerResult
69+
from ._work import (
70+
EagerResult,
71+
Query,
72+
ResultSummary,
73+
SummaryCounters,
74+
SummaryNotification,
75+
SummaryNotificationPosition,
76+
unit_of_work,
77+
)
6478
from .addressing import (
6579
Address,
6680
IPv4Address,
@@ -86,12 +100,6 @@
86100
Version,
87101
WRITE_ACCESS,
88102
)
89-
from .work import (
90-
Query,
91-
ResultSummary,
92-
SummaryCounters,
93-
unit_of_work,
94-
)
95103

96104

97105
__all__ = [
@@ -115,6 +123,7 @@
115123
"Config",
116124
"custom_auth",
117125
"DEFAULT_DATABASE",
126+
"NotificationDisabledCategory",
118127
"Driver",
119128
"EagerResult",
120129
"ExperimentalWarning",
@@ -125,7 +134,11 @@
125134
"kerberos_auth",
126135
"log",
127136
"ManagedTransaction",
137+
"NotificationMinimumSeverity",
128138
"Neo4jDriver",
139+
"NotificationCategory",
140+
"NotificationFilter",
141+
"NotificationSeverity",
129142
"PoolConfig",
130143
"Query",
131144
"READ_ACCESS",
@@ -137,6 +150,8 @@
137150
"Session",
138151
"SessionConfig",
139152
"SummaryCounters",
153+
"SummaryNotification",
154+
"SummaryNotificationPosition",
140155
"Transaction",
141156
"TRUST_ALL_CERTIFICATES",
142157
"TRUST_SYSTEM_CA_SIGNED_CERTIFICATES",

0 commit comments

Comments
 (0)