powerlaw
Toolbox for testing if a probability distribution fits a power law
What it is and what it does
powerlaw is a statistical toolbox for testing whether empirical data follows a power-law distribution and comparing it against competing heavy-tailed models like lognormals. It implements the rigorous methods from Clauset et al. 2007 and Klaus et al. 2011, which address the common problem of incorrectly identifying power laws in real-world data. The package fits power-law parameters (alpha and xmin), performs goodness-of-fit tests, and conducts likelihood-ratio comparisons between distributions.
The library is designed for researchers and data analysts who need to determine whether their data exhibits true power-law behavior or whether simpler distributions (like lognormal) provide equally good or better explanations. It integrates with matplotlib for visualization and uses numpy and scipy for numerical computation. The package includes a lognormal_positive variant for cases where theoretical constraints require the underlying distribution parameters to remain positive.
Use it for:
- Analyze network degree distributions or other empirical data to test whether they follow power laws.
- Compare competing heavy-tailed distribution hypotheses using likelihood-ratio tests to determine the best fit.
- Visualize fitted power-law distributions and raw data together using matplotlib integration.
- Validate whether observed tail behavior in scientific datasets (e.g., biological, physical) matches power-law predictions.
- Fit power-law exponents (alpha) and minimum values (xmin) for downstream modeling or theoretical comparison.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Fits heavy-tailed distributions like power laws to data and compares them against alternative distributions such as lognormals using statistical methods from Clauset et al. 2007.
Yes. The package is actively maintained, has no known vulnerabilities, low install friction, and a permissive license. It is the standard tool for rigorous power-law fitting in Python and is well-suited for academic research, data analysis, and any work requiring careful statistical comparison of heavy-tailed distributions. Install it if you need to test whether data actually follows a power law rather than relying on visual inspection or naive fitting.
Install
powerlaw on PyPI
pip
pip install powerlawuv
uv add powerlawpoetry
poetry add powerlawInstalling powerlaw
Before you install
Low friction: pure Python wheel with five standard scientific dependencies (scipy, numpy, matplotlib, mpmath, tqdm) that most data science environments already have. Actively maintained with recent commits and CI across Python 3.8–3.12.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely with minimal restrictions, making it suitable for academic, commercial, and private projects.
Quickstart
import powerlaw
import numpy as np
data = np.array([1.7, 3.2, 5.4, 2.1, 1.5, 2.8])
fit = powerlaw.Fit(data)
print(fit.power_law.alpha)
R, p = fit.distribution_compare('power_law', 'lognormal')
Verify before relying
- Whether mpmath's numerical precision requirement for negative numbers in scipy's gamma functions remains a practical limitation in current scipy versions.
- Performance characteristics and scalability limits on very large datasets.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 5 — scipy, numpy, matplotlib, mpmath, tqdm |
| Maintenance | actively maintained — 224 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 118,899/month — #12,100 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: powerlaw-2.0.0-py3-none-any.whl
Tags
More Mathematics packages
NetworkX provides data structures and…
permissive · top 1,000 on PyPI
kiwisolverkiwisolver is a Python binding to a fast C++…
permissive · top 1,000 on PyPI
sympySymPy is a Python library for symbolic…
permissive · top 1,000 on PyPI
contourpyContourPy calculates contours of 2D…
permissive · top 1,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
onnxruntimeonnxruntime loads and executes Open Neural…
permissive · top 1,000 on PyPI
reliabilityReliability engineering and survival analysis…
copyleft · top 5,000 on PyPI
powershapPowershap performs feature selection by testing…
permissive · top 15,000 on PyPI
pwlfFits continuous piecewise linear functions to…
permissive · top 15,000 on PyPI
statisticsProvides basic mathematical statistics…
permissive · top 15,000 on PyPI
piecewise-regressionFits piecewise linear regression models to data…
permissive · top 15,000 on PyPI
pyjptpyjpt learns and reasons about joint…
unclear · top 15,000 on PyPI
copulasCopulas models multivariate statistical…
unclear · top 15,000 on PyPI
bootstrappedBuilds confidence intervals from data samples…
unclear · top 15,000 on PyPI
numpyroNumPyro is a probabilistic programming library…
permissive · top 15,000 on PyPI
distraxDistrax provides JAX-native probability…
permissive · top 15,000 on PyPI