Skip to main content

spark-bestfit

CI Documentation Status PyPI version Production Ready License: MIT Code style: black Ruff

Modern distribution fitting library with pluggable backends (Spark, Ray, Local)

Efficiently fit ~90 scipy.stats distributions to your data using parallel processing. Supports Apache Spark for production clusters, Ray for ML workflows, or local execution for development.

Features

  • Parallel Processing: Spark, Ray, or local thread backends
  • ~90 Continuous + 16 Discrete Distributions
  • Multiple Metrics: K-S, A-D, SSE, AIC, BIC
  • Bounded Fitting: Truncated distributions with natural bounds
  • Heavy-Tail Detection: Warns when data may need special handling
  • Gaussian Copula: Correlated multi-column sampling
  • Model Serialization: Save/load to JSON or pickle
  • FitterConfig Builder: Fluent API for complex configurations

Full feature list at spark-bestfit.readthedocs.io

Installation

pip install spark-bestfit              # Core (BYO Spark)
pip install spark-bestfit[spark]       # With PySpark
pip install spark-bestfit[ray]         # With Ray
pip install spark-bestfit[plotting]    # With visualization

Quick Start

from spark_bestfit import DistributionFitter
import numpy as np
from pyspark.sql import SparkSession

spark = SparkSession.builder.getOrCreate()
data = np.random.normal(loc=50, scale=10, size=10_000)
df = spark.createDataFrame([(float(x),) for x in data], ["value"])

fitter = DistributionFitter(spark)
results = fitter.fit(df, column="value")

best = results.best(n=1)[0]
print(f"Best: {best.distribution} (KS={best.ks_statistic:.4f})")

Without Spark:

from spark_bestfit import DistributionFitter, LocalBackend
import pandas as pd

df = pd.DataFrame({"value": np.random.normal(50, 10, 1000)})
fitter = DistributionFitter(backend=LocalBackend())
results = fitter.fit(df, column="value")

Backends

Backend Use Case Install
SparkBackend Production clusters, 100M+ rows [spark] or BYO
LocalBackend Development, testing Included
RayBackend Ray clusters, ML pipelines [ray]

See Backend Guide for configuration details.

Compatibility

Spark Python NumPy pandas PyArrow
3.5.x 3.11-3.12 1.24 to <2 (1.26.4) 1.5 to <4 (3.0.6) 12 to <19 (18.1.0)
4.0.x 3.11-3.13 1.24 to <3 (2.5.4) 2.0 to <4 (3.1.0) 12 to <19 (18.1.0)
4.1.x 3.11-3.13 1.24 to <3 (2.5.4) 2.2 to <4 (3.1.0) 15 to <19 (18.1.0)
4.2.x 3.11-3.13 1.24 to <3 (2.5.4) 2.2 to <4 (3.1.0) 18 to <19 (18.1.0)
4.3.x 3.11-3.13 1.24 to <3 (2.5.4) 2.2 to <4 (3.1.0) 18 to <19 (18.1.0)

Ranges are what pip may install; the version in brackets is what pip picked with pyspark[sql]==<patch> for the newest patch of each minor (3.5.9, 4.0.5, 4.1.4, 4.2.1, 4.3.0) in November 2026. pip install spark-bestfit[spark] picks matching versions on its own, except on Spark 3.5: only pyspark[sql] caps NumPy below 2, so pin numpy<2 there. A weekly canary tests every Spark minor from 3.5 up.

Documentation

Full documentation at spark-bestfit.readthedocs.io:

Contributing

Contributions welcome! See Contributing Guide.

License

MIT License - see LICENSE for details.

Metadata

Release files for spark-bestfit 3.0.4

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

Source distribution (sdist)

Source distribution for spark-bestfit 3.0.4
File Size Uploaded Provenance Actions
spark_bestfit-3.0.4.tar.gz 2.9 MB With provenance Details for spark_bestfit-3.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spark-bestfit 3.0.4
File Interpreter ABI Platform Actions
spark_bestfit-3.0.4-py3-none-any.whl Python 3 none any Details for spark_bestfit-3.0.4-py3-none-any.whl

Total release size: 3.1 MB

Release files / spark_bestfit-3.0.4.tar.gz

Download URL spark_bestfit-3.0.4.tar.gz
Size 2.9 MB
Tags Source
SHA-256 checksum
How to use checksums
da823573d881e3bb5667488a06c88ac33013cea58c7478e5b094bea185925999
BLAKE2b-256 checksum
How to use checksums
88ab63699711ee0f7eb09eeebe3c5c588ed500d5bc59da125ce89176692f8c64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 3, 2026.

Transparency log

Release files / spark_bestfit-3.0.4-py3-none-any.whl

Download URL spark_bestfit-3.0.4-py3-none-any.whl
Size 145.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0315859f34c5bddc190b26888906eca48d6f4c7e04ec0c57be6757cc6a85e7a8
BLAKE2b-256 checksum
How to use checksums
5896d08e3a0c31141d168092f0eb994c755f8cc641a98ce84911f4c6745431d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 3, 2026.

Transparency log

Security for spark-bestfit 3.0.4

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spark_bestfit-3.0.4.tar.gz

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 Nov 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.0.4 This release

2 release files Full provenance

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