{"id":24259,"library":"powerlaw","title":"powerlaw","description":"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.","status":"active","version":"2.0.0","language":"python","source_language":"en","source_url":"https://github.com/jeffalstott/powerlaw","tags":["power law","statistics","distribution fitting"],"install":[{"cmd":"pip install powerlaw","lang":"bash","label":"Default install"}],"dependencies":[],"imports":[{"note":"Library is imported directly as 'powerlaw' module; no submodule","wrong":"from powerlaw import powerlaw","symbol":"powerlaw","correct":"import powerlaw"}],"quickstart":{"code":"import powerlaw\nimport numpy as np\n# Generate sample data\nx = np.random.pareto(2.5, 1000)\n# Fit power law\nfit = powerlaw.Fit(x)\n# Print alpha and xmin\nprint(fit.alpha, fit.xmin)\n# Compare to exponential\nR, p = fit.distribution_compare('power_law', 'exponential')","lang":"python","description":"Fit a power law to data and compare to alternative distributions."},"warnings":[{"fix":"Review the new API: `Fit` now directly returns the fitted parameters (alpha, xmin) as attributes. Use `fit.distribution_compare(...)` for comparisons.","message":"Version 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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"See the documentation for new plotting methods; they have similar names but may have different signatures.","message":"Old 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.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Ensure your data is strictly positive (e.g., remove zeros and negative values before fitting).","message":"Data with values <= 0 will cause errors. Power law distributions are defined for positive values only.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `import powerlaw` and then `fit = powerlaw.Fit(data)`.","cause":"Old code that imported a submodule incorrectly or used an outdated import pattern.","error":"AttributeError: module 'powerlaw' has no attribute 'Fit'"},{"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.","cause":"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.","error":"TypeError: Fit() got an unexpected keyword argument 'xmin'"},{"fix":"Filter your data: `data = data[data > 0]` before fitting.","cause":"Power law fitting requires all data points > 0.","error":"ValueError: Data must be positive"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}