Async API Documentation¶
Core¶
AsyncSemiStructuredNode¶
- class neomodel.contrib.AsyncSemiStructuredNode(*args: Any, **kwargs: Any)¶
A base class allowing properties to be stored on a node that aren’t specified in its definition. Conflicting properties are signaled with the
DeflateConflictexception:class Person(AsyncSemiStructuredNode): name = StringProperty() age = IntegerProperty() def hello(self): print("Hi my names " + self.name) tim = await Person(name='Tim', age=8, weight=11).save() tim.hello = "Hi" await tim.save() # DeflateConflict
Relationships¶
- class neomodel.async_.relationship.AsyncStructuredRel(**kwargs: dict[str, Any])¶
Bases:
StructuredRelBaseBase class for relationship objects
- classmethod inflate(graph_entity: Relationship) AsyncStructuredRel¶
Inflate a neo4j_driver relationship object to a neomodel object :param graph_entity: Relationship :return: StructuredRel
- save() AsyncStructuredRel¶
Save the relationship
- Returns:
self
- class neomodel.async_.relationship.StructuredRelBase(**kwargs: dict[str, Any])¶
Bases:
AsyncPropertyManager
- class neomodel.async_.relationship_manager.AsyncRelationshipManager(source: Any, key: str, definition: dict)¶
Bases:
objectBase class for all relationships managed through neomodel.
I.e the ‘friends’ object in user.friends.all()
- all_relationships(node: AsyncStructuredNode) list[AsyncStructuredRel]¶
Retrieve all relationship objects between self and node.
- Parameters:
node
- Returns:
[StructuredRel]
- async check_cardinality(node: AsyncStructuredNode) None¶
Check whether a new connection to a node would violate the cardinality of the relationship.
- Parameters:
node – The node that is being connected.
- Type:
AsyncStructuredNode
- Raises:
AttemptedCardinalityViolation
- connect(node: AsyncStructuredNode, properties: dict[str, Any] | None = None) AsyncStructuredRel | None¶
Connect a node
- Parameters:
node
properties – for the new relationship
- Type:
- Returns:
- exclude(*args: Any, **kwargs: dict) AsyncBaseSet¶
Exclude nodes that match the provided properties.
- Parameters:
args – a Q object
kwargs – same syntax as NodeSet.filter()
- Returns:
NodeSet
- filter(*args: Any, **kwargs: dict) AsyncBaseSet¶
Retrieve related nodes matching the provided properties.
- Parameters:
args – a Q object
kwargs – same syntax as NodeSet.filter()
- Returns:
NodeSet
- async get(**kwargs: Any) AsyncNodeSet¶
Retrieve a related node with the matching node properties.
- Parameters:
kwargs – same syntax as NodeSet.filter()
- Returns:
node
- async get_or_none(**kwargs: dict) AsyncNodeSet¶
Retrieve a related node with the matching node properties or return None.
- Parameters:
kwargs – same syntax as NodeSet.filter()
- Returns:
node
- async is_connected(node: AsyncStructuredNode) bool¶
Check if a node is connected with this relationship type :param node: :return: bool
- match(**kwargs: dict) AsyncNodeSet¶
Return set of nodes who’s relationship properties match supplied args
- Parameters:
kwargs – same syntax as NodeSet.filter()
- Returns:
NodeSet
- order_by(*props: Any) AsyncBaseSet¶
Order related nodes by specified properties
- Parameters:
props
- Returns:
NodeSet
- reconnect(old_node: AsyncStructuredNode, new_node: AsyncStructuredNode) None¶
Disconnect old_node and connect new_node copying over any properties on the original relationship.
Useful for preventing cardinality violations
- Parameters:
old_node
new_node
- Returns:
None
- relationship(node: AsyncStructuredNode) AsyncStructuredRel | None¶
Retrieve the relationship object for this first relationship between self and node.
- Parameters:
node
- Returns:
StructuredRel
- class neomodel.async_.relationship_manager.AsyncZeroOrMore(source: Any, key: str, definition: dict)¶
Bases:
AsyncRelationshipManagerA relationship of zero or more nodes (the default)
- neomodel.async_.relationship_manager.deflate_relationship_properties(relationship: AsyncRelationshipManager, rel_props: dict[str, Any], query_params: dict[str, Any]) dict[str, str]¶
Deflate relationship properties and prepare them for Cypher query.
- Parameters:
relationship – The relationship manager containing the model
rel_props – Dictionary of relationship properties to deflate
query_params – Query parameters dict to add deflated values to
- Returns:
Dictionary mapping property names to parameter placeholders (e.g. {‘since’: ‘$since’})
- neomodel.async_.relationship_manager.validate_relationship(relationship: Any, rel_props: Any) None¶
Validate relationship manager.
- Parameters:
relationship – The relationship manager to validate
- Raises:
TypeError – If relationship is not an AsyncRelationshipManager
ValueError – If relationship source is invalid or relation_type is missing
RuntimeError – If relationship source element_id is None
- class neomodel.async_.cardinality.AsyncOne(source: Any, key: str, definition: dict)¶
Bases:
AsyncRelationshipManagerA relationship to a single node
- async check_cardinality(node: AsyncStructuredNode) None¶
Check whether a new connection to a node would violate the cardinality of the relationship.
- Parameters:
node – The node that is being connected.
- Type:
AsyncStructuredNode
- Raises:
AttemptedCardinalityViolation
- async connect(node: AsyncStructuredNode, properties: dict[str, Any] | None = None) AsyncStructuredRel¶
Connect a node
- Parameters:
node
properties – relationship properties
- Returns:
True / rel instance
- async single() AsyncStructuredNode¶
Return the associated node.
- Returns:
node
- class neomodel.async_.cardinality.AsyncOneOrMore(source: Any, key: str, definition: dict)¶
Bases:
AsyncRelationshipManagerA relationship to zero or more nodes.
- async single() AsyncStructuredNode¶
Fetch one of the related nodes
- Returns:
Node
- class neomodel.async_.cardinality.AsyncZeroOrOne(source: Any, key: str, definition: dict)¶
Bases:
AsyncRelationshipManagerA relationship to zero or one node.
- async check_cardinality(node: AsyncStructuredNode) None¶
Check whether a new connection to a node would violate the cardinality of the relationship.
- Parameters:
node – The node that is being connected.
- Type:
AsyncStructuredNode
- Raises:
AttemptedCardinalityViolation
Property Manager¶
- class neomodel.async_.property_manager.AsyncPropertyManager(**kwargs: dict[str, Any])¶
Bases:
objectCommon methods for handling properties on node and relationship objects.
- classmethod deflate(properties: Any, obj: Any = None, skip_empty: bool = False) dict[str, Any]¶
Deflate the properties of a PropertyManager subclass (a user-defined StructuredNode or StructuredRel) so that it can be put into a neo4j.graph.Entity (a neo4j.graph.Node or neo4j.graph.Relationship) for storage. properties can be constructed manually, or fetched from a PropertyManager subclass using __properties__.
Includes mapping from python class attribute name -> database property name (see Property.db_property).
Ignores any properties that are not defined as python attributes in the class definition.
- classmethod inflate(graph_entity: Node | Relationship) Any¶
Inflate the properties of a graph entity (a neo4j.graph.Node or neo4j.graph.Relationship) into an instance of cls. Includes mapping from database property name (see Property.db_property) -> python class attribute name. Ignores any properties that are not defined as python attributes in the class definition.
Paths¶
- class neomodel.async_.path.AsyncNeomodelPath(a_neopath: Path)¶
Bases:
objectRepresents paths within neomodel.
This object is instantiated when you include whole paths in your
cypher_query()result sets and turnresolve_objectsto True.That is, any query of the form:
MATCH p=(:SOME_NODE_LABELS)-[:SOME_REL_LABELS]-(:SOME_OTHER_NODE_LABELS) return p
NeomodelPathare simple objects that reference their nodes and relationships, each of which is already resolved to their neomodel objects if such mapping is possible.- Parameters:
nodes (list[StructuredNode]) – Neomodel nodes appearing in the path in order of appearance.
relationships (list[StructuredRel]) – Neomodel relationships appearing in the path in order of appearance.
- property end_node: AsyncStructuredNode¶
The last
StructuredNodein this path.
- property start_node: AsyncStructuredNode¶
The first
StructuredNodein this path.
Match¶
- class neomodel.async_.match.AsyncBaseSet¶
Base class for all node sets.
Contains common python magic methods, __len__, __contains__ etc
- async all(lazy: bool = False) list¶
Return all nodes belonging to the set :param lazy: False by default, specify True to get nodes with id only without the parameters. :return: list of nodes :rtype: list
- async check_bool() bool¶
Override for __bool__ dunder method. :return: True if the set contains any nodes, False otherwise :rtype: bool
- async check_nonzero() bool¶
Override for __bool__ dunder method. :return: True if the set contains any node, False otherwise :rtype: bool
- async get_item(key: int | slice) AsyncBaseSet | None¶
- query_cls¶
alias of
AsyncQueryBuilder
- class neomodel.async_.match.AsyncNodeSet(source: Any)¶
A class representing as set of nodes matching common query parameters
- annotate(*vars: tuple, **aliased_vars: tuple) AsyncNodeSet¶
Annotate node set results with extra variables.
- exclude(*args: Any, **kwargs: Any) AsyncBaseSet¶
Exclude nodes from the NodeSet via filters.
- Parameters:
kwargs – filter parameters see syntax for the filter method
- Returns:
self
- filter(*args: Any, **kwargs: Any) AsyncBaseSet¶
Apply filters to the existing nodes in the set.
- Parameters:
args –
a Q object
e.g .filter(Q(salary__lt=10000) | Q(salary__gt=20000)).
kwargs –
filter parameters
Filters mimic Django’s syntax with the double ‘__’ to separate field and operators.
e.g .filter(salary__gt=20000) results in salary > 20000.
The following operators are available:
’lt’: less than
’gt’: greater than
’lte’: less than or equal to
’gte’: greater than or equal to
’ne’: not equal to
’in’: matches one of list (or tuple)
’isnull’: is null
’regex’: matches supplied regex (neo4j regex format)
’exact’: exactly match string (just ‘=’)
’iexact’: case insensitive match string
’contains’: contains string
’icontains’: case insensitive contains
’startswith’: string starts with
’istartswith’: case insensitive string starts with
’endswith’: string ends with
’iendswith’: case insensitive string ends with
- Returns:
self
- async first(**kwargs: Any) Any¶
Retrieve the first node from the set matching supplied parameters
- Parameters:
kwargs – same syntax as filter()
- Returns:
node
- async first_or_none(**kwargs: Any) Any¶
Retrieve the first node from the set matching supplied parameters or return none
- Parameters:
kwargs – same syntax as filter()
- Returns:
node or none
- async get(lazy: bool = False, **kwargs: Any) Any¶
Retrieve one node from the set matching supplied parameters :param lazy: False by default, specify True to get nodes with id only without the parameters. :param kwargs: same syntax as filter() :return: node
- async get_or_none(**kwargs: Any) Any¶
Retrieve a node from the set matching supplied parameters or return none
- Parameters:
kwargs – same syntax as filter()
- Returns:
node or none
- has(**kwargs: Any) AsyncBaseSet¶
- intermediate_transform(vars: dict[str, Transformation], distinct: bool = False, ordering: list | None = None) AsyncNodeSet¶
- order_by(*props: Any) AsyncBaseSet¶
Order by properties. Prepend with minus to do descending. Pass None to remove ordering.
- async resolve_subgraph() list¶
Convert every result contained in this node set to a subgraph.
By default, we receive results from neomodel as a list of nodes without the hierarchy. This method tries to rebuild this hierarchy without overriding anything in the node, that’s why we use a dedicated property to store node’s relations.
- async subquery(nodeset: AsyncNodeSet, return_set: list[str], initial_context: list[str] | None = None) AsyncNodeSet¶
Add a subquery to this node set.
A subquery is a regular cypher query but executed within the context of a CALL statement. Such query will generally fetch additional variables which must be declared inside return_set variable in order to be included in the final RETURN statement.
- traverse(*paths: tuple[str, ...], **aliased_paths: dict) AsyncNodeSet¶
Specify a set of paths to traverse.
- unique_variables(*paths: str) AsyncNodeSet¶
Generate unique variable names for the given paths.
- class neomodel.async_.match.AsyncTraversal(source: Any, name: str, definition: dict)¶
Models a traversal from a node to another.
- Parameters:
- match(**kwargs: Any) AsyncTraversal¶
Traverse relationships with properties matching the given parameters.
e.g: .match(price__lt=10)
- Parameters:
kwargs – see NodeSet.filter() for syntax
- Returns:
self