stanio

0.5.1 · active · verified Thu Apr 09

stanio is a Python library providing utilities for preparing data inputs and processing outputs for Stan, a probabilistic programming language. It supports common formats like Stan's JSON and R dump (rdump). The current version is 0.5.1, with a release cadence that addresses bug fixes and minor improvements as needed.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to dump Python data structures, including NumPy arrays, into Stan's JSON format and then load them back. It covers the primary use case of `stanio` for preparing input data for Stan models.

import stanio
import numpy as np
import os

data_to_dump = {"x": np.array([1.0, 2.0]), "y": 5, "theta": [[0.1, 0.2], [0.3, 0.4]]}

# Dump data to Stan JSON format
json_file_path = "my_data.json"
stanio.dump_stan_json(data_to_dump, json_file_path)
print(f"Data dumped to {json_file_path}")

# Load data from Stan JSON format
loaded_data = stanio.load_stan_json(json_file_path)
print(f"Loaded data: {loaded_data}")

# Clean up the created file
os.remove(json_file_path)
print(f"Removed {json_file_path}")

view raw JSON →