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.
Documentation
For comprehensive guides, API reference, and tutorials, visit the official documentation:
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
This example runs as-is: NPAP downloads and caches the network for you. It reduces the European high-voltage grid from 6,863 buses to 50, and takes about a minute.
import npap
from npap import AggregationProfile
from npap.datasets import fetch_pypsa_eur
files = fetch_pypsa_eur()
manager = npap.PartitionAggregatorManager()
manager.load_data(
strategy="csv_files",
node_file=str(files["buses.csv"]),
edge_file=str(files["lines.csv"]),
)
manager.aggregate_parallel_edges(
edge_properties={"x": "equivalent_reactance", "s_nom": "sum"},
default_strategy="average",
)
manager.partition(strategy="geographical_kmedoids_haversine", n_clusters=50)
profile = AggregationProfile(
topology_strategy="simple",
node_properties={"lat": "average", "lon": "average", "voltage": "first"},
edge_properties={"x": "equivalent_reactance", "s_nom": "sum"},
default_node_strategy="average",
default_edge_strategy="average",
)
reduced = manager.aggregate(profile=profile)
manager.plot_network(graph=reduced, style="simple", title="Reduced network")
The result is a 50-bus, 153-line network — 0.7% of the buses you started with.
The Quick Start guide explains each step and how the configuration choices affect the outcome, and the example notebooks run the full voltage-aware pipeline, which respects transformers, DC links and voltage levels.
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.
Built with care for the open-source community 🫰
Metadata
Release files for npap 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| npap-1.1.1.tar.gz | 7.1 MB | With provenance | Details for npap-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| npap-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for npap-1.1.1-py3-none-any.whl |
Total release size: 7.2 MB
Release files / npap-1.1.1.tar.gz
| Download URL | npap-1.1.1.tar.gz |
|---|---|
| Size | 7.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d9efdf842be060ea1b11492b319f160828ad443319bbebc0d4b1c66379ca1e80
|
|
BLAKE2b-256 checksum How to use checksums |
47bd2086c5e06ed148c405ce627296bf758b208a82e7f613661c7dc1a667d43a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 1, 2026.
Transparency logRelease files / npap-1.1.1-py3-none-any.whl
| Download URL | npap-1.1.1-py3-none-any.whl |
|---|---|
| Size | 92.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
07b1881d5f3286cee0bc4488f50daf9430b2f8d1f2b4ad72bd9af2016ff4f1a7
|
|
BLAKE2b-256 checksum How to use checksums |
29dc70f11f6292c2d15fd22cae3142825c3bb64aaf43365a96d04aea90e3be3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 1, 2026.
Transparency logSecurity for npap 1.1.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for npap-1.1.1.tar.gz
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 Nov 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.