Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PyPI Python CI Documentation Status License: EPL-2.0 OR LGPL-2.1+

Python-JGraphT

Python bindings for the JGraphT graph library.

JGraphT is a free library that provides mathematical graph-theory objects and algorithms. It has very efficient and generic graph data structures and a sizeable collection of sophisticated algorithms, and it is written with stability, performance and interoperability in mind. It includes algorithms from many application domains, such as path planning, routing, network analysis, combinatorial optimization and computational biology.

The original library is written in Java. This package uses jgrapht, a Rust port of it (source), and is built with PyO3 and maturin. The result is a native, self-contained extension with no dependency on the JVM or on GraalVM.

This is JGraphT for Python 2.0, a complete rewrite that replaces the 1.x jgrapht package, which wrapped the GraalVM-built jgrapht-capi shared library. It is not backward compatible with 1.x.

Features

  • Two graph classes. Graph is mutable; its vertices and edges are any hashable Python objects. SparseGraph is immutable and compact, with the integer vertices 0..n-1 and edges 0..m-1. Every algorithm accepts both.
  • Algorithms (about 200 functions): shortest paths (Dijkstra, Bellman-Ford, A* with a Python heuristic, Floyd-Warshall, Johnson, k shortest paths, contraction hierarchies, transit nodes), spanning trees, maximum flow and minimum cuts, minimum-cost flow, matchings, connectivity and components, cycles and Eulerian tours, TSP heuristics, coloring, cliques and independent sets, isomorphism, centrality and other scores, clustering, planarity and drawing layouts, and more. See the API reference.
  • Generators: structured families, random graphs, the 44 named graphs and NETGEN flow instances, as either graph class.
  • Graph I/O: CSV, DIMACS, DOT, GEXF, GML, graph6, GraphML, JSON and TSPLIB are read; all of these except TSPLIB, plus LEMON, matrices and Visio, are written. Attributes, weights, event streams, and TSPLIB tours are supported.
  • Attributes: vertices, edges and the graph itself carry attribute dicts (g.vertex_attrs[v]["color"] = "red"), which the readers fill and the writers write.
  • Derived graphs: copies, induced and edge subgraphs, unions, reversed, undirected and re-weighted versions, and a read-only wrapper.
  • Drawing and conversion: jgrapht.drawing draws graphs with matplotlib, and jgrapht.convert converts to and from NetworkX and pydot. Both need the optional package they work with.

Examples

import jgrapht as jg

g = jg.Graph(weighted=True)
for v in "abcd":
    g.add_vertex(v)
g.add_edge("a", "b", edge="ab", weight=1.0)   # edge objects are any hashable; omit for ints
g.add_edge("b", "c", weight=2.0)
g.add_edge("c", "d", weight=1.0)
print(jg.shortest_path(g, "a", "d"))
# GraphPath(vertices=['a', 'b', 'c', 'd'], weight=4.0)

# compact immutable graph on vertices 0..n-1, edges numbered in input order
s = jg.SparseGraph(4, [(0, 1), (1, 2), (2, 3)], weights=[1.0, 2.0, 1.0])
print(jg.shortest_path(s, 0, 3).edges)         # [0, 1, 2]
print(jg.connected_components(s))              # [[0, 1, 2, 3]]

# generators and named graphs
p = jg.named_graph("petersen")
print(jg.girth(p), jg.diameter(p))             # 5 2.0
grid = jg.grid_graph(10, 10, sparse=True)

# reading and writing
text = jg.graph_to_string(p, "gml")
h = jg.parse_graph(text, "gml")
jg.write_graph(g, "graph.graphml", "graphml", vertex_id=str, edge_weights=True)
g2 = jg.read_graph("graph.graphml", "graphml", weighted=True)

Python callbacks are supported where the algorithm takes a function (A* heuristics, isomorphism predicates, vertex and edge attribute functions for export); an exception raised in a callback stops the algorithm and propagates to the caller. Failures of the library itself raise jgrapht.GraphError, a ValueError.

