Skip to main content

heavytails

A pure-Python library of heavy-tailed probability distributions

CI codecov PyPI Python versions License: MIT Documentation Ruff Checked with mypy

heavytails implements continuous and discrete heavy-tailed distributions, tail index estimators, and diagnostic utilities — using only the Python standard library. Every density, quantile and sampler is derived from first principles, so the implementation can be read, checked and taught rather than taken on faith.

It targets research, teaching and simulation work in risk, finance, insurance and extreme-value analysis.


Features

  • No runtime dependencies. The library imports nothing outside math, random and friends, so it installs anywhere Python does.
  • Complete distribution interface. PDF/PMF, CDF, survival function, quantile function and random sampling for every family, with survival functions computed directly so they stay accurate far into the tail where 1 - cdf(x) has lost every significant digit.
  • Reproducible sampling through a deterministic RNG wrapper.
  • Special functions from scratch — incomplete gamma and incomplete beta — plus a safeguarded-Newton numeric PPF for families with no closed form.
  • Tail index estimation with the Hill, Pickands and moment estimators.
  • Parameter fitting by maximum likelihood and method of moments, with AIC/BIC model comparison.
  • Diagnostics for log–log tail plots and QQ plots.
  • A command-line interface for sampling, fitting, comparison and benchmarking.
  • Typed throughout, with a py.typed marker so downstream type checkers see the annotations.

Installation

pip install heavytails

The command-line interface needs two extra packages; install it with the cli extra:

pip install "heavytails[cli]"

To work on the library itself:

git clone https://github.com/DiogoRibeiro7/heavytails.git
cd heavytails
poetry install --with dev,docs

Requires Python 3.10 or newer.


Quick start

from heavytails import BurrXII, Pareto, hill_estimator

pareto = Pareto(alpha=1.5, xm=1.0)

pareto.pdf(2.0)        # density
pareto.cdf(2.0)        # distribution function
pareto.sf(10.0)        # survival function: P(X > 10)
pareto.ppf(0.99)       # 99th percentile
samples = pareto.rvs(10_000, seed=42)

# Recover the tail index from the sample. The estimators return the
# extreme-value index gamma = 1 / alpha, so invert it to read alpha back.
gamma = hill_estimator(samples, k=100)   # ≈ 0.65
alpha = 1 / gamma                        # ≈ 1.53, against a true 1.5

burr = BurrXII(c=1.2, k=2.5, s=3.0)
burr.ppf(0.95)

Command line

heavytails list-distributions
heavytails sample pareto --params '{"alpha": 2.0, "xm": 1.0}' -n 1000 -o samples.txt
heavytails estimate-tail samples.txt --method hill
heavytails compare samples.txt

Run heavytails --help for the full command list.


Available distributions

Continuous

Distribution Module Heavy-tail regime
Pareto heavy_tails always
Cauchy heavy_tails always
Student-t heavy_tails small ν
Log-Normal heavy_tails always
Weibull heavy_tails k < 1
Fréchet heavy_tails always
GEV (Fréchet branch) heavy_tails ξ > 0
Generalized Pareto extra_distributions ξ > 0
Burr XII extra_distributions always
Log-Logistic (Fisk) extra_distributions always
Inverse-Gamma extra_distributions always
Beta-Prime extra_distributions always

Discrete

Distribution Module Heavy-tail regime
Zipf discrete always
Yule–Simon discrete always
Discrete Pareto discrete always

Every continuous family provides pdf, cdf, sf, ppf and rvs; every discrete family provides pmf, cdf, ppf and rvs.

Estimation and diagnostics

Module Contents
tail_index Hill, Pickands and moment tail index estimators
plotting Log–log tail plots and QQ plots
utilities Data I/O, automatic fitting and model comparison
validation Mathematical and numerical validation of the families
cli Command-line entry point

Documentation

Full documentation, including the mathematical background, is at https://diogoribeiro7.github.io/heavytails.

To build it locally:

make docs-serve

Development

make install-dev   # install every dependency group
make hooks         # install the pre-commit hooks
make check         # everything CI runs: lint, format, types, tests, security

Individual targets are listed by make help. Contributions are welcome — see CONTRIBUTING.md for the branch flow, commit conventions and review process, and ROADMAP.md for what is planned next.

Notable changes are recorded in CHANGELOG.md.


License

MIT License © 2025 Diogo Ribeiro. See LICENSE.


Citation

If you use this package in research or teaching, please cite it. GitHub's "Cite this repository" button reads CITATION.cff, or use:

Ribeiro, D. (2025). heavytails: A Pure-Python Library for Heavy-Tailed Probability Distributions. https://github.com/DiogoRibeiro7/heavytails

Shared citation metadata is maintained in CITATION.cff; Zenodo-specific archive metadata is maintained in .zenodo.json. The DOI will be added after the first archived GitHub release.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

heavytails-0.2.0.tar.gz (119.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

heavytails-0.2.0-py3-none-any.whl (74.5 kB view details)

Uploaded Python 3

File details

Details for the file heavytails-0.2.0.tar.gz.

File metadata

  • Download URL: heavytails-0.2.0.tar.gz
  • Upload date:
  • Size: 119.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for heavytails-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cf1744d675c544d53fb68b5967d0da229a9a987f6c748dc29a8dd0b57ca577a9
MD5 98c2e9a8c415f2a132cc2a2502663380
BLAKE2b-256 4d372e1fe2f99d5f39c3c90696342e17fc78e14dd0190a9432a6efb2afe36e0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for heavytails-0.2.0.tar.gz:

Publisher: ci.yml on DiogoRibeiro7/heavytails

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file heavytails-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: heavytails-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 74.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for heavytails-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2eaf9b9bc46756b2a8f710b555ffd75bc38bdfd2d5729bc8692e4bd6c1cd0a81
MD5 2a74fa8236512309ad2cbcc0fc7aac00
BLAKE2b-256 74619ba772399cc4379711a15225199223c0d75bfb8baea24a639987e606534d

See more details on using hashes here.

Provenance

The following attestation bundles were made for heavytails-0.2.0-py3-none-any.whl:

Publisher: ci.yml on DiogoRibeiro7/heavytails

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page