General API

Properties

class neomodel.properties.AliasProperty(to: str)

Bases: property, Property

Alias another existing property

property index: bool

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

property unique_index: bool

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

class neomodel.properties.ArrayProperty(base_property: Property | None = None, **kwargs: Any)

Bases: Property

Stores a list of items

default_value() list

Generate a default value

Returns:

the value

class neomodel.properties.BooleanProperty(name: str | None = None, owner: Any | None = None, unique_index: bool = False, index: bool = False, fulltext_index: FulltextIndex | None = None, vector_index: VectorIndex | None = None, required: bool = False, default: Any | None = None, db_property: str | None = None, label: str | None = None, help_text: str | None = None, **kwargs: dict[str, Any])

Bases: Property

Stores a boolean value

default_value() bool

Generate a default value

Returns:

the value

class neomodel.properties.DateProperty(name: str | None = None, owner: Any | None = None, unique_index: bool = False, index: bool = False, fulltext_index: FulltextIndex | None = None, vector_index: VectorIndex | None = None, required: bool = False, default: Any | None = None, db_property: str | None = None, label: str | None = None, help_text: str | None = None, **kwargs: dict[str, Any])

Bases: Property

Stores a date

class neomodel.properties.DateTimeFormatProperty(default_now: bool = False, format: str = '%Y-%m-%d', **kwargs: Any)

Bases: Property

Store a datetime by custom format :param default_now: If True, the creation time (Local) will be used as default. Defaults to False. :param format: Date format string, default is %Y-%m-%d

class neomodel.properties.DateTimeNeo4jFormatProperty(default_now: bool = False, **kwargs: Any)

Bases: Property

Store a datetime by native neo4j format

Parameters:

default_now (bool) – If True, the creation time (Local) will be used as default. Defaults to False.

class neomodel.properties.DateTimeProperty(default_now: bool = False, **kwargs: Any)

Bases: Property

A property representing a datetime.datetime object as unix epoch.

Parameters:

default_now (bool) – If True, the creation time (UTC) will be used as default. Defaults to False.

class neomodel.properties.EmailProperty(expression: str | None = None, **kwargs: Any)

Bases: RegexProperty

Store email addresses

class neomodel.properties.FloatProperty(name: str | None = None, owner: Any | None = None, unique_index: bool = False, index: bool = False, fulltext_index: FulltextIndex | None = None, vector_index: VectorIndex | None = None, required: bool = False, default: Any | None = None, db_property: str | None = None, label: str | None = None, help_text: str | None = None, **kwargs: dict[str, Any])

Bases: Property

Store a floating point value

default_value() float

Generate a default value

Returns:

the value

class neomodel.properties.FulltextIndex(analyzer: str | None = 'standard-no-stop-words', eventually_consistent: bool | None = False)

Bases: object

Fulltext index definition

class neomodel.properties.IntegerProperty(name: str | None = None, owner: Any | None = None, unique_index: bool = False, index: bool = False, fulltext_index: FulltextIndex | None = None, vector_index: VectorIndex | None = None, required: bool = False, default: Any | None = None, db_property: str | None = None, label: str | None = None, help_text: str | None = None, **kwargs: dict[str, Any])

Bases: Property

Stores an Integer value

default_value() int

Generate a default value

Returns:

the value

class neomodel.properties.JSONProperty(ensure_ascii: bool = True, *args: Any, **kwargs: Any)

Bases: Property

Store a data structure as a JSON string.

The structure will be inflated when a node is retrieved.

class neomodel.properties.NormalizedProperty(name: str | None = None, owner: Any | None = None, unique_index: bool = False, index: bool = False, fulltext_index: FulltextIndex | None = None, vector_index: VectorIndex | None = None, required: bool = False, default: Any | None = None, db_property: str | None = None, label: str | None = None, help_text: str | None = None, **kwargs: dict[str, Any])

Bases: Property

Base class for normalized properties. These use the same normalization method to in- or deflating.

default_value() Any

Generate a default value

Returns:

the value

class neomodel.properties.Property(name: str | None = None, owner: Any | None = None, unique_index: bool = False, index: bool = False, fulltext_index: FulltextIndex | None = None, vector_index: VectorIndex | None = None, required: bool = False, default: Any | None = None, db_property: str | None = None, label: str | None = None, help_text: str | None = None, **kwargs: dict[str, Any])

Bases: object

Base class for object properties.

