Skip to main content

stochpylib

Probability · Distributions · Monte Carlo — one coherent Python library.
A growing, from-scratch toolkit of stochastic computing: native implementations behind one common interface, engineered to eventually replace stitching together scipy.stats, statsmodels, pymc, arch, lifelines and copulas.


Python 3.10+ License: MIT 182 tests passing CI status PyPI version 106 of 794 spec names implemented

NumPy SciPy pytest setuptools GitHub Actions spl command-line interface


stochpylib is not a wrapper around existing statistical libraries — every distribution and algorithm is implemented from scratch, with scipy.special/optimize/integrate used only as raw numerical building blocks and scipy.stats serving as the independent test oracle. At its core is a single load-bearing contract: every distribution exposes the same method set (.pdf()/.cdf()/.ppf()/.rvs()/.mean()/.var()/.skewness()/.kurtosis()/.entropy()/.mgf()/.cf()/.fit()/.ks_test()), every stochastic method takes a random_state= seed, and every Monte Carlo estimator returns a shared result object carrying its point estimate together with an honest standard error and confidence interval. Around that contract, three modules are live today: a probability engine (sample spaces, Bayes' theorem, exact-integer combinatorics, independence testing), 47 distributions across discrete/continuous/multivariate/heavy-tailed families — including stable laws with Chambers–Mallows–Leckie sampling and numerically inverted characteristic functions — and a Monte Carlo suite spanning quasi-random sequences (Sobol, Halton, Faure, Niederreiter), variance-reduction techniques (antithetic, control variates, Latin hypercube, conditioned MC, rejection control), and applications from option pricing validated against Black–Scholes to reliability analysis driven by the library's own distribution objects. The thesis this project exists to test: a complete stochastic-computing stack can live in one coherent, well-tested package — the roadmap takes it onward through time series, Gaussian processes, copulas, Lévy processes, MCMC and beyond (23 modules, ~794 public names planned).

Table of Contents

Quickstart

from stochpylib.probability import bayes_theorem, total_probability

# Classic disease-screening example: 1% prevalence, 99% sensitivity, 5% false-positive rate.
p_positive = total_probability((0.99, 0.01), (0.05, 0.99))
p_disease_given_positive = bayes_theorem(0.01, 0.99, p_positive)
print(round(p_disease_given_positive, 4))  # 0.1667
from stochpylib.distributions import Normal, Weibull
from stochpylib.montecarlo import SobolSequence, AntitheticVariates

d = Normal(0.0, 1.0)
d.pdf(0.0); d.cdf(1.96); d.ppf(0.975); d.rvs(100, random_state=0)

fitted = Weibull.fit(lifetimes)          # maximum likelihood from data
stat, p_value = fitted.ks_test(data)     # goodness of fit

pts = SobolSequence(dim=5).generate(10_000)                    # low-discrepancy points
price = AntitheticVariates(n_simulations=100_000).price_european_call(
    S=100, K=100, T=1, r=0.05, sigma=0.2)                      # option pricing

Current Status

Early development — three modules implemented so far:

Module Public names What's inside
stochpylib.probability 21 sample spaces, events, conditional probability, Bayes' theorem, combinatorics (factorial … derangements, Stirling, Bell, Catalan), independence checks
stochpylib.distributions 60 47 distributions (discrete, continuous, multivariate, heavy-tailed) behind the common interface
stochpylib.montecarlo 25 quasi-random sequences, crude/QMC/importance/rejection/stratified estimators, variance reduction, applications

Exact progress against the full design spec lives in development/Implementation-Checklist.md (currently 106 / 794 public names).

Download

If you just want to use stochpylib rather than develop on it, no source checkout is needed:

pip install stochpylib
spl --help        # overview of everything the library offers

The PyPI release lands with the first tagged version (v0.1.0); until then the badge above will show "not found". For local development from this repository, pip install -e . registers the same spl command straight from source instead:

git clone https://github.com/leon1706-lol/Stochpylib.git
cd Stochpylib
pip install -e .

Getting Started

For local development (this repo cloned, a virtual environment active):

pip install -e ".[dev]"     # runtime deps + pytest
pytest tests/ -v            # full test suite must be green before you start changing things
spl --version               # verify your editable install
spl --test                  # embedded self-check (106 checks), no pytest needed

Then implement or improve one module at a time and run the wrap-up procedure described in CONTRIBUTING.md.

Requirements

  • Python ≥ 3.10
  • NumPy and SciPy (the only runtime dependencies)
  • pytest for the development extras (pip install -e ".[dev]")
  • No compilers, no GPU, no other system packages — pure Python/NumPy/SciPy by design

CLI Reference

Every install (PyPI wheel or pip install -e .) registers one console command, spl:

spl --help

Prints a full inventory of the installed library: which modules are available, all public functions per module, every distribution class (generated dynamically from the package, so it never goes stale), the common distribution interface, and a runnable quick-start snippet. Running bare spl shows the same thing.

spl --version

$ spl --version
0.1.0

Prints the installed version — reads pip package metadata, falling back to the in-code version when not installed through pip.

spl --test

Runs the embedded self-check suite shipped inside the wheel (106 checks): package sanity, one closed-form spot check per distribution family, Monte Carlo convergence sanity. This works after any pip install — no pytest, no source checkout — making it the quickest way to verify an installation. Exits non-zero on any failure.

Project Layout

  • stochpylib/ — the installable package, one subpackage per module (probability/, distributions/, montecarlo/), plus cli.py and selftest.py
  • tests/ — one tests/<module>/tests.py per module, outside the package
  • development/ — build history & process docs (see below)
  • .github/workflows/ — CI matrix (Python 3.10–3.13), tag-triggered PyPI publishing (Trusted Publisher/OIDC, no stored tokens), automatic GitHub Releases
  • The full design-spec vault (Stochpylib-Obsidian-Vault/) is maintained privately and is not part of this repository

Development Documentation

Everything a contributor or maintainer needs lives in committed docs:

Test Suite

pytest tests/ -v

182 passed / 2 skipped as of the montecarlo module. Tests are deterministic (fixed seeds everywhere), live outside the installed package, and use scipy.stats as the reference oracle. Statistical assertions are set at ≥ 3 standard errors so results are stable while staying meaningful. Additionally, spl --test re-verifies any installation in seconds.

Release Process

Releases are fully automated from tags:

  1. Update the version in pyproject.toml and stochpylib/__init__.py (semver — see the policy in CONTRIBUTING.md)
  2. Tag and push:
    git tag v0.1.0 && git push origin v0.1.0
    
  3. CI runs the full test matrix, builds sdist + wheel, smoke-verifies the wheel (spl --version, spl --test) and publishes to PyPI via Trusted Publisher (OIDC — no API tokens stored anywhere); a second workflow creates the matching GitHub Release with auto-generated changelog notes

Prerequisite for step 3: configure the Trusted Publisher once under pypi.org → your project → Publishing.

Roadmap

Twenty modules remain on the spec (in rough implementation order): time series, Gaussian processes, copulas, survival analysis, queueing theory, information theory, Lévy processes, financial stochastics, advanced MCMC, Bayesian inference, statistics, nonparametric methods, robust statistics, numerical methods, random matrix theory, spatial statistics, optimization, experimental design, visualization, and utilities. Each lands with the same bar: native implementations, the shared interface conventions, full tests against independent oracles, and honest documentation of deviations.

Contributing

Issues and PRs welcome! Start with CONTRIBUTING.md — it covers the ground rules (no scipy.stats wrapping in library code, the common interface contract, where tests live) and the versioning/deprecation policy. Bug reports go through the issue templates; security issues privately per SECURITY.md. This project follows CODE_OF_CONDUCT.md.

License

MIT © Leon Schwarzkopf


Built by Leon Schwarzkopf, leonschwarzkopf08@gmail.com


stochpylib

Metadata

Release files for stochpylib 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stochpylib 0.1.0
File Size Uploaded
stochpylib-0.1.0.tar.gz 47.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stochpylib 0.1.0
File Interpreter ABI Platform
stochpylib-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 98.4 kB

Release files / stochpylib-0.1.0.tar.gz

Download URL stochpylib-0.1.0.tar.gz
Size 47.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d456fc0d92978f0ee659a373762a9b6fcfd181dfb79da7329df2a6938c366f45
BLAKE2b-256 checksum
How to use checksums
5423a72373956328634b170bf71a639270e6fc135f35f874084f8f50c0c234d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

Release files / stochpylib-0.1.0-py3-none-any.whl

Download URL stochpylib-0.1.0-py3-none-any.whl
Size 50.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
258592625ffcdb7ddcffd5dd51e4cd2e5493ddd2f57d2923589fb52f4129f36c
BLAKE2b-256 checksum
How to use checksums
321b02a2313c6aad0c5f088dc4b42d86636e1b5c6ba6771e41f4cd6a9f070033
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

Release history Release notifications | RSS feed

0.20.0

2 release files

0.6.4

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release 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