CypherModel is a Python library for working with graph databases that speak Cypher, Memgraph and Neo4j, from Python objects. It is designed to be asynchronous end to end, strictly typed, and to keep Cypher one step away rather than hiding it.
The project in detail
It is aimed at FastAPI applications that read and write a graph, like the knowledge graph projects where I use Neontology today, ScienceProtect first among them. It follows the path SQLModel opened for SQL databases: a thin layer on top of Pydantic and a solid driver, here the asynchronous Neo4j Python driver, which both Neo4j and Memgraph recommend. It also stands on what others built: Neontology, which I contributed to, for Pydantic first graph models and relationship classes, and neomodel for a complete asynchronous OGM on Neo4j.
A node is a Pydantic model: the same class validates a request, documents the OpenAPI schema and maps to the graph. A relationship is a model in its own right, with its properties, its source and its target, not an attribute hidden in a node. A typed query builder covers the common cases, and hand written Cypher with typed results covers the rest. Writes are batched with `UNWIND`, and concurrent writers that share a node can be serialized instead of fighting over it.
The library is designed in the open: its site describes the target API before the first version, so the choices are discussed before they are set. It will be published on PyPI under the MIT licence, for Python 3.11 and above, and its code is public on GitHub.