cypher-dsl-python
Build Cypher queries as Python syntax objects and render them to Cypher text plus parameters. The AST vocabulary and rendering behaviour follow the Java Neo4j Cypher-DSL. This is not an official Neo4j product.
The library covers a read and write subset of Cypher 5, plus the Cypher 25 syntax it
models. The Supported Cypher page linked below lists what that covers. It has no runtime
dependencies, ships py.typed and never opens a connection. Drivers, transactions and
schema installation belong to the application or its test harness.
Documentation
The user guide and API reference are published at https://neo-technology-field.github.io/cypher-dsl-python/. The Supported Cypher page lists which cheat-sheet features the builders cover.
Install
pip install cypher-dsl
In a uv project, use uv add cypher-dsl. Python 3.11 to 3.15 are supported.
Build and render a statement
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"])
rendered = Renderer.get(Configuration(server_version="5.26")).render(statement)
print(rendered.cypher)
print(rendered.parameters)
MATCH (m:Movie) WHERE m.released < $year RETURN m.title
{'year': 2000}
Bind a value to a parameter
param(name) is unbound and param(name, value) is bound. A render puts bound values in
parameters and the remaining names in unbound_parameters:
from cypher_dsl import Configuration, Renderer, match, node, param
person = node("Person", name="p")
statement = match(person).where(person["email"] == param("email")).returning(person["display_name"])
rendered = Renderer.get(Configuration(server_version="5.26")).render(statement)
print(rendered.cypher)
print(rendered.parameters)
print(sorted(rendered.unbound_parameters))
MATCH (p:Person) WHERE p.email = $email RETURN p.display_name
{}
['email']
A bare string in a projection is a variable name, so a string value needs lit().
Literals are snapshotted at construction, and inline bytes is rejected in favour of a
bound parameter.
Choose a target
server_versionis required. Declare the Neo4j release the rendered text will run on, such asConfiguration(server_version="5.26"). Neo4j 5.26 LTS is the minimum. Earlier 5.x releases and 4.x are unsupported.Language.AUTOis the default. It selects a language per statement from the syntax requirements, not the newest language the server offers. Statements without a language floor remain unprefixed.- Pin
Language.CYPHER_5orLanguage.CYPHER_25when the text must always name its language. ACYPHER 25pin requires Neo4j 2025.06. Every supported release accepts theCYPHER 5prefix. Pinning also rejects syntax that requires a different language. Language.NONEsuppresses the prefix but still checks the declared release. The database's default language then decides the grammar. A compatible release does not guarantee that its configured default can parse the Cypher text.
from cypher_dsl import Configuration, Language
automatic = Configuration(server_version="2026.10")
cypher_5 = Configuration(server_version="2026.10", language=Language.CYPHER_5)
cypher_25 = Configuration(server_version="2026.10", language=Language.CYPHER_25)
database_default = Configuration(server_version="2026.10", language=Language.NONE)
The library never probes a server. The declared release is the single source of truth for capability checks.
See Choose a target for the release and language rules.
The pretty_print option renders multi-line text for reading. The default renders one line.
Where this comes from
The vocabulary is not mine. The general architecture, AST names, the rendering and escaping rules and many of the test scenarios come from the Java Cypher-DSL, which is Apache-2.0. Thanks to the authors and contributors of that project.
The correspondence was traced against the upstream repository at commit d3b17e42, one
commit after the 2025.3.6 release. NOTICE lists what was taken from where, and a test
module that ports scenarios names the upstream test file at the top of the module.
This is an independent project. It is not an official Neo4j product, and nothing here is endorsed or governed by Neo4j, Inc.
Work on the package
The user documentation is the Sphinx site under docs/. Contributor documentation is
repository-only Markdown and is not part of the published site:
- Architecture: the build walk, the lexical scope, the fragment layout and the validation boundary.
- Query walkthrough: one statement traced from Python calls through the build walk to Cypher text and parameters.
- Testing the package: what the unit suite guarantees, and the manual server audit of the rendered text.
- Architecture decisions: the accepted, superseded and rejected records.
make deps # uv sync --group dev --group test
make test # uv run --group test pytest
make matrix # every session once on every supported interpreter
make lint
make format-check
make typing
make docs # Sphinx build
make package # Nox package session: sdist, wheel, installed smoke test
make help lists the targets. Unit tests assert rendered text and parameters offline and
need no database. make cypher-audit checks the statements the suite renders against a
disposable Neo4j Enterprise container and needs a running Docker daemon. It uses the
rolling neo4j:enterprise image, pulling it only when the image is absent, and sends each
distinct render as EXPLAIN, so it checks parsing and planning without executing a query.
The report separates accepted statements, expected rejections, unexpected rejections and
unexpected acceptances. A rejection is expected only where a test marks it as deliberate.
Any other rejection is a genuine finding, not a reason to add an exemption. Run it when a
rendering rule, a documented example or a rendered-query test changes.
Licence
Apache-2.0. See LICENSE and NOTICE.
Metadata
Release files for cypher-dsl 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cypher_dsl-0.1.0.tar.gz | 621.5 kB | Without provenance | Details for cypher_dsl-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cypher_dsl-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for cypher_dsl-0.1.0-py3-none-any.whl |
Total release size: 752.1 kB
Release files / cypher_dsl-0.1.0.tar.gz
| Download URL | cypher_dsl-0.1.0.tar.gz |
|---|---|
| Size | 621.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9b9cd0d5a4213f23b9e10236c4c5d803df374b0eaa397a2a05cd5e4a9bb038b
|
|
BLAKE2b-256 checksum How to use checksums |
e59486e24f0b0e29de962102164a1a1049f14a90c7d84c49866b0ba6bc3cda2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / cypher_dsl-0.1.0-py3-none-any.whl
| Download URL | cypher_dsl-0.1.0-py3-none-any.whl |
|---|---|
| Size | 130.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
548f044dce38c262ebb964de02779efa7fbe9ce1f65412fc8f6e5dec14fb7d0a
|
|
BLAKE2b-256 checksum How to use checksums |
9da6aba609bc0bdeeedd0e8b951795d28ed115dede89a453261e60c969b6a6fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for cypher-dsl 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.