Installation

Prebuilt wheels for CPython 3.10 to 3.14 are published on PyPI for Linux (x86-64), Windows and macOS (Apple silicon). On a recent machine installing is as easy as:

pip install jgrapht

If your pip is old, upgrade it first:

pip install --upgrade pip
pip install jgrapht

To use a virtual environment, or to install in your user directory:

python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install jgrapht

pip install --user jgrapht      # alternatively, without a virtual environment

Check the installation:

python -c "import jgrapht; print(jgrapht.__version__)"

Drawing and conversion use optional packages, which you can install together with this one:

pip install "jgrapht[plot]"       # matplotlib, for jgrapht.drawing
pip install "jgrapht[networkx]"   # for jgrapht.convert.to_nx and from_nx
pip install "jgrapht[pydot]"      # for jgrapht.convert.to_pydot and from_pydot

Building from source

This needs Python 3.10+ and a Rust toolchain (stable, 1.88+). Cargo downloads the jgrapht and jgrapht-io crates from crates.io, so the build needs network access.

python3 -m venv .venv
source .venv/bin/activate
pip install maturin pytest
maturin develop          # builds the extension and installs it into the venv
pytest

Use maturin develop --release for an optimized build. Rebuild after every change in src/.

Documentation

Full documentation is at https://python-jgrapht.readthedocs.io: an API reference, tutorials, and an example gallery. The sources are in docs/ (Sphinx) and examples/; design notes are in docs/design/. See CHANGELOG.md for what each release adds.

To build the HTML documentation locally (warnings are errors):

pip install -e ".[docs]"
python -m sphinx -W -b html docs docs/_build/html

Development

  • src/ holds the extension: graph.rs and sparse.rs (the graph classes), labels.rs (dispatch from Python graphs to the Rust graph types), alg/ (one module per algorithm family), generators.rs and formats.rs.
  • tests/ holds the pytest suite, including ports of the jgrapht-io parity tests. A guard test requires every public name to appear in docs/api/ and every public callable to have a docstring.
  • .github/workflows/ holds the CI workflow and the manual TestPyPI and tag-triggered PyPI publishing workflows.

Citing

Are you using the software in your research? We would appreciate it if you cite the following publication. Citing software is as important as citing any other source. If you are not sure whether to cite something, Shouldacite can help you decide.

@article{jgrapht,
  title = {{J}{G}raph{T}--{A} {J}ava {L}ibrary for {G}raph {D}ata {S}tructures and {A}lgorithms},
  author = {Michail, Dimitrios and Kinable, Joris and Naveh, Barak and Sichi, John V.},
  year = {2020},
  issue_date = {May 2020},
  publisher = {Association for Computing Machinery},
  address = {New York, NY, USA},
  volume = {46},
  number = {2},
  journal = {ACM Trans. Math. Softw.},
  month = may,
  articleno = {16},
  numpages = {29},
}

License

This library may be used under the terms of either the

like the jgrapht crate and JGraphT. As a recipient, you may choose which license to receive the code under. This library is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer to the licenses for details.

SPDX-License-Identifier: EPL-2.0 OR LGPL-2.1-or-later

Author

(C) Copyright 2026, by Dimitrios Michail

Enjoy!

Metadata

