Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications api #847

Merged
merged 18 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Neo4j Driver Change Log (breaking/major changes only)

## Version 5.x
robsdedude marked this conversation as resolved.
Show resolved Hide resolved

* Deprecated importing from `neo4j.work` and its submodules. Everything should be imported directly from `neo4j` instead.


## Version 5.2

- No breaking or major changes.
Expand Down
1 change: 1 addition & 0 deletions bin/make-unasync
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def apply_unasync(files):
"assert_awaited_once": "assert_called_once",
"assert_awaited_once_with": "assert_called_once_with",
"await_count": "call_count",
"AsyncMock": "MagicMock",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did MagicMock come from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the mocking library has Mock and MagicMock which behave the same except that the latter also mock magic methods (__xyz__ shaped methods). AsyncMock does always mock magic methods as well (I suppose it has to, to be able to intercept calls to __await__, but that is speculation). Either way, by default the unasync script would turn AsyncMock into Mock which brakes tests that rely on magic methods being mocked.

}
additional_testkit_backend_replacements = {}
rules = [
Expand Down
69 changes: 69 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ Additional configuration can be provided via the :class:`neo4j.Driver` construct
+ :ref:`ssl-context-ref`
+ :ref:`trusted-certificates-ref`
+ :ref:`user-agent-ref`
+ :ref:`driver-notification-filters-ref`


.. _connection-acquisition-timeout-ref:
Expand Down Expand Up @@ -370,6 +371,25 @@ Specify the client agent name.
:Default: *The Python Driver will generate a user agent name.*


.. _driver-notification-filters-ref:

``notification_filters``
------------------------
Set filters for which notifications the server should send to the client.

This can be a single or an iterable of :class:`.NotificationFilter` object(s) or
equivalent string(s) (see :class:`.NotificationFilter`).
Alternatively, :const:`None` can be used to indicate
:attr:`NotificationFilter.DEFAULT`.

:Type: :const:`None`, :class:`.NotificationFilter`, :class:`str`, or iterable of either
:Default: :const:`None`

.. versionadded:: 5.2
robsdedude marked this conversation as resolved.
Show resolved Hide resolved

.. seealso:: :class:`.NotificationFilter`, :ref:`session-configuration-ref`



Driver Object Lifetime
======================
Expand Down Expand Up @@ -530,6 +550,7 @@ To construct a :class:`neo4j.Session` use the :meth:`neo4j.Driver.session` metho
+ :ref:`default-access-mode-ref`
+ :ref:`fetch-size-ref`
+ :ref:`bookmark-manager-ref`
+ :ref:`session-notification-filters-ref`


.. _bookmarks-ref:
Expand Down Expand Up @@ -685,6 +706,24 @@ See :class:`.BookmarkManager` for more information.
It might be changed or removed any time even without prior notice.


.. _session-notification-filters-ref:

``notification_filters``
------------------------
Set filters for which notifications the server should send to the client.

This can be a single or an iterable of :class:`.NotificationFilter` object(s) or
equivalent string(s) (see :class:`.NotificationFilter`).
Alternatively, :const:`None` can be used fall back to the filters configured on
the driver (see :ref:`driver-notification-filters-ref`).

:Type: :const:`None`, :class:`.NotificationFilter`, :class:`str`, or iterable of either
:Default: :const:`None`

.. versionadded:: 5.2
robsdedude marked this conversation as resolved.
Show resolved Hide resolved

.. seealso:: :class:`.NotificationFilter`, :ref:`driver-configuration-ref`



***********
Expand Down Expand Up @@ -976,6 +1015,27 @@ ServerInfo
:members:


SummaryNotification
===================

.. autoclass:: neo4j.SummaryNotification()
:members:


NotificationSeverity
--------------------

.. autoclass:: neo4j.NotificationSeverity()
:members:


NotificationCategory
--------------------

.. autoclass:: neo4j.NotificationCategory()
:members:



***************
Core Data Types
Expand Down Expand Up @@ -1216,6 +1276,15 @@ BookmarkManager
:members:


*************************
Constants, Enums, Helpers
*************************

.. autoclass:: neo4j.NotificationFilter
:show-inheritance:
:members:


.. _errors-ref:

******
Expand Down
22 changes: 16 additions & 6 deletions neo4j/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

from logging import getLogger as _getLogger

from ._api import (
NotificationCategory,
NotificationFilter,
NotificationSeverity,
)
from ._async.driver import (
AsyncBoltDriver,
AsyncDriver,
Expand Down Expand Up @@ -57,6 +62,13 @@
Session,
Transaction,
)
from ._work import (
Query,
ResultSummary,
SummaryCounters,
SummaryNotification,
unit_of_work,
)
from .addressing import (
Address,
IPv4Address,
Expand All @@ -82,12 +94,6 @@
Version,
WRITE_ACCESS,
)
from .work import (
Query,
ResultSummary,
SummaryCounters,
unit_of_work,
)


__all__ = [
Expand Down Expand Up @@ -121,6 +127,9 @@
"log",
"ManagedTransaction",
"Neo4jDriver",
"NotificationCategory",
"NotificationFilter",
"NotificationSeverity",
"PoolConfig",
"Query",
"READ_ACCESS",
Expand All @@ -131,6 +140,7 @@
"Session",
"SessionConfig",
"SummaryCounters",
"SummaryNotification",
"Transaction",
"TRUST_ALL_CERTIFICATES",
"TRUST_SYSTEM_CA_SIGNED_CERTIFICATES",
Expand Down
145 changes: 145 additions & 0 deletions neo4j/_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Copyright (c) "Neo4j"
# Neo4j Sweden AB [https://neo4j.com]
#
# This file is part of Neo4j.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from __future__ import annotations

import typing as t
from enum import Enum


if t.TYPE_CHECKING:
import typing_extensions as te


__all__ = [
"NotificationCategory",
"NotificationFilter",
"NotificationSeverity",
]


class NotificationFilter(str, Enum):
"""A filter criterion for which notifications the server should return.

Inherits from :class:`str` and :class:`Enum`. Hence, every driver API
accepting a :class:`.NotificationFilter` value will also accept a string::

True
>>> NONE == "NONE"
True
>>> DEFAULT == "DEFAULT"
True
>>> ALL_ALL == "*.*"
True
>>> ALL_QUERY == "*.QUERY"
True
>>> WARNING_ALL == "WARNING.*"
True
>>> WARNING_DEPRECATION == "WARNING.DEPRECATION"
True
>>> WARNING_HINT == "WARNING.HINT"
True
>>> WARNING_QUERY == "WARNING.QUERY"
True
>>> WARNING_UNSUPPORTED == "WARNING.UNSUPPORTED"
True
>>> INFORMATION_ALL == "INFORMATION.*"
True
>>> INFORMATION_RUNTIME == "INFORMATION.RUNTIME"
True
>>> INFORMATION_QUERY == "INFORMATION.QUERY"
True
>>> INFORMATION_PERFORMANCE == "INFORMATION.PERFORMANCE"
True

:attr:`NONE` instructs the server to not send any notifications.
:attr:`DEFAULT` leaves it up to the server which notifications to send.

The other choices are a combination of a severity and a category.

.. versionadded:: 5.2
robsdedude marked this conversation as resolved.
Show resolved Hide resolved

.. seealso::
:ref:`driver-configuration-ref`, :ref:`session-configuration-ref`
"""
NONE = "NONE"
DEFAULT = "DEFAULT"
ALL_ALL = "*.*"
ALL_QUERY = "*.QUERY"
WARNING_ALL = "WARNING.*"
WARNING_DEPRECATION = "WARNING.DEPRECATION"
WARNING_HINT = "WARNING.HINT"
WARNING_QUERY = "WARNING.QUERY"
WARNING_UNSUPPORTED = "WARNING.UNSUPPORTED"
INFORMATION_ALL = "INFORMATION.*"
INFORMATION_RUNTIME = "INFORMATION.RUNTIME"
INFORMATION_QUERY = "INFORMATION.QUERY"
INFORMATION_PERFORMANCE = "INFORMATION.PERFORMANCE"


if t.TYPE_CHECKING:
T_NotificationFilter = t.Union[
NotificationFilter,
te.Literal[
"NONE",
"DEFAULT",
"*.*",
"*.QUERY",
"WARNING.*",
"WARNING.DEPRECATION",
"WARNING.HINT",
"WARNING.QUERY",
"WARNING.UNSUPPORTED",
"INFORMATION.*",
"INFORMATION.RUNTIME",
"INFORMATION.QUERY",
"INFORMATION.PERFORMANCE",
],
]


class NotificationSeverity(Enum):
"""Server-side notification severity.

.. versionadded:: 5.2
robsdedude marked this conversation as resolved.
Show resolved Hide resolved

.. seealso:: :class:`SummaryNotification.severity_level`
"""

WARNING = "WARNING"
INFORMATION = "INFORMATION"
#: Used when server provides a Severity which the driver is unaware of.
UNKNOWN = "UNKNOWN"


class NotificationCategory(Enum):
"""Server-side notification category.

.. versionadded:: 5.2
robsdedude marked this conversation as resolved.
Show resolved Hide resolved

.. seealso:: :class:`SummaryNotification.category`
"""

HINT = "HINT"
QUERY = "QUERY"
UNSUPPORTED = "UNSUPPORTED"
PERFORMANCE = "PERFORMANCE"
DEPRECATION = "DEPRECATION"
RUNTIME = "RUNTIME"
#: Used when server provides a Category which the driver is unaware of.
UNKNOWN = "UNKNOWN"
Loading