Skip to content

Commit a6d9050

Browse files
authored
Mature execute_query API (#911)
* Renaming `neo4j.RoutingControl.WRITERS` to `WRITE` and `READERS` to `READ`. * Renaming `driver.query_bookmark_manager()` to `execute_query_bookmark_manager()`. * Remove experimental tag from execute_query and its related APIs * `driver.execute_query` * `driver.execute_query_bookmark_manager` * `AsyncBookmarkManager`, `BookmarkManager`, the corresponding config option (session's `bookmark_manager`) and factory method (`driver.bookmark_manager()`) * `RoutingControl` enum * `EagerResult` and `result.to_eager_result()`
1 parent a2d7d33 commit a6d9050

29 files changed

+259
-498
lines changed

CHANGELOG.md

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

55
## NEXT RELEASE
6-
- ...
6+
- Renamed experimental `neo4j.RoutingControl.READERS` to `READ` and `WRITERS` to `WRITE`.
7+
- Renamed experimental `driver.query_bookmark_manager` to `execute_query_bookmark_manager`.
78

89

910
## Version 5.7

docs/source/api.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Closing a driver will immediately shut down all connections in the pool.
164164
verify_connectivity, get_server_info, verify_authentication,
165165
supports_session_auth, supports_multi_db
166166

167-
.. method:: execute_query(query, parameters_=None,routing_=neo4j.RoutingControl.WRITERS, database_=None, impersonated_user_=None, bookmark_manager_=self.query_bookmark_manager, result_transformer_=Result.to_eager_result, **kwargs)
167+
.. method:: execute_query(query, parameters_=None,routing_=neo4j.RoutingControl.WRITE, database_=None, impersonated_user_=None, bookmark_manager_=self.query_bookmark_manager, result_transformer_=Result.to_eager_result, **kwargs)
168168

169169
Execute a query in a transaction function and return all results.
170170

@@ -194,9 +194,9 @@ Closing a driver will immediately shut down all connections in the pool.
194194
bookmark_manager=bookmark_manager_,
195195
auth=auth_,
196196
) as session:
197-
if routing_ == RoutingControl.WRITERS:
197+
if routing_ == RoutingControl.WRITE:
198198
return session.execute_write(work)
199-
elif routing_ == RoutingControl.READERS:
199+
elif routing_ == RoutingControl.READ:
200200
return session.execute_read(work)
201201

202202
Usage example::
@@ -211,7 +211,7 @@ Closing a driver will immediately shut down all connections in the pool.
211211
records, summary, keys = driver.execute_query(
212212
"MATCH (p:Person {age: $age}) RETURN p.name",
213213
{"age": 42},
214-
routing_=neo4j.RoutingControl.READERS, # or just "r"
214+
routing_=neo4j.RoutingControl.READ, # or just "r"
215215
database_="neo4j",
216216
)
217217
assert keys == ["p.name"] # not needed, just for illustration
@@ -232,7 +232,7 @@ Closing a driver will immediately shut down all connections in the pool.
232232
"SET p.nickname = 'My dear' "
233233
"RETURN count(*)",
234234
# optional routing parameter, as write is default
235-
# routing_=neo4j.RoutingControl.WRITERS, # or just "w",
235+
# routing_=neo4j.RoutingControl.WRITE, # or just "w",
236236
database_="neo4j",
237237
result_transformer_=neo4j.Result.single,
238238
age=15,
@@ -380,7 +380,8 @@ Closing a driver will immediately shut down all connections in the pool.
380380
.. versionadded:: 5.5
381381

382382
.. versionchanged:: 5.8
383-
Added the ``auth_`` parameter.
383+
* Added the ``auth_`` parameter.
384+
* Stabilized from experimental.
384385

385386

386387
.. _driver-configuration-ref:
@@ -1022,8 +1023,7 @@ See :class:`.BookmarkManager` for more information.
10221023

10231024
.. versionadded:: 5.0
10241025

1025-
**This is experimental** (see :ref:`filter-warnings-ref`).
1026-
It might be changed or removed any time even without prior notice.
1026+
.. versionchanged:: 5.8 stabilized from experimental
10271027

10281028

10291029
.. _session-auth-ref:

docs/source/async_api.rst

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Closing a driver will immediately shut down all connections in the pool.
153153
verify_connectivity, get_server_info, verify_authentication,
154154
supports_session_auth, supports_multi_db
155155

156-
.. method:: execute_query(query, parameters_=None, routing_=neo4j.RoutingControl.WRITERS, database_=None, impersonated_user_=None, bookmark_manager_=self.query_bookmark_manager, result_transformer_=AsyncResult.to_eager_result, **kwargs)
156+
.. method:: execute_query(query, parameters_=None, routing_=neo4j.RoutingControl.WRITE, database_=None, impersonated_user_=None, bookmark_manager_=self.query_bookmark_manager, result_transformer_=AsyncResult.to_eager_result, **kwargs)
157157
:async:
158158

159159
Execute a query in a transaction function and return all results.
@@ -184,9 +184,9 @@ Closing a driver will immediately shut down all connections in the pool.
184184
bookmark_manager=bookmark_manager_,
185185
auth=auth_,
186186
) as session:
187-
if routing_ == RoutingControl.WRITERS:
187+
if routing_ == RoutingControl.WRITE:
188188
return await session.execute_write(work)
189-
elif routing_ == RoutingControl.READERS:
189+
elif routing_ == RoutingControl.READ:
190190
return await session.execute_read(work)
191191