Release files for jgrapht 2.0.0rc1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jgrapht 2.0.0rc1
File Size Uploaded Provenance Actions
jgrapht-2.0.0rc1.tar.gz 215.9 kB Without provenance Details for jgrapht-2.0.0rc1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for jgrapht 2.0.0rc1
File Actions
jgrapht-2.0.0rc1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for jgrapht-2.0.0rc1-cp314-cp314-win_amd64.whl
jgrapht-2.0.0rc1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details for jgrapht-2.0.0rc1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
jgrapht-2.0.0rc1-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for jgrapht-2.0.0rc1-cp314-cp314-macosx_11_0_arm64.whl
jgrapht-2.0.0rc1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for jgrapht-2.0.0rc1-cp313-cp313-win_amd64.whl
jgrapht-2.0.0rc1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for jgrapht-2.0.0rc1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
jgrapht-2.0.0rc1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for jgrapht-2.0.0rc1-cp313-cp313-macosx_11_0_arm64.whl
jgrapht-2.0.0rc1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for jgrapht-2.0.0rc1-cp312-cp312-win_amd64.whl
jgrapht-2.0.0rc1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for jgrapht-2.0.0rc1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
jgrapht-2.0.0rc1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for jgrapht-2.0.0rc1-cp312-cp312-macosx_11_0_arm64.whl
jgrapht-2.0.0rc1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for jgrapht-2.0.0rc1-cp311-cp311-win_amd64.whl
jgrapht-2.0.0rc1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details for jgrapht-2.0.0rc1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
jgrapht-2.0.0rc1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for jgrapht-2.0.0rc1-cp311-cp311-macosx_11_0_arm64.whl
jgrapht-2.0.0rc1-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for jgrapht-2.0.0rc1-cp310-cp310-win_amd64.whl
jgrapht-2.0.0rc1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details for jgrapht-2.0.0rc1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
jgrapht-2.0.0rc1-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details for jgrapht-2.0.0rc1-cp310-cp310-macosx_11_0_arm64.whl

Total release size: 64.5 MB

Release files / jgrapht-2.0.0rc1.tar.gz

Download URL jgrapht-2.0.0rc1.tar.gz
Size 215.9 kB
Tags Source
SHA-256 checksum
How to use checksums
58afa4769fecf7f5cb11f2fb121a8323531cdd8981955dce176e74f2b3aa34b5
BLAKE2b-256 checksum
How to use checksums
b4d5e0a19b4b1f29d81b3338301088ceedde79c630ff60dec2c034b476534c93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp314-cp314-win_amd64.whl

Download URL jgrapht-2.0.0rc1-cp314-cp314-win_amd64.whl
Size 4.4 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
0e96a32e6d45af70504fee97a8586daa93113ff60a965cfbc84ab66bc12c1970
BLAKE2b-256 checksum
How to use checksums
76b564bf94da3a0b1b57de9e50339b901d9d90df8ff4a6d8fc0fd192bba8cf73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL jgrapht-2.0.0rc1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 4.5 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
6f1d3297e25bf9a3458a0d6b3b9ec337ebc661bd9db689d836afbba774b49b9b
BLAKE2b-256 checksum
How to use checksums
0c37256c2a2560bf1a6df4d5441d1b99a78abf7fbe324aa49cada6334dc6e07a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp314-cp314-macosx_11_0_arm64.whl

Download URL jgrapht-2.0.0rc1-cp314-cp314-macosx_11_0_arm64.whl
Size 3.9 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
4a9d437ae6d4867599b033a6f4df3d473bf3f2c85e2943429958c923a843a824
BLAKE2b-256 checksum
How to use checksums
5bee470cd3ed1ebc8954702e0a923814d2eb242a1b83eeb21b29950d746316ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp313-cp313-win_amd64.whl

Download URL jgrapht-2.0.0rc1-cp313-cp313-win_amd64.whl
Size 4.4 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
489deb87ea10f2c9f4fa59df563d5673ed4a7ac2411ed463aa390613a6c13e74
BLAKE2b-256 checksum
How to use checksums
56ec9c2f2435b30043226a614dc5d5c9291f43206c2a25d6f089abe759497a89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL jgrapht-2.0.0rc1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 4.5 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7ebf06e2507d6487db2968b0153d14dbc3bc8cce6e5e2d3200aeef87873ea3f6
BLAKE2b-256 checksum
How to use checksums
e8957c52fec4bd58d5f5b06db18217622c3089a8dfccd4d7fcd6bbd1a933dc30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp313-cp313-macosx_11_0_arm64.whl

