Why use OGM?
OGM provides a developer-friendly workflow. It allows for writing object-oriented notation to talk to a graph database. Instead of writing Cypher queries, you will be able to write object-oriented code which OGM will take and automatically translate into Cypher queries.
Why GQLAlchemy?
GQLAlchemy is a Python library developed to assist in writing and running queries on Memgraph and other Cypher-based graph databases.
As a Python developer, with GQLAlchemy you will be able to:
- automate object conversion between graph database objects and Python objects,
- write correct Cypher queries with checks inside IDEs,
- easily handles setting up Memgraph features like streaming, etc.
Example of defining a node in GQLAlchemy

What’s going on here:
- Node is a python class that maps to a graph object in Memgraph.
- Classes that inherit from Node map to a single label in a graph database.
- In this case the class User maps to the label :User.
- The properties id and name are map to properties of the nodes labelled User in the graph database, their types must be defined and are enforced.
- If the type of the property is missing the Optional keyword, then it cannot be None or missing.
- Field is a function from pydantic that you can use to define constraints in the graph database like uniqueness constraints, indexes and exists constraints.
- Whenever you provide a constraint to the Field function, you have to provide a Memgraph object in the db argument as well, so those constraints can be enforced.
- john1 is a User object that is created and saved to Memgraph in the following openCypher form: (john1 :User {id: 1, name: "John"}).
- john2 is a User object that is created only with an id property, but is then loaded from Memgraph making john1 and john2 represent the same node in Memgraph
- save or load methods set the internal id of the node, in this case john1._id and john2._id to an id that Memgraph uses, that id uniquely defines a node.
We'll showcase this code example and many more additional features on Februry 26th.
Join us then!