Compatibility layer for py2neo
OTHER License
.. image:: https://img.shields.io/pypi/v/py2neo_compat.svg :target: https://pypi.python.org/pypi/py2neo_compat
.. .. image:: https://img.shields.io/travis/wcooley/py2neo_compat.svg :target: https://travis-ci.org/wcooley/py2neo_compat
.. .. image:: https://readthedocs.org/projects/py2neo-compat/badge/?version=latest :target: https://py2neo-compat.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status
.. .. image:: https://pyup.io/repos/github/wcooley/py2neo_compat/shield.svg :target: https://pyup.io/repos/github/wcooley/py2neo_compat/ :alt: Updates
A (probably vain) attempt to create a cross-version compatibility layer for py2neo_.
Every major release of py2neo has radically (and gratuitously, it seems) changed the API: package/module organization, name of the database connection class, facilities for working with nodes & relationships -- not to mention more complicated features like interacting with schema.
What is implemented here is a hodgepodge of monkey-patches and other hacks to make things work between v1.6 and v2.
At work I inherited a codebase developed around py2neo v1.6, and data access was intricately tied with business logic. Tests were scarce and what tests existed were system tests that did not address errors, boundary conditions, etc., so updating every use of py2neo for a new version would be very risky. (Not to mention that I was just learning py2neo & Neo4j.)
My initial plan was to upgrade to py2neo v2 (current at the time) incrementally by monkey-patching & renaming to make v1.6 able to be used as if it were v2 and when the code had all been changed to use v2, upgrade to py2neo v2. Along the way I had the opportunity to develop a new, stand-alone application, so I started out creating a new dist for the application and developing some libraries that could be shared with legacy system, so I created a separate dist for the shared libraries. I did not want to develop the new application with the old v1.6, so my shared library would need to support both v1.6 and v2. I also started a separate project called gryaml_, to load sample data from YAML files, which also needed to support multiple versions in order to be run as test fixtures.
Implementation-independent names, optionally monkey-patched into the
py2neo
namespace and classes upon call to
py2neo_compat.monkey_patch_py2neo
:
Graph
Graph.create_unique
(only single path)Graph.cypher.stream
Graph.cypher.execute
Graph.delete_all
Graph.find_one
Graph.legacy.delete_index
Graph.legacy.get_*index*
Graph.resource
Graph.uri
Node
Node.labels
property (get-only)Node.pull
method (aliased to refresh
in v1)Node.push
method (aliased to refresh
in v1)Relationship
Relationship.push
method (aliased to refresh
in v1)Relationship.pull
method (aliased to refresh
in v1)Record
node
rel
ServerError
ClientError
URI
Resource
py2neo.legacy.LegacyWriteBatch
py2neo.legacy.Index
py2neo.batch.WriteBatch
Custom wrapper functions, which are not monkey-patched:
py2neo_compat
graph_metadata
create_node
py2neo_entity_to_dict
aka to_dict
: Dump the properties of adict
.schema
:
schema_constraints
- Yields tuples of schema constraints forschema_indexes
- Yields tuples of schema indexes for alldrop_schema
drop_constraints
drop_indexes
create_schema
Known limitations:
Node
.set
. The easy way would be to add the v1 methods to v2, but IFree software: Apache Software License 2.0
.. * Documentation: https://py2neo-compat.readthedocs.io. TBD
For future development, I am considering several options:
Bolt-only Python driver
_.Approaches other than monkey-patching:
py2neo_compat
package, rather than importing, calling the monkey-patchpy2neo
.This would might work better for Nodes and Relationships and the basic Graph features than the schema, batch and legacy index support.
This package was created with Cookiecutter_ and the audreyr/cookiecutter-pypackage
_ project template.
.. _py2neo: http://py2neo.org
.. _gryaml: https://github.com/wcooley/python-gryaml
.. _Bolt-only Python driver
: https://neo4j.com/docs/api/python-driver/current/
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _audreyr/cookiecutter-pypackage
: https://github.com/audreyr/cookiecutter-pypackage