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.DiGraphor 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 constructingGraphdirectly 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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pylmcf-1.2.0.tar.gz | 260.9 kB | Details |
Built distributions (wheels)
Total release size: 8.5 MB
Release files / pylmcf-1.2.0.tar.gz
| Download URL | pylmcf-1.2.0.tar.gz |
|---|---|
| Size | 260.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a1869749e12461e0bac422af57890cb92e56b035152cffd8b3fba50e62b7868
|
|
BLAKE2b-256 checksum How to use checksums |
d16c71b0e75d1c8d61a637590adf826960f08b62f25981193b929e568f07568c
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp315-abi3t-win_arm64.whl
| Download URL | pylmcf-1.2.0-cp315-abi3t-win_arm64.whl |
|---|---|
| Size | 801.0 kB |
| Tags | CPython 3.15 Windows ARM64 abi3t |
|
SHA-256 checksum How to use checksums |
2f4bc961de2f0709b5e318d21ad2201e9dc8dede538d524c728779de16953502
|
|
BLAKE2b-256 checksum How to use checksums |
9a8d096f40b027aa588dd72e81cb55d8f86513194db9a556e79b29fe08bce3bc
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp315-abi3t-win_amd64.whl
| Download URL | pylmcf-1.2.0-cp315-abi3t-win_amd64.whl |
|---|---|
| Size | 623.8 kB |
| Tags | CPython 3.15 Windows x86-64 abi3t |
|
SHA-256 checksum How to use checksums |
5c262d50e5588194982aeb2dc2fe244c3207282617a6a3dde3fba19f3ef6d2c8
|
|
BLAKE2b-256 checksum How to use checksums |
0439a77fea0e6d4b8f1e28bb3424c30207fb7ce34848ba150e2eb3a6be72ddc8
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp315-abi3t-win32.whl
| Download URL | pylmcf-1.2.0-cp315-abi3t-win32.whl |
|---|---|
| Size | 631.6 kB |
| Tags | CPython 3.15 Windows x86-32 abi3t |
|
SHA-256 checksum How to use checksums |
f778ecfb233a5e351b1cb8ebc95d8e5d7907827574a3ffb24fca88d45ab22933
|
|
BLAKE2b-256 checksum How to use checksums |
2a0113170b313ad1c8201dd33da5f98e91193073105e4af740dad03e05cbe6a5
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp315-abi3t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pylmcf-1.2.0-cp315-abi3t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 535.5 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 |
67693946db3721c9997c11c0073c751c9bad387b8f2ae4229c19dd2eada4b0b6
|
|
BLAKE2b-256 checksum How to use checksums |
b59055c8856bba05845323393a65958ba3f0362e3766cdae5b6a4d1baf2c37de
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp315-abi3t-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
| Download URL | pylmcf-1.2.0-cp315-abi3t-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 492.8 kB |
| Tags | CPython 3.15 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 abi3t |
|
SHA-256 checksum How to use checksums |
4892d91f8a1c1b96b5156fd7b9715f7e97d44b9d479e37cae7609a0ac3ddc083
|
|
BLAKE2b-256 checksum How to use checksums |
7ee11f3a6dfba2614f4a3b8aa9771a47c2c0193c196cdde1ce45bf03c3f89b01
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp315-abi3t-macosx_11_0_arm64.whl
| Download URL | pylmcf-1.2.0-cp315-abi3t-macosx_11_0_arm64.whl |
|---|---|
| Size | 506.0 kB |
| Tags | CPython 3.15 abi3t macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1956bb64adaa9fb684587f68b5d9cd7a5f2de884ec7cd68f37380f8f9adca1d5
|
|
BLAKE2b-256 checksum How to use checksums |
26a9a0fc6c2af28cd71eb1cef2fccd7994cc831b0497053e54b7caee4ebb7c40
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp315-abi3t-macosx_10_15_x86_64.whl
| Download URL | pylmcf-1.2.0-cp315-abi3t-macosx_10_15_x86_64.whl |
|---|---|
| Size | 538.7 kB |
| Tags | CPython 3.15 abi3t macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
d4dfcbaf5e1f48cbb29048c42150ef5d57e3f63ef981cd2b43403d84e8562377
|
|
BLAKE2b-256 checksum How to use checksums |
38bd31a996ac28703baa6eb5792530dba9dcf4b8d15cc4a228334cabf8822e20
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp310-abi3-win_arm64.whl
| Download URL | pylmcf-1.2.0-cp310-abi3-win_arm64.whl |
|---|---|
| Size | 783.4 kB |
| Tags | CPython 3.10 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
33128b4d8836761f40fcd702efcdceef977a27f05e0d539f53203fb35804c470
|
|
BLAKE2b-256 checksum How to use checksums |
256bc83cc52c9991ec4fa5b343b8664ae56b1e758eaed76b648b0625b98530f3
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp310-abi3-win_amd64.whl
| Download URL | pylmcf-1.2.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 613.3 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
fec62b36a3860048e304a6d655c653dad36f5350a816ab718282476aa97e869b
|
|
BLAKE2b-256 checksum How to use checksums |
4063c384197ebeabdb051dd41aa4c25e4ce477f9f8f5adb77ead03c3c807b758
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp310-abi3-win32.whl
| Download URL | pylmcf-1.2.0-cp310-abi3-win32.whl |
|---|---|
| Size | 623.4 kB |
| Tags | CPython 3.10 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
f22f959d32ddd54d6e28174f3879c19f1b270cb2b360ec694d9d3af4ae4e75cf
|
|
BLAKE2b-256 checksum How to use checksums |
6d3563bdd502185c1281c8701552d3dd82eda6cfff52d13215ad246e99441082
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pylmcf-1.2.0-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 535.1 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 |
89076f8cc66f284c4c698969aa2f18c9727d2081f85d0153f9f0cfc025bd367b
|
|
BLAKE2b-256 checksum How to use checksums |
c213c76dd2ac0f0e74521d01043b9136b0f37cabde2fb480c07e0a4228a5514b
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
| Download URL | pylmcf-1.2.0-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 492.6 kB |
| Tags | CPython 3.10 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
e2209c9c20a277e18aab54d1a1adf9244cab6f6c3ae3d96121036179cbdbaff7
|
|
BLAKE2b-256 checksum How to use checksums |
001494a6a4eacb0d61afb7c20b13f6c962df74ef98ddf4c8414f5ff4f3c8dae9
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | pylmcf-1.2.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 505.8 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
221335c922146beb77ee0ce26a10eeb9e0ae7cf41dc438a45fa71765bde2345b
|
|
BLAKE2b-256 checksum How to use checksums |
025fac7ef248698f8386af589b249e6649be47a257d5513e9286afbe0f794493
|
| 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 1, 2026.
Transparency logRelease files / pylmcf-1.2.0-cp310-abi3-macosx_10_15_x86_64.whl
| Download URL | pylmcf-1.2.0-cp310-abi3-macosx_10_15_x86_64.whl |
|---|---|
| Size | 538.0 kB |
| Tags | CPython 3.10 abi3 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
05d5509edd76e01608f141c60004ec228033147d9134b9577d8e227f4a5af1b4
|
|
BLAKE2b-256 checksum How to use checksums |
ae11d777a00af0a9f67034c461292e6a80407b41f2110e6099afbd4551dff05c
|
| 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 1, 2026.
Transparency log