Registry / data / powerlaw

powerlaw

JSON →
library2.0.0pypypi✓ verified 86d ago

A toolbox for testing if a probability distribution fits a power law, including fitting power laws, comparing to other distributions via likelihood ratio tests, and plotting. Current version is 2.0.0 (released 2023-12-31), with major refactor from v1.x. Release cadence is irregular.

pip install powerlaw
INSTALL
IMPORT
SIG · POWERLAW
P
powerlaw
datapythonv2.0.0
Install
12.0s avg
Import
3686ms
Disk
329MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 3.758s · 325.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 12.0s · import 3.614s · 313MB
329MB installed
● package 329MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

powerlaw
import powerlaw
from powerlaw import powerlaw
Library is imported directly as 'powerlaw' module; no submodule

Fit a power law to data and compare to alternative distributions.

import powerlaw import numpy as np # Generate sample data x = np.random.pareto(2.5, 1000) # Fit power law fit = powerlaw.Fit(x) # Print alpha and xmin print(fit.alpha, fit.xmin) # Compare to exponential R, p = fit.distribution_compare('power_law', 'exponential')
Debug
Known issues
breakingVersion 2.0.0 is a major refactor with API changes. The previous API (e.g., `powerlaw.Fit` returning a `Result` object with `.power_law.alpha`) has been simplified. Ensure you update code and refer to new documentation.
fix
Review the new API: `Fit` now directly returns the fitted parameters (alpha, xmin) as attributes. Use `fit.distribution_compare(...)` for comparisons.
affects: >=2.0.0
deprecatedOld plotting functions from v1.x (e.g., `fit.plot_pdf()`) may be removed. Use `fit.plot_ccdf()` or `fit.plot_pdf()` as per new API.
fix
See the documentation for new plotting methods; they have similar names but may have different signatures.
affects: >=2.0.0
gotchaData with values <= 0 will cause errors. Power law distributions are defined for positive values only.
fix
Ensure your data is strictly positive (e.g., remove zeros and negative values before fitting).
affects: all
Errors
Common errors & fixes
AttributeError: module 'powerlaw' has no attribute 'Fit'
Old code that imported a submodule incorrectly or used an outdated import pattern.
fix
Use `import powerlaw` and then `fit = powerlaw.Fit(data)`.
TypeError: Fit() got an unexpected keyword argument 'xmin'
The API changed in v2.0; `xmin` is no longer a direct argument to `Fit`; use `Fit(data, xmin=value)` may still work but check docs.
fix
Use `fit = powerlaw.Fit(data, xmin=...)` and refer to v2.0 docs; if using v2.0, the argument is still supported but check for other changes.
ValueError: Data must be positive
Power law fitting requires all data points > 0.
fix
Filter your data: `data = data[data > 0]` before fitting.
Upgrade
Version history
2.0.0latest on PyPI · released Jan 2, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
powerlaw — pip install powerlaw · libregistry