marimo-scipy-utils


Namemarimo-scipy-utils JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryA collection of utilities to make it easier to interact with scipy in a marimo notebook, e.g. manipulate distributions, visualize data, etc.
upload_time2025-07-16 20:42:39
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseNone
keywords scipy matplotlib marimo distributions statistics visualization data analysis data visualization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI](https://img.shields.io/pypi/v/marimo-scipy-utils.svg)](https://pypi.org/project/marimo-scipy-utils/)
[![Lint and Typecheck](https://github.com/hbmartin/marimo-scipy-utils/actions/workflows/lint.yml/badge.svg)](https://github.com/hbmartin/marimo-scipy-utils/actions/workflows/lint.yml)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Code style: black](https://img.shields.io/badge/🐧️-black-000000.svg)](https://github.com/psf/black)

# Marimo SciPy Utils

Utility functions for creating interactive marimo components with scipy distributions.

This package provides functions for creating and configuring interactive UI elements in marimo notebooks, with a focus on parameter input and visualization using scipy probability distributions.

<img src="media/demo.png" />

## Installation

```bash
uv add marimo-scipy-utils
```

## Functions

[See example notebook here](https://github.com/hbmartin/ai-roi-mcm-npv-marimo/blob/main/ai_roi_mcm_npv.py)

### `abbrev_format(x: float, pos: int | None) -> str`

Format numbers with k/M suffixes for thousands/millions.

**Parameters:**
- `x`: The number to format
- `pos`: The tick position (unused but required by matplotlib formatter interface)

**Returns:**
- `str`: The formatted number string with k/M suffix if applicable

**Example:**
```python
abbrev_format(1500, None)  # Returns "2k"
abbrev_format(2500000, None)  # Returns "3M"
abbrev_format(42.7, None)  # Returns "42.7"
```

### `display_sliders(name: str, sliders: mo.ui.dictionary | mo.ui.slider, invars: dict[str, dict], dist: str | Callable | None = None, descriptions: dict = {}) -> mo.Html`

Display parameter sliders with optional distribution plot.

**Parameters:**
- `name`: Name of the parameter group to display
- `sliders`: Either a single slider or dictionary of sliders for distribution params
- `invars`: Dictionary to store input variable configurations
- `dist`: Distribution to use (string name or callable), required for multi-sliders
- `descriptions`: Optional dict mapping parameter names to descriptions

**Returns:**
- Marimo component displaying the sliders and optional distribution plot

For a single slider, displays it as a constant parameter. For multiple sliders, displays them with a plot of the resulting distribution. Distribution must be specified for multiple sliders, either as a string name matching a scipy distribution or as a callable distribution object.

**Raises:**
- `DistributionConfigurationError`: If dist is None for multiple sliders

### `generate_ranges(distribution: str, ranged_distkwargs: dict) -> dict`

Generate parameter ranges for a probability distribution.

Takes a distribution name and dictionary of parameter ranges, validates the ranges against allowed bounds for that distribution, and returns a merged dictionary with complete range specifications.

**Parameters:**
- `distribution`: Name of the probability distribution (e.g. "normal", "beta")
- `ranged_distkwargs`: Dictionary mapping parameter names to their range specifications. Each range spec should have "lower" and "upper" bounds.

**Returns:**
- `dict`: Complete parameter range specifications with distribution defaults merged with provided ranges

**Raises:**
- `MissingParameterError`: If a required parameter range is not provided
- `ParameterBoundError`: If a provided range exceeds the allowed bounds for a param

### `params_sliders(ranged_distkwargs: dict) -> mo.ui.dictionary`

Create a dictionary of sliders for parameter ranges.

Takes a dictionary of param ranges and creates interactive sliders for each param. The sliders will be bounded by the lower/upper values specified in the ranges dict. The step size and initial value can optionally be specified per param.

**Parameters:**
- `ranged_distkwargs`: Dictionary mapping parameter names to their range specifications. Each range spec should have "lower" and "upper" bounds, and optionally "step" and "value" keys.

**Returns:**
- `mo.ui.dictionary`: A dictionary of marimo slider UI elements, one per parameter. Each slider will be configured according to the parameter's range spec.

**Example:**
```python
ranges = {
    "mean": {"lower": 0, "upper": 100, "step": 1, "value": 50},
    "std": {"lower": 0, "upper": 10}
}
sliders = params_sliders(ranges)
```

## Supported Distributions

Any scipy distribution can be used.

Included helpers following scipy distributions:
- `uniform`: Uniform distribution
- `triang`: Triangular distribution
- `beta`: Beta distribution
- `norm`: Normal distribution

## Dependencies

- marimo
- matplotlib
- scipy

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "marimo-scipy-utils",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "scipy, matplotlib, marimo, distributions, statistics, visualization, data analysis, data visualization",
    "author": null,
    "author_email": "Harold Martin <Harold.Martin@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/4b/07/4648d11228ef22298a864f3ef2b3ab648a7e27f0a3941762fe6946cbcd10/marimo_scipy_utils-0.1.1.tar.gz",
    "platform": null,
    "description": "[![PyPI](https://img.shields.io/pypi/v/marimo-scipy-utils.svg)](https://pypi.org/project/marimo-scipy-utils/)\n[![Lint and Typecheck](https://github.com/hbmartin/marimo-scipy-utils/actions/workflows/lint.yml/badge.svg)](https://github.com/hbmartin/marimo-scipy-utils/actions/workflows/lint.yml)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![Code style: black](https://img.shields.io/badge/\ud83d\udc27\ufe0f-black-000000.svg)](https://github.com/psf/black)\n\n# Marimo SciPy Utils\n\nUtility functions for creating interactive marimo components with scipy distributions.\n\nThis package provides functions for creating and configuring interactive UI elements in marimo notebooks, with a focus on parameter input and visualization using scipy probability distributions.\n\n<img src=\"media/demo.png\" />\n\n## Installation\n\n```bash\nuv add marimo-scipy-utils\n```\n\n## Functions\n\n[See example notebook here](https://github.com/hbmartin/ai-roi-mcm-npv-marimo/blob/main/ai_roi_mcm_npv.py)\n\n### `abbrev_format(x: float, pos: int | None) -> str`\n\nFormat numbers with k/M suffixes for thousands/millions.\n\n**Parameters:**\n- `x`: The number to format\n- `pos`: The tick position (unused but required by matplotlib formatter interface)\n\n**Returns:**\n- `str`: The formatted number string with k/M suffix if applicable\n\n**Example:**\n```python\nabbrev_format(1500, None)  # Returns \"2k\"\nabbrev_format(2500000, None)  # Returns \"3M\"\nabbrev_format(42.7, None)  # Returns \"42.7\"\n```\n\n### `display_sliders(name: str, sliders: mo.ui.dictionary | mo.ui.slider, invars: dict[str, dict], dist: str | Callable | None = None, descriptions: dict = {}) -> mo.Html`\n\nDisplay parameter sliders with optional distribution plot.\n\n**Parameters:**\n- `name`: Name of the parameter group to display\n- `sliders`: Either a single slider or dictionary of sliders for distribution params\n- `invars`: Dictionary to store input variable configurations\n- `dist`: Distribution to use (string name or callable), required for multi-sliders\n- `descriptions`: Optional dict mapping parameter names to descriptions\n\n**Returns:**\n- Marimo component displaying the sliders and optional distribution plot\n\nFor a single slider, displays it as a constant parameter. For multiple sliders, displays them with a plot of the resulting distribution. Distribution must be specified for multiple sliders, either as a string name matching a scipy distribution or as a callable distribution object.\n\n**Raises:**\n- `DistributionConfigurationError`: If dist is None for multiple sliders\n\n### `generate_ranges(distribution: str, ranged_distkwargs: dict) -> dict`\n\nGenerate parameter ranges for a probability distribution.\n\nTakes a distribution name and dictionary of parameter ranges, validates the ranges against allowed bounds for that distribution, and returns a merged dictionary with complete range specifications.\n\n**Parameters:**\n- `distribution`: Name of the probability distribution (e.g. \"normal\", \"beta\")\n- `ranged_distkwargs`: Dictionary mapping parameter names to their range specifications. Each range spec should have \"lower\" and \"upper\" bounds.\n\n**Returns:**\n- `dict`: Complete parameter range specifications with distribution defaults merged with provided ranges\n\n**Raises:**\n- `MissingParameterError`: If a required parameter range is not provided\n- `ParameterBoundError`: If a provided range exceeds the allowed bounds for a param\n\n### `params_sliders(ranged_distkwargs: dict) -> mo.ui.dictionary`\n\nCreate a dictionary of sliders for parameter ranges.\n\nTakes a dictionary of param ranges and creates interactive sliders for each param. The sliders will be bounded by the lower/upper values specified in the ranges dict. The step size and initial value can optionally be specified per param.\n\n**Parameters:**\n- `ranged_distkwargs`: Dictionary mapping parameter names to their range specifications. Each range spec should have \"lower\" and \"upper\" bounds, and optionally \"step\" and \"value\" keys.\n\n**Returns:**\n- `mo.ui.dictionary`: A dictionary of marimo slider UI elements, one per parameter. Each slider will be configured according to the parameter's range spec.\n\n**Example:**\n```python\nranges = {\n    \"mean\": {\"lower\": 0, \"upper\": 100, \"step\": 1, \"value\": 50},\n    \"std\": {\"lower\": 0, \"upper\": 10}\n}\nsliders = params_sliders(ranges)\n```\n\n## Supported Distributions\n\nAny scipy distribution can be used.\n\nIncluded helpers following scipy distributions:\n- `uniform`: Uniform distribution\n- `triang`: Triangular distribution\n- `beta`: Beta distribution\n- `norm`: Normal distribution\n\n## Dependencies\n\n- marimo\n- matplotlib\n- scipy\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A collection of utilities to make it easier to interact with scipy in a marimo notebook, e.g. manipulate distributions, visualize data, etc.",
    "version": "0.1.1",
    "project_urls": null,
    "split_keywords": [
        "scipy",
        " matplotlib",
        " marimo",
        " distributions",
        " statistics",
        " visualization",
        " data analysis",
        " data visualization"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "47573326c3f97c66d941ec222867837795a6699e687bb3d1218a1fe747a2b3b5",
                "md5": "40fbe4de9ab0f76fbae9d972dd907624",
                "sha256": "9232946a37a3c8c6f154cd975058194d0d6f025ee7cfd6612d970951ca73ed52"
            },
            "downloads": -1,
            "filename": "marimo_scipy_utils-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "40fbe4de9ab0f76fbae9d972dd907624",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 11848,
            "upload_time": "2025-07-16T20:42:38",
            "upload_time_iso_8601": "2025-07-16T20:42:38.190409Z",
            "url": "https://files.pythonhosted.org/packages/47/57/3326c3f97c66d941ec222867837795a6699e687bb3d1218a1fe747a2b3b5/marimo_scipy_utils-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4b074648d11228ef22298a864f3ef2b3ab648a7e27f0a3941762fe6946cbcd10",
                "md5": "7c3171f1ab36ebb32576da2ca690b52a",
                "sha256": "09bbfc70d49b80b2582b6039bff9f9b0b36e0a79336a6403ca739040ce103ad2"
            },
            "downloads": -1,
            "filename": "marimo_scipy_utils-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7c3171f1ab36ebb32576da2ca690b52a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 10720,
            "upload_time": "2025-07-16T20:42:39",
            "upload_time_iso_8601": "2025-07-16T20:42:39.670061Z",
            "url": "https://files.pythonhosted.org/packages/4b/07/4648d11228ef22298a864f3ef2b3ab648a7e27f0a3941762fe6946cbcd10/marimo_scipy_utils-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-16 20:42:39",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "marimo-scipy-utils"
}
        
Elapsed time: 1.42631s