192192
Usage example::
@@ -201,7 +201,7 @@ Closing a driver will immediately shut down all connections in the pool.
201201
records, summary, keys = await driver.execute_query(
202202
"MATCH (p:Person {age: $age}) RETURN p.name",
203203
{"age": 42},
204-
routing_=neo4j.RoutingControl.READERS, # or just "r"
204+
routing_=neo4j.RoutingControl.READ, # or just "r"
205205
database_="neo4j",
206206
)
207207
assert keys == ["p.name"] # not needed, just for illustration
@@ -222,7 +222,7 @@ Closing a driver will immediately shut down all connections in the pool.
222222
"SET p.nickname = 'My dear' "
223223
"RETURN count(*)",
224224
# optional routing parameter, as write is default
225-
# routing_=neo4j.RoutingControl.WRITERS, # or just "w",
225+
# routing_=neo4j.RoutingControl.WRITE, # or just "w",
226226
database_="neo4j",
227227
result_transformer_=neo4j.AsyncResult.single,
228228
age=15,
@@ -360,17 +360,11 @@ Closing a driver will immediately shut down all connections in the pool.
360360
:returns: the result of the ``result_transformer``
361361
:rtype: T
362362

363-
**This is experimental** (see :ref:`filter-warnings-ref`).
364-
It might be changed or removed any time even without prior notice.
365-
366-
We are looking for feedback on this feature. Please let us know what
367-
you think about it here:
368-
https://github.com/neo4j/neo4j-python-driver/discussions/896
369-
370363
.. versionadded:: 5.5
371364

372365
.. versionchanged:: 5.8
373-
Added the ``auth_`` parameter.
366+
* Added the ``auth_`` parameter.
367+
* Stabilized from experimental.
374368

375369

376370
.. _async-driver-configuration-ref:
@@ -659,8 +653,7 @@ See :class:`BookmarkManager` for more information.
659653
:Type: :data:`None`, :class:`BookmarkManager`, or :class:`AsyncBookmarkManager`
660654
:Default: :data:`None`
661655

662-
**This is experimental** (see :ref:`filter-warnings-ref`).
663-
It might be changed or removed any time even without prior notice.
656+
.. versionchanged:: 5.8 stabilized from experimental
664657

665658

666659