Parameters:
  • unique_index (bool) – Creates a unique index for this property. Defaults to False.

  • index (bool) – Creates an index for this property. Defaults to False.

  • fulltext_index (FulltextIndex) – Creates a fulltext index for this property. Defaults to None.

  • vector_index (VectorIndex) – Creates a vector index for this property. Defaults to None.

  • required (bool) – Marks the property as required. Defaults to False.

  • default – A default value or callable that returns one to set when a node is initialized without specifying this property.

  • db_property (str) – A name that this property maps to in the database. Defaults to the model’s property name.

  • label (str) – Optional, used by django_neomodel.

  • help_text (str) – Optional, used by django_neomodel.

default_value() Any

Generate a default value

Returns:

the value

get_db_property_name(attribute_name: str) str

Returns the name that should be used for the property in the database. This is db_property if supplied upon construction, otherwise the given attribute_name from the model is used.

class neomodel.properties.RegexProperty(expression: str | None = None, **kwargs: Any)

Bases: NormalizedProperty

Validates a property against a regular expression.

If sub-classing set:

expression = r’[^@]+@[^@]+.[^@]+’

class neomodel.properties.StringProperty(choices: Any | None = None, max_length: int | None = None, **kwargs: Any)

Bases: NormalizedProperty

Stores a unicode string

Parameters:
  • choices (Any type that can be used to initiate a dict.) – A mapping of valid strings to label strings that are used to display information in an application. If the default value None is used, any string is valid.

  • max_length (int) – The maximum non-zero length that this attribute can be

default_value() str

Generate a default value

Returns:

the value

class neomodel.properties.UniqueIdProperty(**kwargs: Any)

Bases: Property

A unique identifier, a randomly generated uid (uuid4) with a unique index

class neomodel.properties.VectorIndex(dimensions: int | None = 1536, similarity_function: str | None = 'cosine')

Bases: object

Vector index definition

Spatial Properties & Datatypes

Exceptions

exception neomodel.exceptions.AttemptedCardinalityViolation

Bases: NeomodelException

Attempted to alter the database state against the cardinality definitions.

Example: a relationship of type One trying to connect a second node.

exception neomodel.exceptions.CardinalityViolation(rel_manager: Any, actual: int | str)

Bases: NeomodelException

The state of database doesn’t match the nodes cardinality definition.

For example a relationship type OneOrMore returns no nodes.

exception neomodel.exceptions.ConstraintValidationFailed(msg: str)

Bases: ValueError, NeomodelException

exception neomodel.exceptions.DeflateConflict(cls: Any, key: str, value: Any, nid: str)

Bases: InflateConflict

exception neomodel.exceptions.DeflateError(key: str, cls: Any, msg: str, obj: Any)

Bases: ValueError, NeomodelException

exception neomodel.exceptions.DoesNotExist(msg: str)

Bases: NeomodelException

exception neomodel.exceptions.FeatureNotSupported(msg: str)

Bases: NeomodelException

exception neomodel.exceptions.InflateConflict(cls: Any, key: str, value: Any, nid: str)

Bases: NeomodelException

exception neomodel.exceptions.InflateError(key: str, cls: Any, msg: str, obj: Any | None = None)

Bases: ValueError, NeomodelException

exception neomodel.exceptions.MultipleNodesReturned(msg: str)

Bases: ValueError, NeomodelException

exception neomodel.exceptions.NeomodelException

Bases: Exception

A base class that identifies all exceptions raised by neomodel.

exception neomodel.exceptions.NodeClassAlreadyDefined(db_node_rel_class: Any, current_node_class_registry: dict[frozenset, Any], current_db_specific_node_class_registry: dict[str, dict])

Bases: ModelDefinitionException

Raised when an attempt is made to re-map a set of labels to a class that already has a mapping within the node-to-class registry.

exception neomodel.exceptions.NodeClassNotDefined(db_node_rel_class: Any, current_node_class_registry: dict[frozenset, Any], current_db_specific_node_class_registry: dict[str, dict])

Bases: ModelDefinitionException

Raised when it is impossible to resolve a Neo4j driver Node to a data model object. This can happen as a result of a query returning nodes for which class definitions do exist but have not been imported or because the retrieved nodes contain more labels for a known class.

In either of these cases the mismatch must be reported

exception neomodel.exceptions.NotConnected(action: str, node1: Any, node2: Any)

Bases: NeomodelException

exception neomodel.exceptions.RelationshipClassNotDefined(db_node_rel_class: Any, current_node_class_registry: dict[frozenset, Any], current_db_specific_node_class_registry: dict[str, dict])

Bases: ModelDefinitionException

Raised when it is impossible to resolve a Neo4j driver Relationship to a data model object.

exception neomodel.exceptions.RelationshipClassRedefined(db_rel_class_type: Any, current_node_class_registry: dict[frozenset, Any], current_db_specific_node_class_registry: dict[str, dict], remapping_to_class: Any)

Bases: ModelDefinitionException

Raised when an attempt is made to re-map a relationship label to a relationship model of an entirely different type

exception neomodel.exceptions.RequiredProperty(key: str, cls: Any)

Bases: NeomodelException

exception neomodel.exceptions.UniqueProperty(msg: str)

Bases: ConstraintValidationFailed

Scripts

neomodel_inspect_database

usage: neomodel_inspect_database [-h] [--db bolt://neo4j:neo4j@localhost:7687] [--write-to <someapp/models.py> ...]

Connects to a Neo4j database and inspects existing nodes and relationships.
Infers the schema of the database and generates Python class definitions.

If a connection URL is not specified, the tool will look up the environment 
variable NEO4J_BOLT_URL. If that environment variable is not set, the tool
will attempt to connect to the default URL bolt://neo4j:neo4j@localhost:7687

If a file is specified, the tool will write the class definitions to that file.
If no file is specified, the tool will print the class definitions to stdout.

Note : this script only has a synchronous mode.

options:
    -h, --help            show this help message and exit
    --db bolt://neo4j:neo4j@localhost:7687
                        Neo4j Server URL
    -T, --write-to someapp/models.py
                        File where to write output.
    --no-rel-props        Do not inspect relationship properties
    --no-rel-cardinality  Do not infer relationship cardinality
class neomodel.scripts.neomodel_inspect_database.NodeInspector

Bases: object

static get_constraints_for_label(label)
static get_indexed_properties_for_label(label)
static get_properties_for_label(label)
class neomodel.scripts.neomodel_inspect_database.RelationshipInspector

Bases: object

static get_constraints_for_type(rel_type)
static get_indexed_properties_for_type(rel_type)
static infer_cardinality(rel_type, start_label)
classmethod outgoing_relationships(start_label, get_properties: bool = True)
neomodel.scripts.neomodel_inspect_database.build_prop_string(unique_properties, indexed_properties, prop, prop_type)
neomodel.scripts.neomodel_inspect_database.build_rel_type_definition(label, outgoing_relationships, defined_rel_types, infer_cardinality: bool = True)
neomodel.scripts.neomodel_inspect_database.clean_class_member_key(key)
neomodel.scripts.neomodel_inspect_database.generate_rel_class_name(rel_type)
neomodel.scripts.neomodel_inspect_database.get_node_labels()
neomodel.scripts.neomodel_inspect_database.inspect_database(bolt_url, get_relationship_properties: bool = True, infer_relationship_cardinality: bool = True)
neomodel.scripts.neomodel_inspect_database.main()
neomodel.scripts.neomodel_inspect_database.parse_imports()
neomodel.scripts.neomodel_inspect_database.parse_prop_class(prop_type)

neomodel_install_labels

usage: neomodel_install_labels [-h] [--db bolt://neo4j:neo4j@localhost:7687] <someapp.models/app.py> [<someapp.models/app.py> ...]

Setup indexes and constraints on labels in Neo4j for your neomodel schema.

If a connection URL is not specified, the tool will look up the environment 
variable NEO4J_BOLT_URL. If that environment variable is not set, the tool
will attempt to connect to the default URL bolt://neo4j:neo4j@localhost:7687

Note : this script only has a synchronous mode.

positional arguments:
  <someapp.models/app.py>
                        python modules or files with neomodel schema declarations.

options:
  -h, --help            show this help message and exit
  --db bolt://neo4j:neo4j@localhost:7687
                        Neo4j Server URL
neomodel.scripts.neomodel_install_labels.main()

neomodel_remove_labels

usage: neomodel_remove_labels [-h] [--db bolt://neo4j:neo4j@localhost:7687]

Drop all indexes and constraints on labels from schema in Neo4j database.

If a connection URL is not specified, the tool will look up the environment 
variable NEO4J_BOLT_URL. If that environment variable is not set, the tool
will attempt to connect to the default URL bolt://neo4j:neo4j@localhost:7687

Note : this script only has a synchronous mode.

options:
  -h, --help            show this help message and exit
  --db bolt://neo4j:neo4j@localhost:7687
                        Neo4j Server URL
neomodel.scripts.neomodel_remove_labels.main()