Download URL jgrapht-2.0.0rc1-cp313-cp313-macosx_11_0_arm64.whl
Size 3.9 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
49676ac0d3a4e51bb5ef4a17f2a7c395827ec4a9dc1c9dadab8d41ec084c6f7b
BLAKE2b-256 checksum
How to use checksums
3151b9bb3735d31d9ff553b01b0a2037eaf68c1e8d63c336299a1751f323cd39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp312-cp312-win_amd64.whl

Download URL jgrapht-2.0.0rc1-cp312-cp312-win_amd64.whl
Size 4.4 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
f970233d54f29f85275fc5fe715930393e348b5937f3b6d12c1da3795bbbc809
BLAKE2b-256 checksum
How to use checksums
dd08efea6c7b3d1a552f9c668da1cd022181c09673515b8dc0e1ea73a3b9de27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL jgrapht-2.0.0rc1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 4.5 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
67e958c330d4d09b91a666bcd5fe781e41b4bb5110dfae0ae696ce4c764f0a3b
BLAKE2b-256 checksum
How to use checksums
4ec8df50bd03159888593d015a49d7f41970232d48317cf2b7f82f9ef061c6ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp312-cp312-macosx_11_0_arm64.whl

Download URL jgrapht-2.0.0rc1-cp312-cp312-macosx_11_0_arm64.whl
Size 3.9 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
559234d042179944519b88329eea16d95018e992c9d5ff57fc130d9b446e899f
BLAKE2b-256 checksum
How to use checksums
d82cae94594d4d5b4815fff4e6600bf848559bc5831cd3e8f68b5978c0ec744a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp311-cp311-win_amd64.whl

Download URL jgrapht-2.0.0rc1-cp311-cp311-win_amd64.whl
Size 4.5 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
ba298d2ce2bf213667ee951ce17009714650374fdd8c4e024d123e0e9b681d4c
BLAKE2b-256 checksum
How to use checksums
745ab19b0b7082376f3231f375b6cfc479fcfeb14671d5f8c221e8b3fda8de0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL jgrapht-2.0.0rc1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 4.5 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ad569cf4b9cbe1be3ccb1d6d62181a391e09fc7115a9aa2d4a08186ed6cd1ac9
BLAKE2b-256 checksum
How to use checksums
a5d8099939e28a9ba4e8d43a0308a65b332506b50819856e0db9328855dd6075
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp311-cp311-macosx_11_0_arm64.whl

Download URL jgrapht-2.0.0rc1-cp311-cp311-macosx_11_0_arm64.whl
Size 3.9 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
523114087b718cc05ec728a3ecbf2aef614ed1012c74b27428abb62d5396ec62
BLAKE2b-256 checksum
How to use checksums
e7b16c9cafe4c6af0229aeba85e25ec15cd24b1230f7a17115d73c1663fffd5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp310-cp310-win_amd64.whl

Download URL jgrapht-2.0.0rc1-cp310-cp310-win_amd64.whl
Size 4.5 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
907ec6ef54fdacbb6e3c2c4d5457e56e344135b2a3e9df803894752bcf5a4235
BLAKE2b-256 checksum
How to use checksums
b4e99e9f226a4fbc410af4518508110cac8514f44e73e2dde746ccb022f8c431
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL jgrapht-2.0.0rc1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 4.5 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
833008068d9c9690218141310b0bc65167a7cbd06c4cf0c4c4806cf7f72d3933
BLAKE2b-256 checksum
How to use checksums
27bf46a30736d01f47f0df7cbe5c22bf033a2eb3f43d9a8ac5d9f401aed42cca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / jgrapht-2.0.0rc1-cp310-cp310-macosx_11_0_arm64.whl

Download URL jgrapht-2.0.0rc1-cp310-cp310-macosx_11_0_arm64.whl
Size 3.9 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
52775098f0144078089eb1c16b78377228d954eb612429f0fc86a999efff22df
BLAKE2b-256 checksum
How to use checksums
e2f84251d655d1544274a8de2ad8b36e66d4ed778734e02747fbd30b53f5db9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for jgrapht 2.0.0rc1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page