Airflow Summit 2025 is coming October 07-09. Register now for early bird ticket!

Neo4jOperator

Use the Neo4jOperator to execute SQL commands in a Neo4j database.

Using the Operator

Use the neo4j_conn_id argument to connect to your Neo4j instance where the connection metadata is structured as follows:

Neo4j Airflow Connection Metadata

Parameter

Input

Host: string

Neo4j hostname

Schema: string

Database name

Login: string

Neo4j user

Password: string

Neo4j user password

Port: int

Neo4j port

tests/system/neo4j/example_neo4j.py[source]


neo4j_task = Neo4jOperator(
    task_id="run_neo4j_query",
    neo4j_conn_id="neo4j_conn_id",
    sql='MATCH (tom {name: "Tom Hanks", date: "{{ds}}"}) RETURN tom',
    dag=dag,
)

Passing parameters into the query

Neo4jOperator provides parameters argument to pass parameters into the query. This allows you to use placeholders in your parameterized query and substitute them with actual values at execution time.

When using the parameters argument, you should prefix placeholders in your query using the $ syntax. For example, if your query uses a placeholder like $name, you would provide the parameters as {"name": "value"} in the operator. This allows you to write dynamic queries without having to concatenate strings. This is particularly useful when you want to execute the same query with different values, or use values from the Airflow context, such as task instance parameters or variables.

tests/system/neo4j/example_neo4j_query.py[source]


neo4j_task = Neo4jOperator(
    task_id="run_neo4j_query_with_parameters",
    neo4j_conn_id="neo4j_conn_id",
    parameters={"name": "Tom Hanks"},
    sql='MATCH (actor {name: $name, date: "{{ds}}"}) RETURN actor',
    dag=dag,
)

Was this entry helpful?