<a id="cypher-dsl"></a>

# cypher-dsl

Build Cypher queries as Python syntax objects and render them to Cypher text plus parameters. The library covers a read and write subset of Cypher 5, plus the Cypher 25 syntax it models. [Supported Cypher](support.md) lists exactly which cheat-sheet features it covers and which it does not. It does not connect to a database, so building a [statement](getting-started.md#statement) and executing it stay separate concerns.

```python
from cypher_dsl import Configuration, Renderer, match, node, param

movie = node("Movie", name="m")
statement = (
    match(movie)
    .where(movie["released"] < param("year", 2000))
    .returning(movie["title"])
)
renderer = Renderer.get(Configuration(server_version="5.26"))
rendered = renderer.render(statement)

assert rendered.cypher == (
    "MATCH (m:Movie) WHERE m.released < $year RETURN m.title"
)
assert rendered.parameters == {"year": 2000}
```

Rendering does not change the statement, and every render returns its own parameter dictionary: changing one result’s dictionary leaves the statement and other results alone. To reuse one query with different request values, build the parameter with `param(name)` and no value. The render reports it under `unbound_parameters`, and the code that runs the query supplies the value. Request data goes through `param()` and never through string interpolation.

# Guide

* [Getting started](getting-started.md)
  * [Install](getting-started.md#install)
  * [Build and render a statement](getting-started.md#build-and-render-a-statement)
  * [Read related nodes](getting-started.md#read-related-nodes)
  * [Filter before the next query part](getting-started.md#filter-before-the-next-query-part)
  * [Write and update data](getting-started.md#write-and-update-data)
  * [Combine conditions with operators](getting-started.md#combine-conditions-with-operators)
  * [Escape to raw expression text](getting-started.md#escape-to-raw-expression-text)
  * [What is not available](getting-started.md#what-is-not-available)
* [Supported Cypher](support.md)
  * [Read](support.md#read)
  * [Write](support.md#write)
  * [Patterns](support.md#patterns)
  * [Composed queries](support.md#composed-queries)
  * [Subqueries and procedures](support.md#subqueries-and-procedures)
  * [Expressions](support.md#expressions)
  * [Functions](support.md#functions)
  * [Targets](support.md#targets)
  * [What Neo4j checks](support.md#what-neo4j-checks)
  * [Not yet](support.md#not-yet)
  * [Not planned](support.md#not-planned)
* [Build graph patterns](patterns.md)
  * [Build a node pattern](patterns.md#build-a-node-pattern)
  * [Refer to a node without its label](patterns.md#refer-to-a-node-without-its-label)
  * [Test a label on a bound node](patterns.md#test-a-label-on-a-bound-node)
  * [Test an element during the match](patterns.md#test-an-element-during-the-match)
  * [Add labels to an existing pattern](patterns.md#add-labels-to-an-existing-pattern)
  * [Match labels with an expression](patterns.md#match-labels-with-an-expression)
  * [Connect two patterns](patterns.md#connect-two-patterns)
  * [Extend a chain across relationships](patterns.md#extend-a-chain-across-relationships)
  * [Quantify a relationship](patterns.md#quantify-a-relationship)
  * [Quantify a path pattern](patterns.md#quantify-a-path-pattern)
  * [Name a path](patterns.md#name-a-path)
  * [Trace a path across segments](patterns.md#trace-a-path-across-segments)
  * [Select which paths a `MATCH` returns](patterns.md#select-which-paths-a-match-returns)
  * [Reuse a bound pattern in a write](patterns.md#reuse-a-bound-pattern-in-a-write)
  * [What to watch out for](patterns.md#what-to-watch-out-for)
* [Read data](reading.md)
  * [Match several patterns at once](reading.md#match-several-patterns-at-once)
  * [Keep rows that have no match](reading.md#keep-rows-that-have-no-match)
  * [Build conditions with DSL operators](reading.md#build-conditions-with-dsl-operators)
  * [Test labels and types](reading.md#test-labels-and-types)
  * [Test a value’s type](reading.md#test-a-value-s-type)
  * [Test whether a path exists](reading.md#test-whether-a-path-exists)
  * [Filter an UNWIND through WITH](reading.md#filter-an-unwind-through-with)
  * [Call functions](reading.md#call-functions)
  * [Project, alias and widen](reading.md#project-alias-and-widen)
  * [Deduplicate, order and paginate](reading.md#deduplicate-order-and-paginate)
  * [Group explicitly](reading.md#group-explicitly)
  * [Compute values in the projection](reading.md#compute-values-in-the-projection)
  * [Choose between values with CASE](reading.md#choose-between-values-with-case)
  * [Project selected properties into a map](reading.md#project-selected-properties-into-a-map)
  * [Iterate a list inside an expression](reading.md#iterate-a-list-inside-an-expression)
  * [Test the elements of a list](reading.md#test-the-elements-of-a-list)
* [Write data](writing.md)
  * [Create nodes and relationships](writing.md#create-nodes-and-relationships)
  * [Merge on an explicit identity](writing.md#merge-on-an-explicit-identity)
  * [Set properties and labels](writing.md#set-properties-and-labels)
  * [Remove properties and labels](writing.md#remove-properties-and-labels)
  * [Delete nodes and relationships](writing.md#delete-nodes-and-relationships)
  * [Write a dynamic property name](writing.md#write-a-dynamic-property-name)
  * [Write a dynamic label or type](writing.md#write-a-dynamic-label-or-type)
* [Compose statements](composing.md)
  * [End a query part with WITH](composing.md#end-a-query-part-with-with)
  * [Combine statements with UNION](composing.md#combine-statements-with-union)
  * [Reuse and compare statements](composing.md#reuse-and-compare-statements)
  * [Build a statement from optional filters](composing.md#build-a-statement-from-optional-filters)
* [Call subqueries](subqueries.md)
  * [Import all, some or no variables](subqueries.md#import-all-some-or-no-variables)
  * [Keep rows the subquery drops](subqueries.md#keep-rows-the-subquery-drops)
  * [Write in batches](subqueries.md#write-in-batches)
  * [Process a UNION](subqueries.md#process-a-union)
  * [What the library checks](subqueries.md#what-the-library-checks)
  * [Test whether a subquery matches](subqueries.md#test-whether-a-subquery-matches)
  * [Count the rows of a subquery](subqueries.md#count-the-rows-of-a-subquery)
  * [Collect a subquery into a list](subqueries.md#collect-a-subquery-into-a-list)
  * [Calling procedures](subqueries.md#calling-procedures)
* [Call procedures](procedures.md)
  * [Call a procedure and read its output](procedures.md#call-a-procedure-and-read-its-output)
  * [Call a procedure on its own](procedures.md#call-a-procedure-on-its-own)
  * [Yield and rename output columns](procedures.md#yield-and-rename-output-columns)
  * [Filter the yielded rows](procedures.md#filter-the-yielded-rows)
  * [Render an optional procedure call](procedures.md#render-an-optional-procedure-call)
  * [Where a procedure call may appear](procedures.md#where-a-procedure-call-may-appear)
  * [What is not available](procedures.md#what-is-not-available)
* [Bind parameters](parameters.md)
  * [Put request data in a parameter](parameters.md#put-request-data-in-a-parameter)
  * [Bind one name once](parameters.md#bind-one-name-once)
  * [Write a constant into the text](parameters.md#write-a-constant-into-the-text)
  * [Tell names and values apart](parameters.md#tell-names-and-values-apart)
  * [Carry a value the library cannot copy](parameters.md#carry-a-value-the-library-cannot-copy)
  * [How names are quoted](parameters.md#how-names-are-quoted)
  * [What the renderer will not do](parameters.md#what-the-renderer-will-not-do)
* [Choose a target](targets.md)
  * [Let each statement select its language](targets.md#let-each-statement-select-its-language)
  * [Pin the language in the text](targets.md#pin-the-language-in-the-text)
  * [Suppress the prefix](targets.md#suppress-the-prefix)
  * [Quote every name](targets.md#quote-every-name)
  * [Render statements for reading](targets.md#render-statements-for-reading)
* [Render a statement](running.md)
  * [Get a renderer for your target](running.md#get-a-renderer-for-your-target)
  * [Read the render result](running.md#read-the-render-result)
  * [Supply the unbound values at execution](running.md#supply-the-unbound-values-at-execution)
  * [Log the text, not the values](running.md#log-the-text-not-the-values)
  * [Catch the library’s failures](running.md#catch-the-library-s-failures)

# Optional add-on

* [Model a graph](model.md)
  * [Declare the graph names](model.md#declare-the-graph-names)
  * [Build a query from the declarations](model.md#build-a-query-from-the-declarations)
  * [Rename a property in the declaration](model.md#rename-a-property-in-the-declaration)

# Reference

* [Catch the library’s own exceptions](errors.md)
  * [The classes](errors.md#the-classes)
  * [Where each family comes from](errors.md#where-each-family-comes-from)
* [API reference](api.md)
  * [Names in `cypher_dsl`](api.md#module-cypher_dsl)
  * [Exceptions](api.md#module-cypher_dsl.errors)
  * [The model subpackage](api.md#the-model-subpackage)
