Skip to main content


QueryBuilder Objects

class QueryBuilder(DeclarativeBase)


def load_csv(path: str, header: bool, row: str) -> "DeclarativeBase"

Load data from a CSV file by executing a Cypher query for each row.


  • path - A string representing the path to the CSV file.
  • header - A bool indicating if the CSV file starts with a header row.
  • row - A string representing the name of the variable for iterating over each row.


A DeclarativeBase instance for constructing queries.


Load CSV with header:

  • Python - load_csv(path="path/to/my/file.csv", header=True, row="row").return_().execute()

  • Cypher - LOAD CSV FROM 'path/to/my/file.csv' WITH HEADER AS row RETURN *;

    Load CSV without header:

  • Python - load_csv(path='path/to/my/file.csv', header=False, row='row').return_().execute()

  • Cypher - LOAD CSV FROM 'path/to/my/file.csv' NO HEADER AS row RETURN *;


def call(procedure: str,
arguments: Optional[Union[str, Tuple[Union[str, int, float]]]] = None,
node_labels: Optional[Union[str, List[List[str]]]] = None,
relationship_types: Optional[Union[str, List[List[str]]]] = None,
relationship_directions: Optional[
List[RelationshipDirection]]] = RelationshipDirection.RIGHT,
subgraph_path: str = None) -> "DeclarativeBase"

Override of base class method to support Memgraph's subgraph functionality.

Method can be called with node labels and relationship types, both being optional, which are used to construct a subgraph, or if neither is provided, a subgraph query is used, which can be passed as a string representing a Cypher query defining the MATCH clause which selects the nodes and relationships to use.


  • procedure - A string representing the name of the procedure in the format query_module.procedure.
  • arguments - A string representing the arguments of the procedure in text format.
  • node_labels - Either a string, which is then used as the label for all nodes, or a list of lists defining all labels for every node
  • relationship_types - Types of relationships to be used in the subgraph. Either a single type or a list of lists defining all types for every relationship
  • relationship_directions - Directions of the relationships.
  • subgraph_path - Optional way to define the subgraph via a Cypher MATCH clause.


A DeclarativeBase instance for constructing queries.


  • Python - `call('export_util.json', '/home/user', "LABEL", ["TYPE1", "TYPE2"]).execute()

  • Cypher - MATCH p=(a)-[:TYPE1 | :TYPE2]->(b) WHERE (a:LABEL) AND (b:LABEL) WITH project(p) AS graph CALL export_util.json(graph, '/home/user')


  • Python - `call('export_util.json', '/home/user', subgraph_path="(:LABEL)-[:TYPE]->(:LABEL)").execute()

  • Cypher - MATCH p=(:LABEL)-[:TYPE1]->(:LABEL) WITH project(p) AS graph CALL export_util.json(graph, '/home/user')

ProjectPartialQuery Objects

class ProjectPartialQuery(PartialQuery)


def construct_query() -> str

Constructs a Project partial querty.

Given path part of a query (e.g. (:LABEL)-[:TYPE]->(:LABEL2)), adds MATCH, a path identifier and appends the WITH clause.