TGraphX, PyG, DGL, and NetworkX: A Tool Selection Matrix
These four tools cover different parts of graph learning and graph analytics. The useful question is not which one is best, but which one fits the task in front of you.
Scope of this comparison (checked 26 November 2026). The TGraphX examples were run with TGraphX 1.5.1 on CPU, and the PyTorch Geometric (PyG) behaviour shown was checked with PyG 2.8.1. NetworkX 3.7 was used for the conversion example. DGL was not installed or executed: statements about it come from its GitHub repository (source and releases), PyPI and the TGraphX and DGL comparison. Its documentation site was not available (see the warning in the DGL section). Before you decide, check the DGL repository and the current documentation of PyG, NetworkX and TGraphX.
Quick Reference
| Tool | Primary scope | Status |
|---|---|---|
| TGraphX | Graph learning with tensor-valued node features | Beta; several subsystems are Experimental |
| PyG | General-purpose GNNs on PyTorch | Mature and widely used |
| DGL | GNNs, including large and distributed graphs | Newest GitHub release: 2.4.0 (September 2024); do not use dgl.ai addresses for now |
| NetworkX | Graph analytics and algorithms (no GNN layers) | Mature and widely used |
TGraphX: Tensor-Valued Node Features
TGraphX is a Beta, MIT-licensed library for PyTorch. A node feature can be a
vector [F], an image-like tensor [C, H, W] or a volume [C, D, H, W], and it
has message-passing layers that keep the spatial axes.
It ships:
- construction-time checks on shapes, devices and the range of
edge_index - spatial layers (convolutional, SAGE, GAT, GIN) and vector layers (GCN, GATv2, APPNP)
- neighbour, GraphSAINT and Cluster-GCN sampling (Beta)
- graph mining and algorithms, knowledge graph embeddings, and Experimental heterogeneous and temporal modules
- training helpers, CSV, TensorBoard and MLflow loggers, and JSON writers
Limitations to weigh:
- the API can still change, so pin the version
- no distributed graph store for training on a partitioned graph
- a much smaller layer collection than PyG or DGL
- a young project, so expect fewer third-party examples
- verify analytics results: in 1.5.1, for instance,
mining.modularityreturns wrong values andmining.betweenness_centralityreturns twice the values that NetworkX gives for the same undirected graph.mining.pagerankis also wrong when some node has no outgoing edge (the scores sum to less than 1): divide by the sum or usenx.pagerank
A short check of three of the features listed under "It ships":
import torch
from tgraphx import Graph, NeighborLoader, mining
torch.manual_seed(0)
g = Graph(node_features=torch.randn(100, 3, 8, 8), # image-like node features
edge_index=torch.randint(0, 100, (2, 400)),
node_labels=torch.randint(0, 3, (100,)))
# 1. Out-of-range node IDs are rejected when the graph is built
try:
Graph(node_features=torch.randn(5, 4), edge_index=torch.tensor([[0], [9]]))
except ValueError as err:
print("rejected:", err)
else:
raise AssertionError("expected a ValueError")
# 2. Neighbour sampling; pass the seed nodes explicitly with mask=
train_mask = torch.arange(100) < 60
batch = next(iter(NeighborLoader(g, fanouts=[5, 3], mask=train_mask,
batch_size=16, seed=0)))
print(batch.batch_size, tuple(batch.node_features.shape[1:])) # 16 (3, 8, 8)
# 3. Graph algorithms take (edge_index, num_nodes)
scores = mining.pagerank(g.edge_index, g.num_nodes)
scores = scores / scores.sum() # 1.5.1 loses score at nodes with no outgoing edge
print(tuple(scores.shape)) # (100,)
PyG (PyTorch Geometric): A Broad GNN Library
PyG is a widely used PyTorch library for graph neural networks.
It offers:
- a large collection of convolution layers, models and datasets
NeighborLoader,LinkNeighborLoader, cluster and GraphSAINT loaders- heterogeneous graphs (
HeteroData,to_hetero), knowledge graph embeddings (torch_geometric.nn.kge) and explainability tools - GraphGym for configuration-driven experiments
Limitations to weigh:
- some features need compiled extensions. In 2.8.1,
NeighborLoaderraises anImportErrorunlesspyg-libortorch-sparseis installed. Datacan hold node tensors of any shape, but most built-in convolutions expect[N, F]; image-valued nodes usually mean writing or adapting a layer- a large API surface to learn
See TGraphX versus PyTorch Geometric for a closer look.
DGL: Large and Distributed Graphs
DGL (Deep Graph Library) stores features in ndata and edata dictionaries on a
graph object and expresses message passing as message and reduce functions.
Warning: the dgl.ai domain. When checked on 26 and 27 November 2026,
dgl.ai, which hosted DGL's documentation, wheel index and datasets, showed a
registrar page reading "Domain registration has expired", or failed to connect
over HTTPS. Do not install wheels or download dgl.data datasets from any
*.dgl.ai address until you can confirm that the DGL project controls the domain
again. Use the GitHub repository for the source
code and issues.
It offers:
- a large set of layers and mini-batch samplers (
dgl.dataloading) dgl.distributedfor training on a graph partitioned across machines- heterogeneous graphs
- dataset classes in
dgl.data. Many of them download fromdata.dgl.aiby default, so the warning above applies to them - DGL-KE, a separate package for knowledge graph embeddings
Limitations to weigh:
- check maintenance and compatibility first. The newest release listed on
GitHub is 2.4.0 from September 2024, and the newest Linux x86-64
dglwheel on PyPI is 2.1.0 (checked 27 November 2026). Confirm there is a build for your Python, PyTorch and CUDA versions that you can get from a source you trust. - the DGL team has announced the deprecation of its MXNet and TensorFlow backends, so treat it as a PyTorch library for new work
See the feature-by-feature TGraphX and DGL comparison for the detailed trade-offs.
NetworkX: Graph Analytics, Not GNNs
NetworkX is a Python library for creating, analysing and manipulating graphs.
It offers:
- a broad algorithm library: paths, centrality, communities, flows, matching, spectral tools and more
- convenient graph construction and basic drawing through matplotlib
- many file formats, including GraphML, GML, edge lists and adjacency lists
Limitations to weigh:
- no neural network layers or automatic differentiation
- the default implementation uses Python data structures, which becomes slow
and memory-hungry on large graphs. Optional dispatch backends (for example
nx-cugraphon NVIDIA GPUs) can accelerate supported algorithms.
TGraphX versus NetworkX covers how the two fit together.
Tool Selection Matrix
| Need | TGraphX 1.5.1 | PyG 2.8 | DGL 2.4 | NetworkX 3 |
|---|---|---|---|---|
Vector node features [N, F] |
Built in | Built in, many layers | Built in, many layers | No learning |
Node features [N, C, H, W] or [N, C, D, H, W] |
Built-in layers | Store; write or adapt layer | Store; write or adapt layer | No learning |
Sequence node features [N, T, D] |
Store only; no layer designed for them (some vector layers accept them silently) | Custom layer | Custom layer | No learning |
| Neighbour sampling | Built in (Beta) | Built in; needs pyg-lib or torch-sparse |
Built in | No |
| Partitioned graph across machines | No (DDP helpers only) | Separate cuGraph-PyG package (NVIDIA GPUs); torch_geometric.distributed deprecated since 2.7 |
dgl.distributed |
No |
| Heterogeneous graphs | Experimental | Built in | Built in | Attributes only; no learning |
| Knowledge graph embeddings | Beta and Experimental parts | Built in | Scoring modules; DGL-KE separate | No |
| Graph algorithms | Centrality, paths, flows, communities and more (smaller than NetworkX) | Some utilities | Some utilities | Broad |
| Drawing graphs | Basic (matplotlib) | Basic subgraph views | Convert to NetworkX | Basic (matplotlib) |
| Out-of-range edge IDs at construction | Rejected | Accepted by Data(); validate() rejects |
Rejected if num_nodes is given |
Edges create the nodes |
| Config-driven experiments | Minimal Runner, GridRunner |
GraphGym | Not in the core package | No |
Two rows need a note. TGraphX's Runner is a minimal runner: it trains on one
full batch and computes no validation loss, so do not count on it for model
selection. On node tasks it also ignores masks set with
Graph(train_mask=...), so the loss covers validation and test nodes; write
your own loop for node classification or regression. And PyG's check is
explicit rather than automatic, as this shows (it needs torch_geometric
installed):
from torch_geometric.data import Data
bad = Data(x=torch.randn(5, 4), edge_index=torch.tensor([[0], [9]])) # accepted
try:
bad.validate()
except ValueError as err:
print("validate():", err)
else:
raise AssertionError("expected a ValueError")
Combining Tools
These libraries are often used together.
NetworkX to TGraphX
Analyse the topology in NetworkX, attach features, then convert with
Graph.from_networkx. It relabels nodes to 0..N-1 and, for an undirected
graph, adds both edge directions. Pass node_feature_key; without it every node
gets a single zero feature. Edge attributes are not carried over.
import networkx as nx
from tgraphx import Graph
nx.write_graphml(nx.karate_club_graph(), "karate.graphml")
G = nx.read_graphml("karate.graphml") # node IDs come back as strings
clustering = nx.clustering(G)
for node in G.nodes:
G.nodes[node]["x"] = [float(G.degree(node)), clustering[node]]
nx_graph = Graph.from_networkx(G, node_feature_key="x")
node_ids = list(G.nodes) # row i of the tensors is node_ids[i]
print(nx_graph.num_nodes, nx_graph.num_edges, nx_graph.feature_shape) # 34 156 (2,)
TGraphX and PyG
tgraphx.interop converts data objects in both directions (data only, not
models). from_pyg_data copies only x, edge_index, edge_weight,
edge_attr and y. Other attributes, including train, validation and test
masks, are not copied, so reattach them. Build the new graph from the
converted one and pass its fields on; a field you leave out, such as the edge
weights, is lost without an error.
from tgraphx.interop import from_pyg_data, to_pyg_data
data = to_pyg_data(g)
data.edge_weight = torch.rand(g.num_edges)
data.edge_attr = torch.rand(g.num_edges, 4)
data.train_mask = train_mask
back = from_pyg_data(data)
print(back.feature_shape, back.train_mask) # (3, 8, 8) None
back = Graph(node_features=back.node_features, edge_index=back.edge_index,
edge_weight=back.edge_weight, edge_features=back.edge_features,
node_labels=back.node_labels, graph_label=back.graph_label,
train_mask=data.train_mask) # val_mask, test_mask likewise
print(int(back.train_mask.sum())) # 60
print(tuple(back.edge_weight.shape), back.edge_feature_shape) # (400,) (4,)
In the other direction, to_pyg_data does not set data.train_mask either (a
Graph's masks end up under data.metadata["masks"]), and it does not export
edge_labels or graph_features.
tgraphx.interop also has to_dgl_graph and from_dgl_graph. They need DGL and
were not run for this article.
Making the Decision
Ask in this order:
- Do you only need graph algorithms, with no learning? Use NetworkX.
- Must you train on a graph partitioned across machines? Look at DGL's
dgl.distributed(after checking compatibility) or, on NVIDIA GPUs, the cuGraph-PyG examples that PyG's deprecation notice points to. PyG's owntorch_geometric.distributedis deprecated since 2.7, and its pure-PyTorch multi-GPU and multi-node tutorials split the training nodes between processes, not the graph. Neither DGL nor cuGraph-PyG was run for this article. TGraphX does not provide this. - Are node features images or volumes that should keep their layout during message passing? TGraphX has built-in layers for that. PyG or DGL also work if you are willing to write the layer.
- Do you need many published architectures and benchmark datasets? Start
with PyG. DGL also has many layers, if you can get a build that fits your
environment, but do not download its datasets while the
dgl.aiwarning above applies. - Do you need an API that has been stable for years? Prefer a mature library over a Beta one.
- None of these? PyG is a reasonable default, with a large layer and dataset collection and many published examples.
There is no universally correct answer, and a project can use more than one: NetworkX for analysis, one GNN library for training. If the experiment helpers are what draws you to TGraphX, the research-engineering positioning note goes further, including what stays your responsibility.