Skip to main content

Simple and fast graph operations written in Rust

Project description

rust-graph

image PyPI - Downloads image image Actions status

Ruff rustfmt Actions status
Ruff Clippy Actions status
pytest cargo test Actions status
uv Actions status

Graph algorithms implemented in Rust, available as a Python package. >10x faster than networkx.

So far, there is only one function implemented: all_pairs_dijkstra_path_length. It's a re-write of the networkx function with the same name and should return the same results.

🛠️ Installation

pip install rust-graph

🚦 Usage

from rust_graph import all_pairs_dijkstra_path_length

weighted_edges = [
    (0, 1, 1.0),
    (1, 2, 2.0),
    (2, 3, 3.0),
    (3, 0, 4.0),
    (0, 3, 5.0),
]

shortest_paths = all_pairs_dijkstra_path_length(weighted_edges, cutoff=3.0)
>>> shortest_paths
{3: {3: 0.0, 2: 3.0}, 2: {2: 0.0, 1: 2.0, 0: 3.0, 3: 3.0}, 1: {0: 1.0, 2: 2.0, 1: 0.0}, 0: {1: 1.0, 0: 0.0, 2: 3.0}}

📈 Benchmark

Tried a couple of options but failed for various reasons. Here are some notes on them:

  • cugraph:
    • Slower than networkx for the test data.
    • Not available on PyPI, only supports python 3.10 (and not above) and some dependencies were broken, making it difficult to set up.
  • rustworkx:
    • cutoff parameter is not implemented.
    • Extremely slow when the output is too large, because it returns lazy types rather than the actual values and converting it is probably not memory efficient.

Thus, we compare the performance of networkx and rust-graph for the all_pairs_dijkstra_path_length function.

MacBook Pro (M1)

23x as fast as networkx:

networkx Dijkstra took 4.45 s
rust-graph Dijkstra took 0.19 s

Personal laptop (AMD Ryzen R7 5800H (8 cores, 20MB total cache, 3.2 GHz, boost up to 4.4 GHz))

12x as fast as networkx:

networkx Dijkstra took 6.83 s
rust-graph Dijkstra took 0.57 s

If not using rayon parallelism, it's twice as slow:

networkx Dijkstra took 7.12 s
rust-graph Dijkstra took 1.04 s

Azure server (AMD EPYC 7V13 64-Core Processor)

CPU info:

    Model name:            AMD EPYC 7V13 64-Core Processor
    CPU family:          25
    Model:               1
    Thread(s) per core:  1
    Core(s) per socket:  48

15x as fast as networkx:

networkx Dijkstra took 6.14 s
rust-graph Dijkstra took 0.41 s

👨‍💻️ Maintenance Notes

Install from source

Install uv, rustup and maturin. Activate a virtual environment. Then,

bash scripts/install.sh
uv pip install -r deps/requirements_dev.in
python3 scripts/hf_download.py  # Download test data

Run benchmarks

python3 tools/benchmark.py

Compile requirements (generate lockfiles)

Use GitHub Actions: apply-pip-compile.yml. Manually launch the workflow and it will make a commit with the updated lockfiles.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rust_graph-0.1.0.tar.gz (12.4 kB view hashes)

Uploaded Source

Built Distributions

rust_graph-0.1.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (303.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rust_graph-0.1.0-pp310-pypy310_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (359.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rust_graph-0.1.0-pp310-pypy310_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (343.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

rust_graph-0.1.0-pp310-pypy310_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (320.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

rust_graph-0.1.0-pp310-pypy310_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (314.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rust_graph-0.1.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (314.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rust_graph-0.1.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (303.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

rust_graph-0.1.0-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (360.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rust_graph-0.1.0-pp39-pypy39_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (343.9 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

rust_graph-0.1.0-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (320.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

rust_graph-0.1.0-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (315.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rust_graph-0.1.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (315.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rust_graph-0.1.0-pp38-pypy38_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (360.8 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

rust_graph-0.1.0-pp38-pypy38_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (343.7 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

rust_graph-0.1.0-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (315.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

rust_graph-0.1.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (315.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

rust_graph-0.1.0-cp312-none-win_amd64.whl (157.3 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

rust_graph-0.1.0-cp312-none-win32.whl (153.6 kB view hashes)

Uploaded CPython 3.12 Windows x86

rust_graph-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (301.6 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

rust_graph-0.1.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (350.0 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ s390x

rust_graph-0.1.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (341.7 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

rust_graph-0.1.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl (319.2 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686

rust_graph-0.1.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (313.8 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARMv7l

rust_graph-0.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (313.9 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

rust_graph-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (261.6 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

rust_graph-0.1.0-cp312-cp312-macosx_10_12_x86_64.whl (265.4 kB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

rust_graph-0.1.0-cp311-none-win_amd64.whl (157.2 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

rust_graph-0.1.0-cp311-none-win32.whl (153.8 kB view hashes)

Uploaded CPython 3.11 Windows x86

rust_graph-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (302.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

rust_graph-0.1.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (355.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

rust_graph-0.1.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (342.7 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

rust_graph-0.1.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl (319.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686

rust_graph-0.1.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (314.2 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

rust_graph-0.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (313.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

rust_graph-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (262.2 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

rust_graph-0.1.0-cp311-cp311-macosx_10_12_x86_64.whl (266.2 kB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

rust_graph-0.1.0-cp310-none-win_amd64.whl (157.3 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

rust_graph-0.1.0-cp310-none-win32.whl (153.9 kB view hashes)

Uploaded CPython 3.10 Windows x86

rust_graph-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (302.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

rust_graph-0.1.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (356.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

rust_graph-0.1.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (342.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

rust_graph-0.1.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl (319.9 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686

rust_graph-0.1.0-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (314.4 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

rust_graph-0.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (313.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

rust_graph-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (262.3 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

rust_graph-0.1.0-cp310-cp310-macosx_10_12_x86_64.whl (266.4 kB view hashes)

Uploaded CPython 3.10 macOS 10.12+ x86-64

rust_graph-0.1.0-cp39-none-win_amd64.whl (157.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

rust_graph-0.1.0-cp39-none-win32.whl (153.8 kB view hashes)

Uploaded CPython 3.9 Windows x86

rust_graph-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (302.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

rust_graph-0.1.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (358.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

rust_graph-0.1.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (343.1 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

rust_graph-0.1.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (319.9 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686

rust_graph-0.1.0-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (314.7 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

rust_graph-0.1.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (314.0 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

rust_graph-0.1.0-cp39-cp39-macosx_11_0_arm64.whl (262.8 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

rust_graph-0.1.0-cp39-cp39-macosx_10_12_x86_64.whl (266.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.12+ x86-64

rust_graph-0.1.0-cp38-none-win_amd64.whl (157.0 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

rust_graph-0.1.0-cp38-none-win32.whl (153.6 kB view hashes)

Uploaded CPython 3.8 Windows x86

rust_graph-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (302.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

rust_graph-0.1.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (357.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

rust_graph-0.1.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (342.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

rust_graph-0.1.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl (319.3 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686

rust_graph-0.1.0-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (314.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

rust_graph-0.1.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (313.8 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page