Skip to main content

A Multilayer network analysis python3 library

Project description

py3plex logo

Tests Examples Tutorial Code Quality Benchmarks Documentation Formal Verification Fuzzing PyPI version CLI Tool Docker Lines of Code

Multilayer networks are complex networks with additional information assigned to nodes or edges (or both). This library includes some of the state-of-the-art algorithms for decomposition, visualization and analysis of such networks.

Key Features:

  • SQL-like DSL for intuitive network queries with smart defaults
  • Multilayer network visualization and analysis
  • Community detection and centrality measures
  • Network decomposition and embeddings
from py3plex.core import datasets
from py3plex.dsl import Q, UQ
from py3plex.algorithms.community_detection import multilayer_louvain

# 1. Load a built-in multilayer biological network (~500 nodes, 4 layers)
network = datasets.fetch_multilayer("human_ppi_gene_disease_drug")

# 2. Run multilayer community detection
partition_vector, Q_modularity = multilayer_louvain(network, gamma=1.2, random_state=42)
network.assign_partition(partition_vector)

# 3. Find master regulator candidates with uncertainty quantification
master_regulators = (
    Q.nodes()
     .node_type("gene")                        # Filter by node type
     .where(degree__gt=3)                      # Remove peripheral genes
     .uq(method="perturbation", n_samples=100, ci=0.95, seed=42)  # Quantify confidence
     .per_layer()                              # Group by layer
        .compute("degree_centrality", "betweenness_centrality")
        .top_k(20, "betweenness_centrality__mean")  # Top 20 per layer by mean
     .end_grouping()
     .sort(by="betweenness_centrality__mean", descending=True)
     .limit(20)                                # Final top 20 candidates
     .execute(network)
)

df = master_regulators.to_pandas(expand_uncertainty=True)
print(df[["id", "layer", "betweenness_centrality", "betweenness_centrality_std", 
          "betweenness_centrality_ci95_low", "betweenness_centrality_ci95_high"]].head(10))

Emits:

Found 287 communities, modularity = 0.649
    id  layer  betweenness_centrality  betweenness_centrality_std  betweenness_centrality_ci95_low  betweenness_centrality_ci95_high
0  252      0                0.025961                    0.002134                         0.021820                          0.030102
1   91      0                0.024918                    0.002051                         0.020902                          0.028934
2  419      0                0.024184                    0.001987                         0.020298                          0.028070
...

Py3plex Visualization Showcase

Cross-Ecosystem Interoperability

Py3plex provides lossless conversion to and from common graph ecosystems:

from py3plex.compat import convert

# Convert to NetworkX
nx_graph = convert(network, "networkx")

# Convert to SciPy sparse matrix (with sidecar for attributes)
matrix = convert(network, "scipy_sparse", strict=False, sidecar="graph_data")

# Convert to igraph (optional: pip install python-igraph)
ig_graph = convert(network, "igraph")

# Convert back to py3plex
restored = convert(nx_graph, "py3plex")

Key features:

  • ✓ Preserves graph structure, node/edge IDs, and all attributes
  • ✓ Explicit failure modes with clear error messages (strict mode)
  • ✓ Sidecar bundles for lossy target formats (compat mode)
  • ✓ Schema validation and compatibility checking
  • ✓ Support for NetworkX, SciPy sparse, igraph, PyG (planned), DGL (planned)

See documentation for complete interoperability guide.

Getting Started

License

Py3plex is released under the MIT License.

Note on licensing: Prior to version 1.0, the project was distributed under the BSD-3-Clause license. Starting with version 1.0, the license was changed to MIT to better align with the broader Python scientific ecosystem and simplify contribution and reuse. Both licenses are permissive and OSI-approved.

Citations

@Article{Skrlj2019,
author={Skrlj, Blaz
and Kralj, Jan
and Lavrac, Nada},
title={Py3plex toolkit for visualization and analysis of multilayer networks},
journal={Applied Network Science},
year={2019},
volume={4},
number={1},
pages={94},
abstract={Complex networks are used as means for representing multimodal, real-life systems. With increasing amounts of data that lead to large multilayer networks consisting of different node and edge types, that can also be subject to temporal change, there is an increasing need for versatile visualization and analysis software. This work presents a lightweight Python library, Py3plex, which focuses on the visualization and analysis of multilayer networks. The library implements a set of simple graphical primitives supporting intra- as well as inter-layer visualization. It also supports many common operations on multilayer networks, such as aggregation, slicing, indexing, traversal, and more. The paper also focuses on how node embeddings can be used to speed up contemporary (multilayer) layout computation. The library's functionality is showcased on both real and synthetic networks.},
issn={2364-8228},
doi={10.1007/s41109-019-0203-7},
url={https://doi.org/10.1007/s41109-019-0203-7}
}

and

@InProceedings{10.1007/978-3-030-05411-3_60,
author="{\v{S}}krlj, Bla{\v{z}}
and Kralj, Jan
and Lavra{\v{c}}, Nada",
editor="Aiello, Luca Maria
and Cherifi, Chantal
and Cherifi, Hocine
and Lambiotte, Renaud
and Li{\'o}, Pietro
and Rocha, Luis M.",
title="Py3plex: A Library for Scalable Multilayer Network Analysis and Visualization",
booktitle="Complex Networks and Their Applications VII",
year="2019",
publisher="Springer International Publishing",
address="Cham",
pages="757--768",
abstract="Real-life systems are commonly represented as networks of interacting entities. While homogeneous networks consist of nodes of a single node type, multilayer networks are characterized by multiple types of nodes or edges, all present in the same system. Analysis and visualization of such networks represent a challenge for real-life complex network applications. The presented Py3plex Python-based library facilitates the exploration and visualization of multilayer networks. The library includes a diagonal projection-based network visualization, developed specifically for large networks with multiple node (and edge) types. The library also includes state-of-the-art methods for network decomposition and statistical analysis. The Py3plex functionality is showcased on real-world multilayer networks from the domains of biology and on synthetic networks.",
isbn="978-3-030-05411-3"
}

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

py3plex-1.0.3.tar.gz (1.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py3plex-1.0.3-py3-none-any.whl (781.8 kB view details)

Uploaded Python 3

File details

Details for the file py3plex-1.0.3.tar.gz.

File metadata

  • Download URL: py3plex-1.0.3.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py3plex-1.0.3.tar.gz
Algorithm Hash digest
SHA256 38bdbda3e3834390d3dcdc6d7b119a0d51f904bbac8805e1c4b74cf8a3fbfe5e
MD5 dd58498986c59187c5bd35fc80f0e825
BLAKE2b-256 115284d11da3dd3063e600c4af2377fd8f0aa5b3e3d689e4450326c08380c99a

See more details on using hashes here.

File details

Details for the file py3plex-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: py3plex-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 781.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py3plex-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0abb5982bf3f79353918d5340c7138b35c6ebbc3c7206cf8a355c3653d5a1859
MD5 d03e9431067dd3119ec600ea147804fd
BLAKE2b-256 227b5cf7c0c2c15503f2c654263789e047f2eafb232045af18fa9141564fb194

See more details on using hashes here.

Supported by

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