{"id":1728,"library":"stanio","title":"stanio","description":"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.","status":"active","version":"0.5.1","language":"python","source_language":"en","source_url":"https://github.com/stan-dev/stanio","tags":["stan","bayesian","data-science","io","serialization","numpy"],"install":[{"cmd":"pip install stanio","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for handling numerical arrays and matrices, which are fundamental data structures for Stan models.","package":"numpy","optional":false}],"imports":[{"symbol":"dump_stan_json","correct":"from stanio import dump_stan_json"},{"symbol":"load_stan_json","correct":"from stanio import load_stan_json"},{"symbol":"dump_rdump","correct":"from stanio import dump_rdump"},{"symbol":"load_rdump","correct":"from stanio import load_rdump"}],"quickstart":{"code":"import stanio\nimport numpy as np\nimport os\n\ndata_to_dump = {\"x\": np.array([1.0, 2.0]), \"y\": 5, \"theta\": [[0.1, 0.2], [0.3, 0.4]]}\n\n# Dump data to Stan JSON format\njson_file_path = \"my_data.json\"\nstanio.dump_stan_json(data_to_dump, json_file_path)\nprint(f\"Data dumped to {json_file_path}\")\n\n# Load data from Stan JSON format\nloaded_data = stanio.load_stan_json(json_file_path)\nprint(f\"Loaded data: {loaded_data}\")\n\n# Clean up the created file\nos.remove(json_file_path)\nprint(f\"Removed {json_file_path}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to stanio version 0.5.1 or newer to ensure correct handling of `numpy.matrix`. Alternatively, convert `numpy.matrix` objects to standard `numpy.ndarray` before dumping.","message":"Older versions of stanio (prior to v0.5.1) had issues when dumping `numpy.matrix` types to JSON, potentially leading to incorrect serialization or errors.","severity":"gotcha","affected_versions":"<0.5.1"},{"fix":"Carefully review Stan's data block requirements. For potentially ambiguous types (e.g., empty collections, mixed-type lists), explicitly convert them to `numpy.ndarray` with appropriate dtypes before passing to `stanio.dump_stan_json` or `stanio.dump_rdump`.","message":"Ensure Python data types align with Stan's expected types. While stanio handles many conversions, complex nested structures or unusual scalar types might not map directly, leading to Stan errors. For example, empty lists might not be interpreted as empty arrays if Stan expects a fixed-size array.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.5.1':38 'address':44 'bayesian':53 'bug':45 'cadenc':42 'common':24 'current':35 'data':11,55 'data-sci':54 'dump':32 'fix':46 'format':25 'improv':49 'input':12 'io':57 'json':29 'languag':21 'librari':6 'like':26 'minor':48 'need':51 'numpi':59 'output':15 'prepar':10 'probabilist':19 'process':14 'program':20 'provid':7 'python':5 'r':31 'rdump':33 'releas':41 'scienc':56 'serial':58 'stan':17,27,52 'stanio':1,2 'support':23 'util':8 'version':36","created_at":"2026-04-09T04:00:35.232053+00:00","updated_at":"2026-04-16T22:20:38.756009+00:00","problems":[{"fix":"Ensure the data argument passed to the dump function is a dictionary or a compatible mapping object.","cause":"The `stanio.dump_rdump` or `stanio.dump_stan_json` function received a data argument that was not a dictionary-like object (a `Mapping`), but rather a different type like a string or list.","error":"TypeError: argument of type 'str' is not a `Mapping` object"},{"fix":"Review and correct the syntax of the R dump file to ensure it conforms to the expected R dump format, fixing issues like missing quotes, unbalanced parentheses, or incorrect assignments.","cause":"The R dump file (`.R` data file) provided to `stanio.read_rdump` contains malformed syntax, preventing the `stanio` parser from correctly interpreting its content.","error":"stanio.rdump_parser.RDumpSyntaxError: Expected `\"` but got `eof` at line 1, column 19."},{"fix":"Correct the import statement to refer to the actual functions available directly under `stanio`, such as `dump_rdump`, `read_rdump`, `dump_stan_json`, or `read_stan_json`.","cause":"The import statement is attempting to access a submodule or class (e.g., `Rump`) that does not exist within the `stanio` library, likely due to a typo or misunderstanding of the library's structure.","error":"ModuleNotFoundError: No module named 'stanio.Rump'"},{"fix":"Consult the `stanio` documentation or use IDE introspection (tab-completion) to verify the correct function names and their usage, calling only existing attributes.","cause":"The code is attempting to call a function or access an attribute (e.g., `some_non_existent_func`) that does not exist directly within the `stanio` module's public API.","error":"AttributeError: module 'stanio' has no attribute 'some_non_existent_func'"},{"fix":"Open the output file in binary write mode (`'wb'`) when providing a file object to `stanio.dump_rdump` or `stanio.dump_stan_json`.","cause":"When using `stanio.dump_rdump` or `stanio.dump_stan_json` with a file object, the file was opened in text mode (`'w'`), but the library attempts to write binary data to it, which requires the file to be opened in binary write mode (`'wb'`).","error":"TypeError: write() argument must be str, not bytes"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.5.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/stan-dev/stanio","docs":null,"changelog":null,"pypi":"https://pypi.org/project/stanio/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":null}}