General API

Properties

class neomodel.properties.AliasProperty(to=None)

Bases: property, Property

Alias another existing property

class neomodel.properties.ArrayProperty(base_property=None, **kwargs)

Bases: Property

Stores a list of items

default_value()

Generate a default value

Returns:

the value

class neomodel.properties.BooleanProperty(unique_index=False, index=False, required=False, default=None, db_property=None, label=None, help_text=None, **kwargs)

Bases: Property

Stores a boolean value

default_value()

Generate a default value

Returns:

the value

class neomodel.properties.DateProperty(unique_index=False, index=False, required=False, default=None, db_property=None, label=None, help_text=None, **kwargs)

Bases: Property

Stores a date

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

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.

Parameters:

format (str) – Date format string, default is %Y-%m-%d

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

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=None, **kwargs)

Bases: RegexProperty

Store email addresses

class neomodel.properties.FloatProperty(unique_index=False, index=False, required=False, default=None, db_property=None, label=None, help_text=None, **kwargs)

Bases: Property

Store a floating point value

default_value()

Generate a default value

Returns:

the value

class neomodel.properties.IntegerProperty(unique_index=False, index=False, required=False, default=None, db_property=None, label=None, help_text=None, **kwargs)

Bases: Property

Stores an Integer value

default_value()

Generate a default value

Returns:

the value

class neomodel.properties.JSONProperty(*args, **kwargs)

Bases: Property

Store a data structure as a JSON string.

The structure will be inflated when a node is retrieved.

class neomodel.properties.NormalizedProperty(unique_index=False, index=False, required=False, default=None, db_property=None, label=None, help_text=None, **kwargs)

Bases: Property

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

default_value()

Generate a default value

Returns:

the value

class neomodel.properties.Property(unique_index=False, index=False, required=False, default=None, db_property=None, label=None, help_text=None, **kwargs)

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.

  • 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()

Generate a default value

Returns:

the value

get_db_property_name(attribute_name)

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=None, **kwargs)

Bases: NormalizedProperty

Validates a property against a regular expression.

If sub-classing set:

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

class neomodel.properties.StringProperty(choices=None, max_length=None, **kwargs)

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()

Generate a default value

Returns:

the value

class neomodel.properties.UniqueIdProperty(**kwargs)

Bases: Property

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

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, actual)

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)

Bases: ValueError, NeomodelException

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

Bases: InflateConflict

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

Bases: ValueError, NeomodelException

exception neomodel.exceptions.DoesNotExist(msg)

Bases: NeomodelException

exception neomodel.exceptions.FeatureNotSupported(msg)

Bases: NeomodelException

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

Bases: NeomodelException

exception neomodel.exceptions.InflateError(key, cls, msg, obj=None)

Bases: ValueError, NeomodelException

exception neomodel.exceptions.MultipleNodesReturned(msg)

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, current_node_class_registry)

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, current_node_class_registry)

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, node1, node2)

Bases: NeomodelException

exception neomodel.exceptions.RelationshipClassNotDefined(db_node_rel_class, current_node_class_registry)

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, current_node_class_registry, remapping_to_class)

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, cls)

Bases: NeomodelException

exception neomodel.exceptions.UniqueProperty(msg)

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.load_python_module_or_file(name)

Imports an existing python module or file into the current workspace.

In both cases, the resource must exist.

Parameters:

name (str) – A string that refers either to a Python module or a source coe file to load in the current workspace.

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()