Skip to main content

neomodel

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/.

  • Familiar class based model definitions with proper inheritance.
  • Powerful query API.
  • Schema enforcement through cardinality restrictions.
  • Full transaction support.
  • Thread safe.
  • Pre/post save/delete hooks.
  • Django integration via django_neomodel

Reliability Rating Security Rating Documentation Status

Requirements

For neomodel releases 6.x :

  • Python 3.10+
  • Neo4j 2025.x.x, 5.x, 4.4 (LTS)
  • Neo4j Enterprise, Community and Aura are supported

For neomodel releases 5.x :

  • Python 3.8+
  • Neo4j 5.x, 4.4 (LTS)

For neomodel releases 4.x :

  • Python 3.7 -> 3.10
  • Neo4j 4.x (including 4.4 LTS for neomodel version 4.0.10)

Documentation

Available on readthedocs.

Also check out DeepWiki : Ask DeepWiki

New in 6.0.0

From now on, neomodel will use SemVer (major.minor.patch) for versioning.

This version introduces a modern configuration system, using a dataclass with typing, runtime and update validation rules, and environment variables support. See the documentation section for more details.

Semantic Indexes (Vector and Full-text) are now natively supported so you do not have to use a custom Cypher query. Special thanks to @greengori11a for this.

Breaking changes

  • List object resolution from Cypher was creating "2-depth" lists for no apparent reason. This release fixes this so that, for example "RETURN collect(node)" will return the nodes directly as a list in the result. In other words, you can extract this list at results[0][0] instead of results[0][0][0]
  • See more breaking changes in the documentation

Installation

Install from pypi (recommended):

$ pip install neomodel ($ source dev # To install all things needed in a Python3 venv)

# neomodel can use the Rust extension to the Neo4j driver for faster transport, to install use:

$ pip install neomodel[rust-driver-ext]

# neomodel has some optional dependencies (Shapely, pandas, numpy), to install these use:

$ pip install neomodel[extras, rust-driver-ext]

To install from github:

$ pip install git+git://github.com/neo4j-contrib/neomodel.git@HEAD#egg=neomodel-dev

Performance comparison

You can find some performance tests made using Locust in this repo.

Two learnings from this :

  • The wrapping of the driver made by neomodel is very thin performance-wise : it does not add a lot of overhead ;
  • When used in a concurrent fashion, async neomodel is faster than concurrent sync neomodel, and a lot faster than serial queries.

Contributing

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.

Running the test suite

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 -r requirements-dev.txt
$ 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

Developing with async

Transpiling async -> sync

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.

Specific async/sync code

This transpiling script mainly does two things :

  • It removes the await keywords, and the Async prefixes in class names
  • It does some specific replacements, like 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neomodel-7.0.0.tar.gz (307.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

neomodel-7.0.0-py3-none-any.whl (363.6 kB view details)

Uploaded Python 3

File details

Details for the file neomodel-7.0.0.tar.gz.

File metadata

  • Download URL: neomodel-7.0.0.tar.gz
  • Upload date:
  • Size: 307.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for neomodel-7.0.0.tar.gz
Algorithm Hash digest
SHA256 13154656283860f0a06d4b17c724540eb4bc294ba5ae711a373b763f772ad048
MD5 76df5b02c2bb9dd85e0aab86a4178940
BLAKE2b-256 673510da4a805dc64467763b2ccd50f487f585c10a75d52e66dad639af532da0

See more details on using hashes here.

File details

Details for the file neomodel-7.0.0-py3-none-any.whl.

File metadata

  • Download URL: neomodel-7.0.0-py3-none-any.whl
  • Upload date:
  • Size: 363.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for neomodel-7.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b42581be4651da6ee732870fa709616ac2ee697c8ed36bc97acd0e6bf5da6c34
MD5 cdbc8d08cc322953c3c3a84f2588a3c5
BLAKE2b-256 6e532c1bc2d4ba7c79098565f3074f2d38af8754e9904b9870d910db18389c05

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

7.0.0 This release

2 files

6.2.0

2 files

6.1.0

2 files

6.0.1

2 files

6.0.0

2 files

5.5.3

2 files

5.5.2

2 files

5.5.1

2 files

5.5.0

2 files

5.4.5

2 files

5.4.4

2 files

5.4.3

2 files

5.4.2

2 files

5.4.1

2 files

5.4.0

2 files

5.3.3

2 files

5.3.2

2 files

5.3.1

2 files

5.3.0

2 files

5.2.1

2 files

5.2.0

2 files

5.1.2

2 files

5.1.1

2 files

5.1.0

2 files

5.0.1

2 files

5.0.0

2 files

4.0.10

2 files

4.0.9

2 files

4.0.8

2 files

4.0.7

2 files

4.0.6

1 file

4.0.5

1 file

4.0.4

1 file

4.0.3

1 file

4.0.2

2 files

4.0.1

1 file

4.0.0

1 file

3.3.2

1 file

3.3.1

2 files

3.3.0

1 file

3.2.9

1 file

3.2.8

1 file

3.2.7

3 files

3.2.6

3 files

3.2.5

2 files

3.2.4

2 files

3.2.3

2 files

3.2.2

2 files

3.2.1

2 files

3.2.0

2 files

3.1.0

2 files

3.0.3

2 files

3.0.2

2 files

3.0.1

2 files

3.0.0

2 files

2.0.2

2 files

2.0.1

1 file

1.0.2

1 file

1.0.1

2 files

1.0.0

2 files

0.3.6

1 file

0.3.5

1 file

0.3.4

1 file

0.3.3

1 file

0.3.2

1 file

0.3.1

1 file

0.3.0

1 file

0.2.9

1 file

0.2.8

1 file

0.2.7

1 file

0.2.6

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page