src/neo4j/_api.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,22 @@ class RoutingControl(str, Enum):
208208
Inherits from :class:`str` and :class:`Enum`. Every driver API accepting a
209209
:class:`.RoutingControl` value will also accept a string
210210
211-
>>> RoutingControl.READERS == "r"
211+
>>> RoutingControl.READ == "r"
212212
True
213-
>>> RoutingControl.WRITERS == "w"
213+
>>> RoutingControl.WRITE == "w"
214214
True
215215
216-
**This is experimental.**
217-
It might be changed or removed any time even without prior notice.
218-
219216
.. seealso::
220217
:attr:`.AsyncDriver.execute_query`, :attr:`.Driver.execute_query`
221218
222219
.. versionadded:: 5.5
220+
221+
.. versionchanged:: 5.8
222+
* renamed ``READERS`` to ``READ`` and ``WRITERS`` to ``WRITE``
223+
* stabilized from experimental
223224
"""
224-
READERS = "r"
225-
WRITERS = "w"
225+
READ = "r"
226+
WRITE = "w"
226227

227228

228229
if t.TYPE_CHECKING:

src/neo4j/_async/auth_management.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# work around for https://github.com/sphinx-doc/sphinx/pull/10880
2121
# make sure TAuth is resolved in the docs, else they're pretty useless
2222

23+
2324
import time
2425
import typing as t
2526
from logging import getLogger

src/neo4j/_async/driver.py

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@
4444
)
4545
from .._meta import (
4646
deprecation_warn,
47-
experimental,
4847
experimental_warn,
49-
ExperimentalWarning,
5048
preview,
5149
preview_warn,
5250
PreviewWarning,
@@ -293,10 +291,6 @@ def driver(
293291
routing_context=routing_context, **config)
294292

295293
@classmethod
296-
@experimental(
297-
"The bookmark manager feature is experimental. "
298-
"It might be changed or removed any time even without prior notice."
299-
)
300294
def bookmark_manager(
301295
cls,
302296
initial_bookmarks: t.Union[None, Bookmarks, t.Iterable[str]] = None,
@@ -357,9 +351,6 @@ def bookmark_manager(
357351
358352
:returns: A default implementation of :class:`AsyncBookmarkManager`.
359353
360-
**This is experimental** (see :ref:`filter-warnings-ref`).
361-
It might be changed or removed any time even without prior notice.
362-
363354
.. versionadded:: 5.0
364355
365356
.. versionchanged:: 5.3
@@ -373,6 +364,8 @@ def bookmark_manager(
373364
an argument.
374365
* ``bookmarks_consumer`` no longer receives the database name as
375366
an argument.
367+
368+
.. versionchanged:: 5.8 stabilized from experimental
376369
"""
377370
return AsyncNeo4jBookmarkManager(
378371
initial_bookmarks=initial_bookmarks,
@@ -480,12 +473,7 @@ def __init__(self, pool, default_workspace_config):
480473
assert default_workspace_config is not None
481474
self._pool = pool
482475
self._default_workspace_config = default_workspace_config
483-
with warnings.catch_warnings():
484-
warnings.filterwarnings("ignore",
485-
message=r".*\bbookmark manager\b.*",
486-
category=ExperimentalWarning)
487-
self._query_bookmark_manager = \
488-
AsyncGraphDatabase.bookmark_manager()
476+
self._query_bookmark_manager = AsyncGraphDatabase.bookmark_manager()
489477

490478
async def __aenter__(self) -> AsyncDriver:
491479
return self
@@ -579,7 +567,7 @@ async def execute_query(
579567
self,
580568
query_: str,
581569
parameters_: t.Optional[t.Dict[str, t.Any]] = None,
582-
routing_: T_RoutingControl = RoutingControl.WRITERS,
570+
routing_: T_RoutingControl = RoutingControl.WRITE,
583571
database_: t.Optional[str] = None,
584572
impersonated_user_: t.Optional[str] = None,
585573
bookmark_manager_: t.Union[
@@ -598,7 +586,7 @@ async def execute_query(
598586
self,
599587
query_: str,
600588
parameters_: t.Optional[t.Dict[str, t.Any]] = None,
601-
routing_: T_RoutingControl = RoutingControl.WRITERS,
589+
routing_: T_RoutingControl = RoutingControl.WRITE,
602590
database_: t.Optional[str] = None,
603591
impersonated_user_: t.Optional[str] = None,
604592
bookmark_manager_: t.Union[
@@ -612,15 +600,11 @@ async def execute_query(
612600
) -> _T:
613601
...
614602

615-
@experimental(
616-
"Driver.execute_query is experimental. "
617-
"It might be changed or removed any time even without prior notice."
618-
)
619603
async def execute_query(
620604
self,
621605
query_: str,
622606
parameters_: t.Optional[t.Dict[str, t.Any]] = None,
623-
routing_: T_RoutingControl = RoutingControl.WRITERS,
607+
routing_: T_RoutingControl = RoutingControl.WRITE,
624608
database_: t.Optional[str] = None,
625609
impersonated_user_: t.Optional[str] = None,
626610
bookmark_manager_: t.Union[
@@ -661,9 +645,9 @@ async def work(tx):
661645
bookmark_manager=bookmark_manager_,
662646
auth=auth_,
663647
) as session:
664-
if routing_ == RoutingControl.WRITERS:
648+
if routing_ == RoutingControl.WRITE:
665649
return await session.execute_write(work)
666-
elif routing_ == RoutingControl.READERS:
650+
elif routing_ == RoutingControl.READ:
667651
return await session.execute_read(work)
668652
669653
Usage example::
@@ -678,7 +662,7 @@ async def example(driver: neo4j.AsyncDriver) -> List[str]:
678662
records, summary, keys = await driver.execute_query(
679663
"MATCH (p:Person {age: $age}) RETURN p.name",
680664
{"age": 42},
681-
routing_=neo4j.RoutingControl.READERS, # or just "r"
665+
routing_=neo4j.RoutingControl.READ, # or just "r"
682666
database_="neo4j",
683667
)
684668
assert keys == ["p.name"] # not needed, just for illustration
@@ -699,7 +683,7 @@ async def example(driver: neo4j.AsyncDriver) -> int:
699683
"SET p.nickname = 'My dear' "
700684
"RETURN count(*)",
701685
# optional routing parameter, as write is default
702-
# routing_=neo4j.RoutingControl.WRITERS, # or just "w",
686+
# routing_=neo4j.RoutingControl.WRITE, # or just "w",
703687
database_="neo4j",
704688
result_transformer_=neo4j.AsyncResult.single,
705689
age=15,
@@ -837,17 +821,11 @@ async def example(driver: neo4j.AsyncDriver) -> neo4j.Record::
837821
:returns: the result of the ``result_transformer``
838822
:rtype: T
839823
840-
**This is experimental** (see :ref:`filter-warnings-ref`).
841-
It might be changed or removed any time even without prior notice.
842-
843-
We are looking for feedback on this feature. Please let us know what
844-
you think about it here:
845-
https://github.com/neo4j/neo4j-python-driver/discussions/896
846-
847824
.. versionadded:: 5.5
848825
849826
.. versionchanged:: 5.8
850-
Added the ``auth_`` parameter.
827+
* Added the ``auth_`` parameter.
828+
* Stabilized from experimental.
851829
"""
852830
invalid_kwargs = [k for k in kwargs if
853831
k[-2:-1] != "_" and k[-1:] == "_"]
@@ -866,9 +844,6 @@ async def example(driver: neo4j.AsyncDriver) -> neo4j.Record::
866844
assert bookmark_manager_ is not _default
867845

868846
with warnings.catch_warnings():
869-
warnings.filterwarnings("ignore",
870-
message=r".*\bbookmark_manager\b.*",
871-
category=ExperimentalWarning)
872847
warnings.filterwarnings("ignore",
873848
message=r"^User switching\b.*",
874849
category=PreviewWarning)
@@ -877,9 +852,9 @@ async def example(driver: neo4j.AsyncDriver) -> neo4j.Record::
877852
bookmark_manager=bookmark_manager_,
878853
auth=auth_)
879854
async with session:
880-
if routing_ == RoutingControl.WRITERS:
855+
if routing_ == RoutingControl.WRITE:
881856
executor = session.execute_write
882-
elif routing_ == RoutingControl.READERS:
857+
elif routing_ == RoutingControl.READ:
883858
executor = session.execute_read
884859
else:
885860
raise ValueError("Invalid routing control value: %r"
@@ -889,11 +864,7 @@ async def example(driver: neo4j.AsyncDriver) -> neo4j.Record::
889864
)
890865

891866
@property
892-
@experimental(
893-
"Driver.query_bookmark_manager is experimental. "
894-
"It might be changed or removed any time even without prior notice."
895-
)
896-
def query_bookmark_manager(self) -> AsyncBookmarkManager:
867+
def execute_query_bookmark_manager(self) -> AsyncBookmarkManager:
897868
"""The driver's default query bookmark manager.
898869
899870
This is the default :class:`AsyncBookmarkManager` used by
@@ -912,10 +883,12 @@ async def example(driver: neo4j.AsyncDriver) -> None:
912883
# (i.e., can read what was written by <QUERY 2>)
913884
await driver.execute_query("<QUERY 3>")
914885
915-
**This is experimental** (see :ref:`filter-warnings-ref`).
916-
It might be changed or removed any time even without prior notice.
917-
918886
.. versionadded:: 5.5
887+
888+
.. versionchanged:: 5.8
889+
* Renamed from ``query_bookmark_manager`` to
890+
``execute_query_bookmark_manager``.
891+
* Stabilized from experimental.
919892
"""
920893
return self._query_bookmark_manager
921894

@@ -1212,11 +1185,7 @@ async def _work(
12121185
) -> _T:
12131186
res = await tx.run(query, parameters)
12141187
if transformer is AsyncResult.to_eager_result:
1215-
with warnings.catch_warnings():
1216-
warnings.filterwarnings("ignore",
1217-
message=r".*\bto_eager_result\b.*",
1218-
category=ExperimentalWarning)
1219-
return await transformer(res)
1188+
return await transformer(res)
12201189
return await transformer(res)
12211190

12221191

0 commit comments

Comments
 (0)