Skip to main content

NPAP - Network Partitioning & Aggregation Package

PyPI version Python versions License: MIT Documentation codecov pre-commit.ci status Ruff JOSS status


NPAP is an open-source Python library for partitioning and aggregating network graphs, with a special focus on electrical power systems. Built on top of NetworkX, it provides a clean strategy-based architecture that makes it easy to cluster networks and reduce their complexity while preserving essential properties.

Whether you're working with power grids, transportation networks, or any graph-based spatial data, NPAP helps you simplify complex networks into manageable pieces.

[!NOTE] Project contributors from IEE (Institute of Electricity Economics and Energy Innovation) at the Technical University of Graz are supported by the Research Center Energetic and funded by the European Union (ERC, NetZero-Opt, 101116212).

Documentation

For comprehensive guides, API reference, and tutorials, visit the official documentation:

https://npap.readthedocs.io

Features

  • Multiple Partitioning Algorithms - K-means, K-medoids, DBSCAN, HDBSCAN, and hierarchical clustering
  • Distance Metrics - Euclidean for local coordinates, Haversine for geographic data
  • Electrical Distance - Partition based on PTDF-derived electrical proximity
  • Voltage-Aware Clustering - Respects voltage levels and transformer boundaries
  • Flexible Aggregation - Sum, average, or custom strategies for node/edge properties
  • Extensible Design - Easy to add your own partitioning or aggregation strategies

Installation

pip install npap

Quick Start

from npap import PartitionAggregatorManager, AggregationProfile, AggregationMode

# 1. Initialize the manager
manager = PartitionAggregatorManager()

# 2. Load data (voltage-aware loader for power systems)
manager.load_data(
    strategy="va_loader",
    node_file="buses.csv",
    line_file="lines.csv",
    transformer_file="transformers.csv",
    converter_file="converters.csv",
    link_file="dc_links.csv",
)

# 3. Aggregate parallel edges (optional)
manager.aggregate_parallel_edges(
    edge_properties={"x": "equivalent_reactance", "type": "first"}, default_strategy="average"
)

# 4. Partition the network
manager.partition(strategy="electrical_kmedoids", n_clusters=50)

# 5. Visualize the partitioned network
manager.plot_network(style="clustered", title="Partitioned Network")

# 6. Aggregate with a custom profile
profile = AggregationProfile(
    mode=AggregationMode.GEOGRAPHICAL,
    topology_strategy="simple",
    node_properties={"lat": "average", "lon": "average", "voltage": "average"},
    edge_properties={"p_max": "sum", "x": "equivalent_reactance"},
    default_node_strategy="average",
    default_edge_strategy="average",
)
aggregated_network = manager.aggregate(profile=profile)

# 7. Visualize the reduced network
manager.plot_network(style="simple", title="Aggregated Network")

Contributing

We warmly welcome contributions from everyone! Whether it's fixing a typo, improving documentation, reporting bugs, or implementing new features — every contribution matters.

Please read our Contributing Guide to get started, or visit the full Contributing Documentation for detailed guidelines.

Reporting Issues and Asking Questions

Found a bug, want to request a feature, or have a question about using NPAP? Open an issue — the template picker will guide you to the right form. Please search the existing issues first, in case it has already been reported.

License

NPAP is released under the MIT License.

Acknowledgements

Funded by the European Union (ERC, NetZero-Opt, 101116212). Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Research Council. Neither the European Union nor the granting authority can be held responsible for them.

ERC     NetZero-Opt


Built with care for the open-source community 🫰

Metadata

Release files for npap 1.1.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 npap 1.1.0
File Size Uploaded
npap-1.1.0.tar.gz 4.9 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for npap 1.1.0
File Interpreter ABI Platform
npap-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 5.0 MB

Release files / npap-1.1.0.tar.gz

Download URL npap-1.1.0.tar.gz
Size 4.9 MB
Tags Source
SHA-256 checksum
How to use checksums
1dd9099175b5fe894b65a2c6dc422f1b7599c9895b8100b0d0c7e0c208a3d9a4
BLAKE2b-256 checksum
How to use checksums
fa8c5e0a45507e0df17f45e40ed2b7a8c25e76944a06505cfcf5ad25f0d2de9d
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 Aug 15, 2026.

Transparency log

Release files / npap-1.1.0-py3-none-any.whl

Download URL npap-1.1.0-py3-none-any.whl
Size 87.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c7c3b08ce7046f8ce743119c201169077a2d1d653182130a2697eb981506ffd2
BLAKE2b-256 checksum
How to use checksums
8208f18054e6179909645c2c47084920f6ec67374a2b9e1a8f9852ad51363ad4
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 Aug 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.1

2 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