Skip to main content

stochtest

PyPI - Version PyPI - Python Version


Stochtest is a Python library for performing statistical assertions on stochastic outputs (i.e. outputs described by probability distributions) using statistical methods. It enables automated testing for probabilistic code and Monte Carlo simulations.

Installation

pip install stochtest

Usage

1. Asserting Rates & Means

Use stochtest.assert_that(samples) to validate acceptance rates (proportions) or expected values (means).

import stochtest
import numpy as np

# --- Acceptance Rates (Proportions) ---
samples = np.random.normal(1000)

stochtest.assert_that(samples > 0).has_acceptance_rate_greater_than(0.4)
stochtest.assert_that(outcomes).has_acceptance_rate_between(0.45, 0.55)

# --- Expected Values (Means) ---
# Validated using one-sample Student's t-tests
returns = np.random.normal(1, 0.5, 1000)

stochtest.assert_that(returns).has_expected_value_greater_than(0.5)
stochtest.assert_that(returns).has_expected_value_between(0.9, 1.1)

2. Asserting Distributions

Use stochtest.distributions.assert_that(samples) to verify that an entire dataset matches a specific shape or theoretical distribution using a Bootstrapped Kolmogorov-Smirnov (KS) Test.

This asserts that the distributions are sufficiently similar by ensuring the KS distance is consistently within a specific margin with high confidence.

import numpy as np
import scipy.stats
import stochtest.distributions

samples = np.random.normal(0, 1, 1000)

# Assert samples follow a normal distribution (mean=0, std=1)
stochtest.distributions.assert_that(samples).has_normal_distribution(
    loc=0, scale=1, margin=0.05
)

# Assert samples match a custom CDF (e.g., Uniform)
stochtest.distributions.assert_that(samples).has_distribution(
    lambda x: scipy.stats.uniform.cdf(x), 
    margin=0.05
)

License

stochtest is distributed under the terms of the MIT license.

Release files for stochtest 0.6.2

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

Source distribution (sdist)

Source distribution for stochtest 0.6.2
File Size Uploaded
stochtest-0.6.2.tar.gz 7.0 kB Details

Built distribution (wheel)

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

Total release size: 14.7 kB

Release files / stochtest-0.6.2.tar.gz

Download URL stochtest-0.6.2.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
04d460bbe0d76c2dcfef9acec69912c17f5756c0eddcf23d28f17e65c027ad59
BLAKE2b-256 checksum
How to use checksums
ac81a140a28ac2ffa69f20caa6dd8f8fc266e1f53e6f830957494c15997f55bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Dec 17, 2025.

Transparency log

Release files / stochtest-0.6.2-py3-none-any.whl

Download URL stochtest-0.6.2-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a85cc725bf76dd39d795897b622edbc4aafb55b2248b0828878bd3e847639893
BLAKE2b-256 checksum
How to use checksums
df86b76a3e7ad1ca25b3d88bc29ca3b8e670e85be474b9cb11a19aa64afe3feb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Dec 17, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.1.1

1 release file

0.1.0

1 release file

0.0.4

1 release file

0.0.3

2 release files

0.0.2

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