close
Memgraph
Python

Graph databases. Pure Python.

Use GQLAlchemy to connect to Memgraph, map graph entities to Python objects, and query your data without writing Cypher. Full access to graph algorithms, streaming, and ML from Python.

GQLAlchemy

Manage graph data as Python objects

GQLAlchemy is Memgraph's object-graph mapper, similar to SQLAlchemy for relational databases. Define your graph schema as Python classes, validate data, and query with a fluent Python query builder instead of writing raw Cypher.

  • Map nodes and relationships to Python dataclasses
  • Built-in data validation and schema enforcement
  • Fluent query builder for complex graph queries
  • Access 60+ MAGE graph algorithms from Python
GQLAlchemy
recommendation.py
from gqlalchemy import Memgraph, Node, Field, match
from typing import Optional

memgraph = Memgraph("127.0.0.1", 7687)

# OGM - map nodes to Python classes
class Movie(Node):
    id: int = Field(index=True, unique=True, db=memgraph)
    title: Optional[str]

# Query builder
results = list(
    match()
    .node(labels="User", variable="u")
    .to(relationship_type="RATED")
    .node(labels="Movie", variable="m")
    .return_()
    .execute()
)

for row in results:
    print(row["m"])
custom_module.py
import mgp
import networkx as nx

# Define a custom Cypher procedure in Python
@mgp.read_proc
def betweenness(ctx: mgp.ProcCtx, node: mgp.Vertex
) -> mgp.Record(score=float):
    G = nx.Graph()
    for v in ctx.graph.vertices():
        G.add_node(v.id)
    scores = nx.betweenness_centrality(G)
    return mgp.Record(score=scores[node.id])
Custom procedures

Extend Cypher with your own Python logic

When built-in algorithms don't cover your use case, write custom query modules in Python and call them from Cypher. Edit and run them directly from Memgraph Lab without restarting the database.

  • Write custom procedures in Python, C, C++, or Rust
  • Use igraph and NetworkX inside your modules
  • Hot-reload procedures without restarting Memgraph
  • Call from Cypher: CALL my_module.procedure()
Custom modules docs
Custom procedures

Build with the community

GQLAlchemy and MAGE are open source. Implement graph algorithms, improve the Python client, and share modules with the community. The library grows when you contribute.

  • GQLAlchemy: open source OGM on GitHub
  • MAGE: contribute algorithms in Python or Rust
  • Discord community for graph analytics developers
  • Memgraph Academy: structured Python and graph courses
Github

Object-graph mapper for Memgraph - GQLAlchemy

Write Python instead of Cypher. Model your graph as Python dataclasses with full validation.

60+ graph algorithms, open source - MAGE

PageRank, community detection, GNNs, and more, all callable from Python or Cypher.

Capabilities

Built for the workloads Python developers run.

  • Performance

    Memgraph's in-memory C++ core handles real-time, concurrent, write-heavy workloads. You write Python. Memgraph handles the speed.

  • Algorithms

    All 60+ MAGE algorithms: PageRank, community detection, GNNs, node2vec. All callable directly from Python or via the query builder.

  • Flexibility

    Works with your existing Python stack. Native integrations with NetworkX, igraph, and NVIDIA cuGraph. Connectors for Kafka, Pulsar, and Redpanda for streaming pipelines.

Free courseMemgraph and Python: from first query to Jupyter Notebook

Create a graph model from a dataset, run Memgraph with Docker, connect via GQLAlchemy, and perform graph queries, all from a Jupyter Notebook.Watch for free

Tutorial ยท Blog postFraud detection with Python: importing data into Memgraph without Cypher

A Python-first walkthrough for building a fraud detection graph. No Cypher required. GQLAlchemy handles everything from data import to query execution.Read blog

Get started

Run Memgraph with your Python project.

ยฉ 2026 Memgraph Ltd. All rights reserved.