Skip to main content

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.0

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.0
File Size Uploaded Provenance Actions
jgrapht-2.0.0.tar.gz 306.6 kB Without provenance Details for jgrapht-2.0.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for jgrapht 2.0.0
File Actions
jgrapht-2.0.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for jgrapht-2.0.0-cp314-cp314-win_amd64.whl
jgrapht-2.0.0-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.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
jgrapht-2.0.0-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for jgrapht-2.0.0-cp314-cp314-macosx_11_0_arm64.whl
jgrapht-2.0.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for jgrapht-2.0.0-cp313-cp313-win_amd64.whl
jgrapht-2.0.0-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.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
jgrapht-2.0.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for jgrapht-2.0.0-cp313-cp313-macosx_11_0_arm64.whl
jgrapht-2.0.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for jgrapht-2.0.0-cp312-cp312-win_amd64.whl
jgrapht-2.0.0-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.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
jgrapht-2.0.0-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for jgrapht-2.0.0-cp312-cp312-macosx_11_0_arm64.whl
jgrapht-2.0.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for jgrapht-2.0.0-cp311-cp311-win_amd64.whl
jgrapht-2.0.0-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.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
jgrapht-2.0.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for jgrapht-2.0.0-cp311-cp311-macosx_11_0_arm64.whl
jgrapht-2.0.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for jgrapht-2.0.0-cp310-cp310-win_amd64.whl
jgrapht-2.0.0-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.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
jgrapht-2.0.0-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details for jgrapht-2.0.0-cp310-cp310-macosx_11_0_arm64.whl

Total release size: 64.6 MB

Release files / jgrapht-2.0.0.tar.gz

Download URL jgrapht-2.0.0.tar.gz
Size 306.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a1a9aac734cd40a7683a68fd8eeca28d843b69a0f187e11ff2e268c772a8512d
BLAKE2b-256 checksum
How to use checksums
0212c4a5fd288885478fe523b9412438e5b15020ad5746ab4c6a27633a9f3b6e
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.0-cp314-cp314-win_amd64.whl

Download URL jgrapht-2.0.0-cp314-cp314-win_amd64.whl
Size 4.4 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
097ae3d1fc1b83af48539c4e143e316fd21f90cb71884a4a445c2fcf6a3b3dd4
BLAKE2b-256 checksum
How to use checksums
9631175e51a1683e4277ac469c7a31fbe793839f1303df55baa04f902d6ea188
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.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL jgrapht-2.0.0-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
e3158cad22711172664ba24a3c326b6696ea4299cb08fad63bed6f6be4a34718
BLAKE2b-256 checksum
How to use checksums
ee04554a298731a380c488a7bd5f64b976ffab60ff8f9f409a46556effe340a7
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.0-cp314-cp314-macosx_11_0_arm64.whl

Download URL jgrapht-2.0.0-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
d457aa37a619dda85e287a1b9860833775c144bdbc48f0c5aee67d227d566c6c
BLAKE2b-256 checksum
How to use checksums
a7735ba9380d8557f39ee5a4a7b67d715fd9ba801a48328d1db9b7aaae27e756
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.0-cp313-cp313-win_amd64.whl

Download URL jgrapht-2.0.0-cp313-cp313-win_amd64.whl
Size 4.4 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
b793432e8ef7cbf0479ea427be1c0f2774ad549b38893504b2330179037476fa
BLAKE2b-256 checksum
How to use checksums
36a16dce4909137dcec35e5c1ed7822638b9590e158066d1201be85adae5b324
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.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL jgrapht-2.0.0-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
9597964046578cd2819e3f92e588baf0cbb79f7bf41af80f0a72d0df49f8faed
BLAKE2b-256 checksum
How to use checksums
ecfd015caea9031b0f21a4f6cbf42506c9501baeec8eadeea646205751da608c
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.0-cp313-cp313-macosx_11_0_arm64.whl

Download URL jgrapht-2.0.0-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
00ae13779df8f70bdcddf7f1aeca769f8a81e3cd023be1ff6cf4b587d8743dec
BLAKE2b-256 checksum
How to use checksums
064d6b07c18d028fc2fe499bd283c0686dc06f55dce99a38cddca9532d97c7df
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.0-cp312-cp312-win_amd64.whl

Download URL jgrapht-2.0.0-cp312-cp312-win_amd64.whl
Size 4.4 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
1b7df3d453fa00f765ae5c3ac44172adfb632c4cfd7ca5ae7771a77c0abc9810
BLAKE2b-256 checksum
How to use checksums
46cc38bbf5a58a12f5b18e8023410a52835bf7b331e5d8dd94619ee4db456b77
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.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL jgrapht-2.0.0-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
953dc5f4d68029ac1cfcd6bebcfc9dde22e254f6c62f8cbb47878da5a4584e9c
BLAKE2b-256 checksum
How to use checksums
4806ebb3f542f66086fa499403222f0ddfe363783cad71d7ae5288eb6adaaca1
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.0-cp312-cp312-macosx_11_0_arm64.whl

Download URL jgrapht-2.0.0-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
bbb94f2ed3fcc1109c237e68cd8cfb8498c787181e814024efc1337e2fe144ae
BLAKE2b-256 checksum
How to use checksums
5a14256a25acf64ba10dc4353ed64913fcb3e274b32f46a2e742fb5997881b0f
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.0-cp311-cp311-win_amd64.whl

Download URL jgrapht-2.0.0-cp311-cp311-win_amd64.whl
Size 4.5 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
09b5f3c41f67bf11c4271aaac6d98ce6bda1fccf0b92a986edd85afa682a70fc
BLAKE2b-256 checksum
How to use checksums
8d45cbc90a52c0c816de13860fd5b78a9772fa652b29afdecb8fa46002d9ea15
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.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL jgrapht-2.0.0-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
a3e42b9fdba0d8d8af0910ad0959d31a203ecb0a4d61f8c0754f8432d8de7d25
BLAKE2b-256 checksum
How to use checksums
6866db61132d16e8b4055924cce63be4027f62bc209a093973e955599d176218
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.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL jgrapht-2.0.0-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
9e3abd7f07732b63ceb73ca69066c1382876f7de3423c8c13be7c2b1578d9219
BLAKE2b-256 checksum
How to use checksums
aa8dbe32e5d980378af8f0eed7c8def8af61eafb09d5101e26e5103001c777df
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.0-cp310-cp310-win_amd64.whl

Download URL jgrapht-2.0.0-cp310-cp310-win_amd64.whl
Size 4.5 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
5d19ed38ad07170323f7751e51055afdb4f10fe12bca8e4f4db826a4c73b6011
BLAKE2b-256 checksum
How to use checksums
c2c8b8b093890c2bd8f1142d380e495cc6e3e7a91c9fdd28e3f1fa867856a97a
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.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL jgrapht-2.0.0-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
4ad6f1d56becb9abfc2844ef61d2c6f53d9faf2032b0f8c428abbd40ec2196bd
BLAKE2b-256 checksum
How to use checksums
c484a84a76c1886abdc48b2422acbb2665616cff158d849c7e922686ba37e956
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.0-cp310-cp310-macosx_11_0_arm64.whl

Download URL jgrapht-2.0.0-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
dfed8dd34bafd4b900526b830c893818a56b2f3e99d13f7a6b587dc815a1a7bd
BLAKE2b-256 checksum
How to use checksums
aa8c3feae18c8df0c5b992dca540807f5db7b6032a736e53af37821c922dbaa6
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.0

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