Skip to main content

Parse function-call strings into frozen scipy.stats distributions

Project description

distparser

Parse function‑call strings into frozen scipy.stats distributions — with dependency resolution, arithmetic expressions, and seed management.

PyPI version Python 3.8+ License: MIT

Installation

pip install distparser

Quick Start

import distparser as lib

# Parse a single distribution string
d = lib.parse_dist("norm(loc=0, scale=1)")
print(d.rvs(size=3))  # array([...])

DistGraph — dependency-aware evaluation

from distparser import DistGraph

config = {
    "mean": 5.0,
    "noise": "norm(0, 0.1)",
    "measurement": "mean + noise",
}

graph = DistGraph(config, seed=42)
result = graph.resolve_all()
print(result["measurement"])  # 5.0 + sample from N(0, 0.1)

Features

  • 15 built-in distributionsuniform, norm, expon, gamma, beta, lognorm, weibull_min, t, chi2, f, pareto, cauchy, laplace, logistic, rayleigh
  • Distribution aliasesnormalnorm, gaussiannorm, unifuniform
  • DistGraph — automatic dependency resolution via topological sort
  • Arithmetic expressions"60 + 30 * uniform(0, 1)" with sin, cos, exp, sqrt, pi and more
  • Seed management — global seed(), context manager seed_context(), per-instance DistGraph(seed=...)
  • Bounds clipping — clamp sampled values with min/max or lbound/rbound
  • Extensible registry — register custom distributions at runtime

Docs

Full documentation at distparser.readthedocs.io.

Development

See AGENTS.md for setup and guidelines.

License

MIT

Project details


Download files

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

Source Distribution

distparser-0.3.2.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

distparser-0.3.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file distparser-0.3.2.tar.gz.

File metadata

  • Download URL: distparser-0.3.2.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for distparser-0.3.2.tar.gz
Algorithm Hash digest
SHA256 64975bdaa8382081b321ea34ecb28960a7a9f7d42d3b42a25f9c40bd668ecc0a
MD5 5fe1598b05b96a4bb33a7f1d9cf53d21
BLAKE2b-256 e17c392745c7f07d1640bfd5ef0575c3e3067a6172da51c505799ec8afae4e8c

See more details on using hashes here.

File details

Details for the file distparser-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: distparser-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for distparser-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c649bfab3cee5bc2863edf783f836dd8e0836fc8c265160002c703f3a921586c
MD5 4d3d38d6bc0831cb62d014c8eb5bf8b1
BLAKE2b-256 c32c0025f94b77e660dece0d081240e8667ec4ef21e8df5cdc87d90413244e12

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page