Parse function-call strings into frozen scipy.stats distributions
Project description
distparser
Parse function‑call syntax strings into frozen scipy.stats distributions
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file distparser-0.2.0.tar.gz.
File metadata
- Download URL: distparser-0.2.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a73a4a8b8f2b9f38c033e6792f7e54beea837b50d3230bc179807508678d3ba1
|
|
| MD5 |
e99f3181c6f85b4edd480383648ba6da
|
|
| BLAKE2b-256 |
7e0d29668e2c95a926604349694c636e0cfec5a196ddbc3d4d64eb1999144e01
|
File details
Details for the file distparser-0.2.0-py3-none-any.whl.
File metadata
- Download URL: distparser-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
102ce14d1d6908c7948011737dee67f96eedfb9f6861cd399c8303732aec2e5c
|
|
| MD5 |
dffc2887c30da0917841e793663ef112
|
|
| BLAKE2b-256 |
83c668e784203cf57dc1d29473d432f2dab9c1ffe94f51c403a9e0aac57c9f09
|