Skip to main content

pylmcf: Python bindings for Min Cost Flow solvers from the LEMON graph library

Overview

pylmcf provides Python bindings for the min-cost flow solvers implemented in the LEMON graph library. It enables efficient network flow optimization in Python applications. It is used by wnet (a Python package enabling the efficient computation of Wasserstein and Truncated Wasserstein distance between multidimensional distributions) and wnetalign (a Python package enabling efficient alignment of MS or NMR spectra).

Features

  • Fast min-cost flow computation using C++ backend (LEMON's Network Simplex by default)
  • Multiple solver variants: Network Simplex, Cycle Canceling, Cost Scaling, Capacity Scaling
  • Supports capacities, costs, supplies/demands, and per-edge lower bounds (minimum flow)
  • NetworkX integration: construct from nx.DiGraph or convert results back for visualization
  • C++ headers exposed for downstream packages that want to call the solver directly

Installation

pip install pylmcf

Optional extras for NetworkX support and visualization:

pip install pylmcf[extras]

Usage

Basic usage

import numpy as np
import pylmcf

# 3-node graph with edges 0→1, 0→2, 1→2
# Edges must be sorted by (start, end)
G = pylmcf.Graph(3,
    edge_starts=np.array([0, 0, 1]),
    edge_ends=np.array([1, 2, 2]))

G.set_node_supply(np.array([5, 0, -5]))   # node 0 supplies 5, node 2 demands 5
G.set_edge_costs(np.array([1, 3, 5]))
G.set_edge_capacities(np.array([3, 3, 5]))

G.solve()

G.result()      # np.array([2, 3, 2])  — flow on each edge
G.total_cost()  # 21

Per-edge lower bounds (minimum flow)

G.set_edge_minimums(np.array([3, 0, 0]))  # edge 0→1 must carry at least 3 units
G.solve()
G.result()      # np.array([3, 2, 3])
G.total_cost()  # 24

Constructing from a NetworkX graph

Note: Graph.FromNX() iterates over graph elements in Python and is significantly slower than constructing Graph directly from numpy arrays. Prefer the direct API for performance-sensitive code.

import networkx as nx

G_nx = nx.DiGraph()
G_nx.add_edge(0, 1, weight=1, capacity=3)
G_nx.add_edge(0, 2, weight=3, capacity=3)
G_nx.add_edge(1, 2, weight=5, capacity=5)
G_nx.nodes[0]["demand"] = -5
G_nx.nodes[2]["demand"] = 5

G = pylmcf.Graph.FromNX(G_nx)
G.solve()
G.result()      # np.array([2, 3, 2])

Alternative solvers

The default solver is LEMON's Network Simplex. Three alternatives are available via the low-level functional API:

from pylmcf import pylmcf_cpp
import numpy as np

a = lambda x: np.array(x, dtype=np.int64)
supply = a([5, 0, -5])
starts = a([0, 0, 1])
ends   = a([1, 2, 2])
caps   = a([3, 3, 5])
costs  = a([1, 3, 5])

flows = pylmcf_cpp.lmcf(supply, starts, ends, caps, costs)               # Network Simplex (default)
flows = pylmcf_cpp.lmcf_cycle_canceling(supply, starts, ends, caps, costs)
flows = pylmcf_cpp.lmcf_cost_scaling(supply, starts, ends, caps, costs)   # int32/int64 only
flows = pylmcf_cpp.lmcf_capacity_scaling(supply, starts, ends, caps, costs)  # int32/int64 only

Visualization

G.show()               # display with matplotlib
G.show("graph.png")    # save to file

C++ include path

If you want to call the LEMON solver from your own C++ extension:

python -m pylmcf --include

Requirements

  • Python 3.10+

Licence

pylmcf is published under the Boost Software Licence. LEMON (which resides in src/pylmcf/cpp/lemon) is also covered by the Boost Software Licence.

Citation

If you use this software, please cite:

Król J, Bochenek M, Jopa S, Kazimierczuk K, Gambin A, Startek MP (2026). WNetAlign: fast and accurate spectra alignment using truncated Wasserstein distance and network simplex. Briefings in Bioinformatics, 27(3), bbag247. https://doi.org/10.1093/bib/bbag247

@article{krol2026wnetalign,
  title   = {WNetAlign: fast and accurate spectra alignment using truncated Wasserstein distance and network simplex},
  author  = {Kr{\'o}l, Justyna and Bochenek, Maria and Jopa, Sylwia and Kazimierczuk, Krzysztof and Gambin, Anna and Startek, Micha{\l} Piotr},
  journal = {Briefings in Bioinformatics},
  volume  = {27},
  number  = {3},
  pages   = {bbag247},
  year    = {2026},
  doi     = {10.1093/bib/bbag247}
}

References

Metadata

Release files for pylmcf 1.2.1

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

Source distribution (sdist)

Source distribution for pylmcf 1.2.1
File Size Uploaded
pylmcf-1.2.1.tar.gz 262.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pylmcf 1.2.1
File
pylmcf-1.2.1-cp315-abi3t-win_arm64.whl CPython 3.15 abi3t Windows ARM64 Details
pylmcf-1.2.1-cp315-abi3t-win_amd64.whl CPython 3.15 abi3t Windows x86-64 Details
pylmcf-1.2.1-cp315-abi3t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.15 abi3t Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
pylmcf-1.2.1-cp315-abi3t-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.15 abi3t Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details
pylmcf-1.2.1-cp315-abi3t-macosx_11_0_arm64.whl CPython 3.15 abi3t macOS 11.0+ ARM64 Details
pylmcf-1.2.1-cp315-abi3t-macosx_10_15_x86_64.whl CPython 3.15 abi3t macOS 10.15+ x86-64 Details
pylmcf-1.2.1-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
pylmcf-1.2.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
pylmcf-1.2.1-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
pylmcf-1.2.1-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.24+ ARM64, Linux glibc 2.28+ ARM64 Details
pylmcf-1.2.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
pylmcf-1.2.1-cp310-abi3-macosx_10_15_x86_64.whl CPython 3.10 abi3 macOS 10.15+ x86-64 Details

Total release size: 7.3 MB

Release files / pylmcf-1.2.1.tar.gz

Download URL pylmcf-1.2.1.tar.gz
Size 262.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d3b6cc9ca49e0053880fd6340965629fe48f2e226456d0401ef06b644052bd7e
BLAKE2b-256 checksum
How to use checksums
cff004ce63e22faa8f8b1338b554ed9224d7db17da0763a1ccfc1ff75873caa8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / pylmcf-1.2.1-cp315-abi3t-win_arm64.whl

Download URL pylmcf-1.2.1-cp315-abi3t-win_arm64.whl
Size 801.7 kB
Tags CPython 3.15 Windows ARM64 abi3t
SHA-256 checksum
How to use checksums
cb9fc224df151e638b0b17ffbb1403ef7613fd5babe2cf03c3586beab5e0ecc8
BLAKE2b-256 checksum
How to use checksums
f970aede048da85f0ed995a330dd80bab17a8782dc1fb2984c2e35b7fa26c21c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / pylmcf-1.2.1-cp315-abi3t-win_amd64.whl

Download URL pylmcf-1.2.1-cp315-abi3t-win_amd64.whl
Size 624.4 kB
Tags CPython 3.15 Windows x86-64 abi3t
SHA-256 checksum
How to use checksums
344d90f9a64c6eb0e8895a8355eb47d991eac0c1d629299398633522def4704c
BLAKE2b-256 checksum
How to use checksums
6c6a6fec9230bd5e59efb39cb3a7ae74369528ca7ebbf7aa575f607020e2133d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / pylmcf-1.2.1-cp315-abi3t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL pylmcf-1.2.1-cp315-abi3t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 539.3 kB
Tags CPython 3.15 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 abi3t
SHA-256 checksum
How to use checksums
f28daa7d0fbe4d367c9add46bbac91689e35064e495d6b5f26bf14c5a9cd37d7
BLAKE2b-256 checksum
How to use checksums
2032060983427dbbffc12f3d4de222b90bebe7eb84d4549eedf8e8ce5a9474ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / pylmcf-1.2.1-cp315-abi3t-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL pylmcf-1.2.1-cp315-abi3t-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 497.6 kB
Tags CPython 3.15 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 abi3t
SHA-256 checksum
How to use checksums
1d71cc1f723942073a7963106c6dddcf993e46a7b8211e5662ad97e231c1decb
BLAKE2b-256 checksum
How to use checksums
1b68ca0e8f9d310f68e1868ada6fdaf744dfc719ce12c0d2b4d0a9b8c2348ee3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / pylmcf-1.2.1-cp315-abi3t-macosx_11_0_arm64.whl

Download URL pylmcf-1.2.1-cp315-abi3t-macosx_11_0_arm64.whl
Size 506.9 kB
Tags CPython 3.15 abi3t macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
054be45d394b972ef7ddd4f1c2bcec3fcda56ca251ef305293f01597b5efef0a
BLAKE2b-256 checksum
How to use checksums
255483eee878b837ab55db50ec4421f86add8291ecbeef875778685d179bb2b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / pylmcf-1.2.1-cp315-abi3t-macosx_10_15_x86_64.whl

Download URL pylmcf-1.2.1-cp315-abi3t-macosx_10_15_x86_64.whl
Size 539.6 kB
Tags CPython 3.15 abi3t macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
85a78673352d0098d35db2a289df859f5f3dcccbc6bd5d87fcd5c1078116642c
BLAKE2b-256 checksum
How to use checksums
01b2d8837e922b649ae74761a4dbaba508e9cd52d2e31f9d7431cbebe4719ce3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / pylmcf-1.2.1-cp310-abi3-win_arm64.whl

Download URL pylmcf-1.2.1-cp310-abi3-win_arm64.whl
Size 784.0 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
4027a91f5e58fa53e01c5756eae3f8ffa5520e1e1ef860e8f5fda9b5b3a7d60f
BLAKE2b-256 checksum
How to use checksums
b84d557477583e9b372d9957cb3df911029f6b4d5e9b687874790825ce0bc2ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / pylmcf-1.2.1-cp310-abi3-win_amd64.whl

Download URL pylmcf-1.2.1-cp310-abi3-win_amd64.whl
Size 613.9 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
076c66344dbf08a0ba84d773bc3e0067c9f617ab502baee9e7a61f6f54c456ab
BLAKE2b-256 checksum
How to use checksums
a29172a21294857543fe194acd1b25202907d3f696e772d29e065c37974ca07d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / pylmcf-1.2.1-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL pylmcf-1.2.1-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 539.7 kB
Tags CPython 3.10 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
8d30bdaf2d9ddcfc5d8e7f28b646d6f72942b2ae123afe5a1af928e03f9f7210
BLAKE2b-256 checksum
How to use checksums
38f2b32d67085af6b333593764afc649f3762407411e4de943050ad3df99bc3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / pylmcf-1.2.1-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL pylmcf-1.2.1-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 500.1 kB
Tags CPython 3.10 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
cd4df6ab342cc7ccd32b94c5ac24e522af772d5f3c950728e52a9f4d767f2cdd
BLAKE2b-256 checksum
How to use checksums
8de59857343c6441add76226798833775091cd521c05f3465180d0a808b5d80d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / pylmcf-1.2.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL pylmcf-1.2.1-cp310-abi3-macosx_11_0_arm64.whl
Size 506.7 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
776fae6ef51691cfd2100b33df375f59f34fcca984e26daeb69f9c1134dac896
BLAKE2b-256 checksum
How to use checksums
f60e2035effbb87d208f09cca7eef2ce4960df75b86b16f4d6c9b86201534250
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release files / pylmcf-1.2.1-cp310-abi3-macosx_10_15_x86_64.whl

Download URL pylmcf-1.2.1-cp310-abi3-macosx_10_15_x86_64.whl
Size 539.0 kB
Tags CPython 3.10 abi3 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
8ddf27b73ed89ab5e1336f955c68eaa0ed8085ed47e9d24c7da3577bc5733cb7
BLAKE2b-256 checksum
How to use checksums
a1b02291873a3b0f1649023ce3f2ea7f2939f80dc5ad0ef4a56ecab04a1569eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.2.1 This release

13 release files

1.1.0

85 release files

1.0.0

67 release files

0.9.8

67 release files

0.9.7

67 release files

0.9.6

67 release files

0.9.5

67 release files

0.9.4

67 release files

0.9.3

74 release files

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