SaatyPy
SaatyPy is a Python package for Analytic Hierarchy Process (AHP) and Analytic Network Process (ANP) decision modeling.
It provides robust, flexible, and well-tested tools for multi-criteria decision analysis, supporting both academic and business use cases.
The package is named in honor of Thomas L. Saaty, the originator of AHP and ANP methodologies.
His pioneering work laid the foundation for modern multi-criteria decision making.
Features
- AHP and ANP model builders
- Pairwise comparison matrices
- Consistency checks and error handling
- Matrix limiters and normalization utilities
- Reporting and result export
- Extensible and type-safe API
Modules Overview
- saatypy.ahp: Build and solve AHP models (hierarchies, priorities, reporting)
- saatypy.anp: Build and solve ANP models (networks, supermatrices, limiters)
- saatypy.components: Core types, pairwise comparisons, error classes, math utilities
- saatypy.reporting: Generate reports and export results
Installation
pip install saatypy
Or clone the repository and install locally:
git clone https://github.com/ehsanAhmadzadeh/saatypy.git
cd saatypy
pip install .
Quick Start (AHP)
from saatypy.ahp import AHPBuilder
model = (AHPBuilder()
.add_criteria(["price", "quality", "service"])
.add_alternatives(["A", "B", "C"])
.build())
model.set_criteria_weights({"price": 0.5, "quality": 0.3, "service": 0.2})
for crit in ["price", "quality", "service"]:
model.set_alt_priorities(crit, {
("A", "B"): 2.0,
("A", "C"): 3.0,
("B", "C"): 1.5
})
priorities, labels = model.alternative_priorities()
print(dict(zip(labels, priorities)))
Quick Start (ANP)
from saatypy.anp import ANPBuilder
from saatypy.components.pairwise import PairwiseComparison
model = (ANPBuilder()
.add_cluster("criteria", ["C1", "C2"])
.add_alternatives(["A", "B"])
.build())
model.set_cluster_weights({"criteria": 0.6, "Alternatives": 0.4})
block_alt_given_crit = {
"C1": PairwiseComparison.from_judgments(["A", "B"], {("A", "B"): 4.0}),
"C2": PairwiseComparison.from_judgments(["A", "B"], {("A", "B"): 3.0/7.0}),
}
model.add_block("Alternatives", "criteria", block_alt_given_crit)
model.add_block_uniform("criteria", "criteria")
priorities, labels = model.alternative_priorities()
print(dict(zip(labels, priorities)))
Error Handling
SaatyPy provides detailed error messages for invalid inputs, missing weights, and matrix inconsistencies:
from saatypy.ahp import AHPBuilder
from saatypy.components.errors import NormalizationError
model = AHPBuilder().add_criteria(["A", "B"]).add_alternatives(["X", "Y"]).build()
try:
model.set_criteria_weights({"invalid": 1.0})
except NormalizationError as e:
print("Error:", e)
Reporting
Extract results directly from your model:
report = model.to_report_data()
print(report["criteria_weights"])
print(report["global_priorities"])
print(report["ranking_str"])
Saving Reports
You can save a formatted report for any model using the ReportManager:
from saatypy.reporting.report import ReportManager
manager = ReportManager() # Default: Markdown format, saves to 'reports/'
report_path = manager.save(model) # model can be AHPModel or ANPModel
print(f"Report saved to: {report_path}")
# To use plain text format:
from saatypy.reporting.report import PlainRenderer
manager = ReportManager(renderer=PlainRenderer())
report_path = manager.save(model, path="my_report.txt")
- By default, reports are saved in Markdown format to the
reports/directory. - You can specify a custom path, file name, or renderer.
- The filename will include a timestamp unless you set
add_timestamp=False.
Advanced Usage
- Hierarchical criteria (AHP)
- Custom limiters (ANP)
- Extend with new adapters or reporting formats
- Use math utilities for normalization and consistency checks
Documentation
References
- Saaty, T. L. (1980). The Analytic Hierarchy Process. McGraw-Hill.
- Saaty, T. L. (1996). Decision Making with Dependence and Feedback: The Analytic Network Process. RWS Publications.
- Saaty, T. L. (2008). Decision making with the analytic hierarchy process. International Journal of Services Sciences, 1(1), 83–98.
- Saaty, T. L. (2005). Theory and Applications of the Analytic Network Process. RWS Publications.
Contributing
See CONTRIBUTING.md for guidelines.
License
See LICENSE.
Changelog
See CHANGELOG.md.
For more details, see the documentation in the docs/ folder.
Metadata
Release files for SaatyPy 0.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 |
|---|---|---|---|---|
| saatypy-0.1.1.tar.gz | 27.4 kB | Without provenance | Details for saatypy-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| saatypy-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for saatypy-0.1.1-py3-none-any.whl |
Total release size: 52.6 kB
Release files / saatypy-0.1.1.tar.gz
| Download URL | saatypy-0.1.1.tar.gz |
|---|---|
| Size | 27.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56389b785c788bbdddc8c95fd98354ceeee9d56732c4c40313bc38b573c8792b
|
|
BLAKE2b-256 checksum How to use checksums |
909156e92fb767a64f291bf3a6b221fc7e0e5ed4488114362d9327a934eb66c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / saatypy-0.1.1-py3-none-any.whl
| Download URL | saatypy-0.1.1-py3-none-any.whl |
|---|---|
| Size | 25.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d2c68c0b604a2b556797719b8cc63b4d497e29b9572f3edb79edada71fc63c91
|
|
BLAKE2b-256 checksum How to use checksums |
ccb74e8f0dcf44f9db9d4e08b6c38606b68452a235f3eb7743b99b7be3e92133
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for SaatyPy 0.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.