Skip to main content

Parse function-call strings into frozen scipy.stats distributions

Project description

distparser

Parse function‑call syntax strings into frozen scipy.stats distributions

PyPI version Python 3.8+ License: MIT

Why distparser?

When you have configuration files or user input that specifies a probability distribution (e.g. "norm(loc=0, scale=1)"), you want to turn that string into a ready‑to‑sample object. distparser does exactly that, with a tiny API and zero surprises.

Installation

pip install distparser

Quick Start

from distparser import parse_dist

# Positional arguments (order matters)
dist = parse_dist("uniform(0, 1)")
sample = dist.rvs()          # e.g. 0.374

# Keyword arguments (order ignored)
dist = parse_dist("norm(loc=0, scale=1)")
samples = dist.rvs(size=5)   # array([-0.12, 1.03, ...])

# Mixed (positional + keyword) – works, but not recommended
dist = parse_dist("expon(scale=2, loc=1)")

Supported Distributions

Built‑in registry covers the most common continuous distributions:

  • uniform(loc, scale)
  • norm(loc, scale)
  • expon(loc, scale)
  • … and many more (see docs).

You can add your own at runtime:

from distparser import register_distribution
from scipy.stats import gumbel_r

register_distribution("gumbel", gumbel_r, ["loc", "scale"])

Development

See AGENTS.md for development 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.0.tar.gz (13.0 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.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: distparser-0.3.0.tar.gz
  • Upload date:
  • Size: 13.0 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.0.tar.gz
Algorithm Hash digest
SHA256 3950b29e1e652d778ed51ff7efa89be6939238c7ba0a538bdee89ddbf6150e11
MD5 238845799cf1e296ba674020aad3afc8
BLAKE2b-256 19aa2668f1bd283b49e5056cd326e4493f470ba491852427e994c04c15c1229d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: distparser-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bbdbc51ee0ba8139a568d20eeac859b188076e937e25fe213ea1910931c7d1d
MD5 6cd35e3ab081a78efa440683dc3d90a2
BLAKE2b-256 fa95e3a278c065d6b2fbc224a357501cf8c60616d3c90ec82bd5200bc7a4a8d2

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