An Object Graph Mapper (OGM) for the neo4j graph database, built on the awesome neo4j_driver
If you need assistance with neomodel, please create an issue on the GitHub repo found at https://github.com/neo4j-contrib/neomodel/.
For neomodel releases 5.x :
For neomodel releases 4.x :
Available on readthedocs.
neomodel now supports asynchronous programming, thanks to the Neo4j driver async API. The documentation has been updated accordingly, with an updated getting started section, and some specific documentation for the async API.
neomodel_install_labels
script instead. Note : this is because of the addition of async, but also because it might lead to uncontrolled creation of indexes/constraints. The script makes you more in control of said creation.Install from pypi (recommended):
$ pip install neomodel ($ source dev # To install all things needed in a Python3 venv)
# Neomodel has some optional dependencies (including Shapely), to install these use:
$ pip install neomodel['extras']
To install from github:
$ pip install git+git://github.com/neo4j-contrib/neomodel.git@HEAD#egg=neomodel-dev
You can find some performance tests made using Locust in this repo.
Two learnings from this :
Ideas, bugs, tests and pull requests always welcome. Please use GitHub\'s Issues page to track these.
If you are interested in developing neomodel
further, pick a subject
from the Issues page and open a Pull Request (PR) for it. If you are
adding a feature that is not captured in that list yet, consider if the
work for it could also contribute towards delivering any of the existing
issues too.
Make sure you have a Neo4j database version 4 or higher to run the tests on.:
$ export NEO4J_BOLT_URL=bolt://<username>:<password>@localhost:7687 # check your username and password
Ensure dbms.security.auth_enabled=true
in your database configuration
file. Setup a virtual environment, install neomodel for development and
run the test suite: :
$ pip install -e '.[dev,pandas,numpy]'
$ pytest
The tests in \"test_connection.py\" will fail locally if you don\'t specify the following environment variables:
$ export AURA_TEST_DB_USER=username
$ export AURA_TEST_DB_PASSWORD=password
$ export AURA_TEST_DB_HOSTNAME=url
If you are running a neo4j database for the first time the test suite
will set the password to \'test\'. If the database is already populated,
the test suite will abort with an error message and ask you to re-run it
with the --resetdb
switch. This is a safeguard to ensure that the test
suite does not accidentally wipe out a database if you happen to not
have restarted your Neo4j server to point to a (usually named)
debug.db
database.
If you have docker-compose
installed, you can run the test suite
against all supported Python interpreters and neo4j versions: :
# in the project's root folder:
$ sh ./tests-with-docker-compose.sh
We use this great library to automatically transpile async code into its sync version.
In other words, when contributing to neomodel, only update the async
code in neomodel/async_
, then run : :
bin/make-unasync
isort .
black .
Note that you can also use the pre-commit hooks for this.
This transpiling script mainly does two things :
adb
->db
, mark_async_test
->mark_sync_test
It might be that your code should only be run for async
, or sync
; or you want different stubs to be run for async
vs sync
.
You can use the following utility function for this - taken from the official Neo4j python driver code :
# neomodel/async_/core.py
from neomodel._async_compat.util import AsyncUtil
# AsyncUtil.is_async_code is always True
if AsyncUtil.is_async_code:
# Specific async code
# This one gets run when in async mode
assert await Coffee.nodes.check_contains(2)
else:
# Specific sync code
# This one gest run when in sync mode
assert 2 in Coffee.nodes
You can check test_match_api for some good examples, and how it's transpiled into sync.