Skip to content

Version bumping for 5.0 #627

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

Merged
merged 3 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Neo4j Driver Change Log

## Version 5.0

- Python 3.10 support added
- Python 3.6 support has been dropped.


## Version 4.4

- Python 3.5 support has been dropped.
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ This repository contains the official Neo4j driver for Python.
Each driver release (from 4.0 upwards) is built specifically to work with a corresponding Neo4j release, i.e. that with the same `major.minor` version number.
These drivers will also be compatible with the previous Neo4j release, although new server features will not be available.

+ Python 3.10 supported.
+ Python 3.9 supported.
+ Python 3.8 supported.
+ Python 3.7 supported.
+ Python 3.6 supported.

Python 2.7 support has been dropped as of the Neo4j 4.0 release.

Expand Down
2 changes: 1 addition & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Neo4j Driver Testing

To run driver tests, [Tox](https://tox.readthedocs.io) is required as well as at least one version of Python.
The versions of Python supported by this driver are CPython 3.6, 3.7, 3.8, and 3.9.
The versions of Python supported by this driver are CPython 3.7, 3.8, 3.9, and 3.10.


## Unit Tests & Stub Tests
Expand Down
9 changes: 2 additions & 7 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@ The Official Neo4j Driver for Python.

Neo4j versions supported:

* Neo4j 5.0
* Neo4j 4.4
* Neo4j 4.3
* Neo4j 3.5

Python versions supported:

* Python 3.10
* Python 3.9
* Python 3.8
* Python 3.7
* Python 3.6

.. note::

The `Python Driver 1.7`_ supports older versions of python, **Neo4j 4.1** will work in fallback mode with that driver.


******
Expand Down
281 changes: 281 additions & 0 deletions neo4j/_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
# Copyright (c) "Neo4j"
# Neo4j Sweden AB [http://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
#
# http://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 .addressing import Address
from .api import READ_ACCESS
from .conf import (
Config,
PoolConfig,
SessionConfig,
WorkspaceConfig,
)
from .meta import experimental
from .work.simple import Session


class Direct:

default_host = "localhost"
default_port = 7687

default_target = ":"

def __init__(self, address):
self._address = address

@property
def address(self):
return self._address

@classmethod
def parse_target(cls, target):
""" Parse a target string to produce an address.
"""
if not target:
target = cls.default_target
address = Address.parse(target, default_host=cls.default_host,
default_port=cls.default_port)
return address


class Routing:

default_host = "localhost"
default_port = 7687

default_targets = ": :17601 :17687"

def __init__(self, initial_addresses):
self._initial_addresses = initial_addresses

@property
def initial_addresses(self):
return self._initial_addresses

@classmethod
def parse_targets(cls, *targets):
""" Parse a sequence of target strings to produce an address
list.
"""
targets = " ".join(targets)
if not targets:
targets = cls.default_targets
addresses = Address.parse_list(targets, default_host=cls.default_host, default_port=cls.default_port)
return addresses


class Driver:
""" Base class for all types of :class:`neo4j.Driver`, instances of which are
used as the primary access point to Neo4j.
"""

#: Connection pool
_pool = None

def __init__(self, pool):
assert pool is not None
self._pool = pool

def __del__(self):
self.close()

def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
self.close()

@property
def encrypted(self):
return bool(self._pool.pool_config.encrypted)

def session(self, **config):
"""Create a session, see :ref:`session-construction-ref`

:param config: session configuration key-word arguments, see :ref:`session-configuration-ref` for available key-word arguments.

:returns: new :class:`neo4j.Session` object
"""
raise NotImplementedError

@experimental("The pipeline API is experimental and may be removed or changed in a future release")
def pipeline(self, **config):
""" Create a pipeline.
"""
raise NotImplementedError

def close(self):
""" Shut down, closing any open connections in the pool.
"""
self._pool.close()

@experimental("The configuration may change in the future.")
def verify_connectivity(self, **config):
""" This verifies if the driver can connect to a remote server or a cluster
by establishing a network connection with the remote and possibly exchanging
a few data before closing the connection. It throws exception if fails to connect.

Use the exception to further understand the cause of the connectivity problem.

Note: Even if this method throws an exception, the driver still need to be closed via close() to free up all resources.
"""
raise NotImplementedError

@experimental("Feature support query, based on Bolt Protocol Version and Neo4j Server Version will change in the future.")
def supports_multi_db(self):
""" Check if the server or cluster supports multi-databases.

:return: Returns true if the server or cluster the driver connects to supports multi-databases, otherwise false.
:rtype: bool
"""
with self.session() as session:
session._connect(READ_ACCESS)
return session._connection.supports_multiple_databases


class BoltDriver(Direct, Driver):
""" A :class:`.BoltDriver` is created from a ``bolt`` URI and addresses
a single database machine. This may be a standalone server or could be a
specific member of a cluster.

Connections established by a :class:`.BoltDriver` are always made to the
exact host and port detailed in the URI.
"""

@classmethod
def open(cls, target, *, auth=None, **config):
"""
:param target:
:param auth:
:param config: The values that can be specified are found in :class: `neo4j.PoolConfig` and :class: `neo4j.WorkspaceConfig`

:return:
:rtype: :class: `neo4j.BoltDriver`
"""
from neo4j.io import BoltPool
address = cls.parse_target(target)
pool_config, default_workspace_config = Config.consume_chain(config, PoolConfig, WorkspaceConfig)
pool = BoltPool.open(address, auth=auth, pool_config=pool_config, workspace_config=default_workspace_config)
return cls(pool, default_workspace_config)

def __init__(self, pool, default_workspace_config):
Direct.__init__(self, pool.address)
Driver.__init__(self, pool)
self._default_workspace_config = default_workspace_config

def session(self, **config):
"""
:param config: The values that can be specified are found in :class: `neo4j.SessionConfig`

:return:
:rtype: :class: `neo4j.Session`
"""
from neo4j.work.simple import Session
session_config = SessionConfig(self._default_workspace_config, config)
SessionConfig.consume(config) # Consume the config
return Session(self._pool, session_config)

def pipeline(self, **config):
from neo4j.work.pipelining import (
Pipeline,
PipelineConfig,
)
pipeline_config = PipelineConfig(self._default_workspace_config, config)
PipelineConfig.consume(config) # Consume the config
return Pipeline(self._pool, pipeline_config)

@experimental("The configuration may change in the future.")
def verify_connectivity(self, **config):
server_agent = None
config["fetch_size"] = -1
with self.session(**config) as session:
result = session.run("RETURN 1 AS x")
value = result.single().value()
summary = result.consume()
server_agent = summary.server.agent
return server_agent


class Neo4jDriver(Routing, Driver):
""" A :class:`.Neo4jDriver` is created from a ``neo4j`` URI. The
routing behaviour works in tandem with Neo4j's `Causal Clustering
<https://neo4j.com/docs/operations-manual/current/clustering/>`_
feature by directing read and write behaviour to appropriate
cluster members.
"""

@classmethod
def open(cls, *targets, auth=None, routing_context=None, **config):
from neo4j.io import Neo4jPool
addresses = cls.parse_targets(*targets)
pool_config, default_workspace_config = Config.consume_chain(config, PoolConfig, WorkspaceConfig)
pool = Neo4jPool.open(*addresses, auth=auth, routing_context=routing_context, pool_config=pool_config, workspace_config=default_workspace_config)
return cls(pool, default_workspace_config)

def __init__(self, pool, default_workspace_config):
Routing.__init__(self, pool.get_default_database_initial_router_addresses())
Driver.__init__(self, pool)
self._default_workspace_config = default_workspace_config

def session(self, **config):
session_config = SessionConfig(self._default_workspace_config, config)
SessionConfig.consume(config) # Consume the config
return Session(self._pool, session_config)

def pipeline(self, **config):
from neo4j.work.pipelining import (
Pipeline,
PipelineConfig,
)
pipeline_config = PipelineConfig(self._default_workspace_config, config)
PipelineConfig.consume(config) # Consume the config
return Pipeline(self._pool, pipeline_config)

@experimental("The configuration may change in the future.")
def verify_connectivity(self, **config):
"""
:raise ServiceUnavailable: raised if the server does not support routing or if routing support is broken.
"""
# TODO: Improve and update Stub Test Server to be able to test.
return self._verify_routing_connectivity()

def _verify_routing_connectivity(self):
from neo4j.exceptions import (
Neo4jError,
ServiceUnavailable,
SessionExpired,
)

table = self._pool.get_routing_table_for_default_database()
routing_info = {}
for ix in list(table.routers):
try:
routing_info[ix] = self._pool.fetch_routing_info(
address=table.routers[0],
database=self._default_workspace_config.database,
imp_user=self._default_workspace_config.impersonated_user,
bookmarks=None,
timeout=self._default_workspace_config
.connection_acquisition_timeout
)
except (ServiceUnavailable, SessionExpired, Neo4jError):
routing_info[ix] = None
for key, val in routing_info.items():
if val is not None:
return routing_info
raise ServiceUnavailable("Could not connect to any routing servers.")
11 changes: 7 additions & 4 deletions neo4j/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def __new__(mcs, name, bases, attributes):
for k, v in attributes.items():
if isinstance(v, DeprecatedAlias):
deprecated_aliases[k] = v.new
elif not k.startswith("_") and not callable(v):
elif not (k.startswith("_")
or callable(v)
or isinstance(v, (staticmethod, classmethod))):
fields.append(k)

def keys(_):
Expand Down Expand Up @@ -232,18 +234,19 @@ def get_ssl_context(self):
# TLS 1.1 - Released in 2006, published as RFC 4346. (Disabled)
# TLS 1.2 - Released in 2008, published as RFC 5246.

# https://docs.python.org/3.6/library/ssl.html#ssl.PROTOCOL_TLS_CLIENT
# https://docs.python.org/3.7/library/ssl.html#ssl.PROTOCOL_TLS_CLIENT
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)

# For recommended security options see
# https://docs.python.org/3.6/library/ssl.html#protocol-versions
# https://docs.python.org/3.7/library/ssl.html#protocol-versions
ssl_context.options |= ssl.OP_NO_TLSv1 # Python 3.2
ssl_context.options |= ssl.OP_NO_TLSv1_1 # Python 3.4


if self.trust == TRUST_ALL_CERTIFICATES:
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE # https://docs.python.org/3.5/library/ssl.html#ssl.CERT_NONE
# https://docs.python.org/3.7/library/ssl.html#ssl.CERT_NONE
ssl_context.verify_mode = ssl.CERT_NONE

# Must be load_default_certs, not set_default_verify_paths to work
# on Windows with system CAs.
Expand Down
2 changes: 1 addition & 1 deletion neo4j/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# Can be automatically overridden in builds
package = "neo4j"
version = "4.4.dev0"
version = "5.0.dev0"


def get_user_agent():
Expand Down
Loading