General API¶
Properties¶
- class neomodel.properties.AliasProperty(to: str)¶
-
Alias another existing property
- class neomodel.properties.ArrayProperty(base_property: Property | None = None, **kwargs: Any)¶
Bases:
Property
Stores a list of items
- 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
- 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 toFalse
. :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
) – IfTrue
, the creation time (Local) will be used as default. Defaults toFalse
.
- 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
) – IfTrue
, the creation time (UTC) will be used as default. Defaults toFalse
.
- 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
- 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
- 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.
- 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 toFalse
.index (
bool
) – Creates an index for this property. Defaults toFalse
.fulltext_index (
FulltextIndex
) – Creates a fulltext index for this property. Defaults toNone
.vector_index (
VectorIndex
) – Creates a vector index for this property. Defaults toNone
.required (
bool
) – Marks the property as required. Defaults toFalse
.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 bydjango_neomodel
.help_text (
str
) – Optional, used bydjango_neomodel
.
- 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:
- 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)¶
- 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()¶