HTTP interface to Stan, a package for Bayesian inference.
An HTTP 1.1 interface to the Stan C++ package, httpstan is a shim that allows users to interact with the Stan C++ library using a Web API. The package is intended for use as a universal backend for frontends which know how to make HTTP requests. The primary audience for this package is developers.
In addition to providing all the functionality of the command-line interface to Stan (CmdStan) over HTTP 1.1, httpstan provides:
Automatic caching of compiled Stan models
Automatic caching of samples from Stan models
Parallel sampling
Important Disclaimer
httpstan is experimental software. This software is not intended for general use.
httpstan currently requires Python 3.6 as it uses asynchronous generators (PEP525). Support for Python 3.5 may emerge at some point. No older versions of Python will be supported.
Background
httpstan is a shim allowing clients speaking HTTP to call functions in the Stan C++ package’s stan::services namespace. httpstan was originally developed as a “backend” for a Python interface to Stan, PyStan.
Install
python3 -m pip install httpstan
Install from Source
make cython # genreate C++ code from Cython .pyx files make protos # generate Python modules for protocol buffer schemas python3 setup.py install
Usage
After installing httpstan, running the module will begin listening on localhost, port 8080:
python3 -m httpstan
In a different terminal, make a POST request to http://localhost:8080/v1/models with Stan program code to compile the program:
curl -X POST -H "Content-Type: application/json" \
-d '{"program_code":"parameters {real y;} model {y ~ normal(0,1);}"}' \
http://localhost:8080/v1/models
This request will return a model id similar to the following:
{"model": {"id": "8137474d19926b0aa8efd4f1d3944131d59269d97a7bd8dab8e79d667eb314df"}}
(The model id will be different on different platforms and with different versions of Stan.)
To draw samples from this model using default settings, we make the following request:
curl -X POST -H "Content-Type: application/json" \
-d '{"type":"stan::services::sample::hmc_nuts_diag_e_adapt"}' \
http://localhost:8080/v1/models/8137474d19926b0aa8efd4f1d3944131d59269d97a7bd8dab8e79d667eb314df/actions
This request will return samples from the normal distribution. The output is taken directly from the output of the relevant function defined in the Stan C++ package. Consult the Stan C++ documentation for details.
Contribute
Contribution guidelines are described in CONTRIBUTE.rst.
License
ISC License.
Metadata
Release files for httpstan 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| httpstan-0.2.5-cp36-cp36m-manylinux1_x86_64.whl | CPython 3.6 | CPython 3.6 pymalloc | Linux glibc 2.5+ x86-64 | Details |
| httpstan-0.2.5-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl | CPython 3.6 | CPython 3.6 pymalloc | macOS 10.9+ Intel (x86-64, i386), macOS 10.10+ Intel (x86-64, i386), macOS 10.9+ x86-64, macOS 10.6+ Intel (x86-64, i386), macOS 10.10+ x86-64 | Details |
Total release size: 73.9 MB
Release files / httpstan-0.2.5-cp36-cp36m-manylinux1_x86_64.whl
| Download URL | httpstan-0.2.5-cp36-cp36m-manylinux1_x86_64.whl |
|---|---|
| Size | 48.6 MB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
4c1490f461bab3b7632f8d659034a750616d5ef246ef2cf99b855faf5db6117f
|
|
BLAKE2b-256 checksum How to use checksums |
bb98e3f927c0e85d756c8e702ca4d59557148f8dde13874ce1b1dff1a71ad5fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / httpstan-0.2.5-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
| Download URL | httpstan-0.2.5-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl |
|---|---|
| Size | 25.3 MB |
| Tags | CPython 3.6 CPython 3.6 pymalloc macOS 10.10+ Intel (x86-64, i386) macOS 10.10+ x86-64 macOS 10.6+ Intel (x86-64, i386) macOS 10.9+ Intel (x86-64, i386) macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
7c051d63cb080cbc02cbc433f27ac7ff83b35b6f14215f6da087281a9f87e44f
|
|
BLAKE2b-256 checksum How to use checksums |
26f6a8038a2dd7f7f25664a2995da9129958bf8b4e74ee3f449f53947f9b1aa2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |