Skip to main content

HTTP-based interface to Stan, a package for Bayesian inference.

Project description

Stan logo

pypi version

HTTP-based REST 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 REST 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 the essential functionality of the command-line interface to Stan (CmdStan) over HTTP, httpstan provides the following features:

  • Automatic caching of compiled Stan models

  • Automatic caching of samples from Stan models

  • Parallel sampling

Documentation: https://httpstan.readthedocs.org.

Requirements

  • Linux or macOS

  • C++ compiler: gcc ≥9.0 or clang ≥10.0.

Background

httpstan is a shim allowing clients able to make HTTP-based requests to call functions in the Stan C++ library’s stan::services namespace. httpstan was originally developed as a “backend” for a Stan interface written in Python, PyStan.

Stability and maintainability are two overriding goals of this software package.

Install

$ python3 -m pip install httpstan

In order to install httpstan from PyPI make sure your system satisfies the requirements:

  • Linux or macOS

  • x86-64 CPU

  • C++ compiler: gcc ≥9.0 or clang ≥10.0.

If your system uses a different kind of CPU, you should be able to install from source using the following commands:

# Build shared libraries
make

# Build the httpstan wheel on your system
python3 -m pip install poetry
python3 -m poetry build

# Install the wheel
python3 -m pip install dist/*.whl

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 -H "Content-Type: application/json" \
    --data '{"program_code":"parameters {real y;} model {y ~ normal(0,1);}"}' \
    http://localhost:8080/v1/models

This request will return a model name along with all the compiler output:

{"compiler_output": "In file included from …", "stanc_warnings": "", "name": "models/xc2pdjb4"}

(The model name depends on the platform and the version of Stan.)

Drawing samples from this model using default settings requires two steps: (1) launching the sampling operation and (2) retrieving the output of the operation (once it has finished).

First we make a request to launch the sampling operation:

curl -H "Content-Type: application/json" \
    --data '{"function":"stan::services::sample::hmc_nuts_diag_e_adapt"}' \
    http://localhost:8080/v1/models/xc2pdjb4/fits

This request instructs httpstan to draw samples from the normal distribution described in the model. The function name picks out a specific function in the stan::services namespace found in the Stan C++ library (see the Stan C++ documentation for details). This request will return immediately with a reference to a long-running fit operation:

{"name": "operations/gkf54axb", "done": false, "metadata": {"fit": {"name": "models/xc2pdjb4/fits/gkf54axb"}}}

Once the operation is complete, the “fit” can be retrieved. The name of the fit, models/xc2pdjb4/fits/gkf54axb, is included in the metadata field of the operation. The fit is saved as sequence of JSON-encoded messages. These messages are strung together with newlines. To retrieve these messages, saving them locally in the file myfit.jsonlines, make the following request:

curl http://localhost:8080/v1/models/xc2pdjb4/fits/gkf54axb > myfit.jsonlines

The Stan “fit”, saved in myfit.jsonlines, aggregates all messages. By reading them one by one you can recover all messages sent by the Stan C++ library.

Citation

We appreciate citations as they let us discover what people have been doing with the software. Citations also provide evidence of use which can help in obtaining grant funding.

To cite httpstan in publications use:

Riddell, A., Hartikainen, A., & Carter, M. (2021). httpstan (4.4.0). https://pypi.org/project/httpstan

Or use the following BibTeX entry:

@misc{httpstan,
  title = {httpstan (4.4.0)},
  author = {Riddell, Allen and Hartikainen, Ari and Carter, Matthew},
  year = {2021},
  month = mar,
  howpublished = {PyPI}
}

Please also cite Stan.

License

ISC License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

httpstan-4.13.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (45.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

httpstan-4.13.0-cp314-cp314-macosx_14_0_arm64.whl (39.6 MB view details)

Uploaded CPython 3.14macOS 14.0+ ARM64

httpstan-4.13.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (45.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

httpstan-4.13.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (45.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

httpstan-4.13.0-cp313-cp313-macosx_15_0_arm64.whl (39.7 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

httpstan-4.13.0-cp313-cp313-macosx_14_0_arm64.whl (39.6 MB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

httpstan-4.13.0-cp313-cp313-macosx_13_0_x86_64.whl (39.6 MB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

httpstan-4.13.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (45.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

httpstan-4.13.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (45.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

httpstan-4.13.0-cp312-cp312-macosx_15_0_arm64.whl (39.7 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

httpstan-4.13.0-cp312-cp312-macosx_14_0_arm64.whl (39.6 MB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

httpstan-4.13.0-cp312-cp312-macosx_13_0_x86_64.whl (39.6 MB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64

httpstan-4.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (45.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

httpstan-4.13.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (45.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

httpstan-4.13.0-cp311-cp311-macosx_15_0_arm64.whl (39.7 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

httpstan-4.13.0-cp311-cp311-macosx_14_0_arm64.whl (39.5 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

httpstan-4.13.0-cp311-cp311-macosx_13_0_x86_64.whl (39.6 MB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64

httpstan-4.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (45.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

httpstan-4.13.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (45.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

httpstan-4.13.0-cp310-cp310-macosx_15_0_arm64.whl (39.7 MB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

httpstan-4.13.0-cp310-cp310-macosx_14_0_arm64.whl (39.5 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

httpstan-4.13.0-cp310-cp310-macosx_13_0_x86_64.whl (39.6 MB view details)

Uploaded CPython 3.10macOS 13.0+ x86-64

File details

Details for the file httpstan-4.13.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 bb8dba968b0c4f4e6332e4c14ed004c07d2bce78b2bf6d47e787433c986197b2
MD5 23dd6d89400a3c06e2c54472fb3021f5
BLAKE2b-256 1a787720e37e44515011d977e3e3e25b3b800d6c7a71afcd94a71ef38f734801

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp314-cp314-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp314-cp314-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 40a5d03845c49ef2c5d60e1eda297b2e72571d1ba2f074aaf064db41e5cecedf
MD5 8715fa355555d1864ca115e9163b8b7a
BLAKE2b-256 74317bb2fb766da4ddda88bce7a6105a1d3877eaf29ba6e77ade2484698f5bd8

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 21dffe0201a5866059d2ed75322c36613421ced1a33d769b992afcc7953766f0
MD5 469a33486da31a78ac8d9de31d7ed2d1
BLAKE2b-256 2bb087f3b199e9312e7d75e68da1202f32d0a1d4046eb32702226d003ea4aeee

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 6b4e9de61b199318bef1141871bf73742a1b657cf95491f21c45c735a8ffeaa3
MD5 6b484854d06a849fb74516323ccb4f1a
BLAKE2b-256 7671546158d24a46d38b928a2406cacdb05cee0086f000e954358c32842dc8e2

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 ffa4923273585d4e91ba5168c4308b0587789de8c043bb0d00ecc0b7642ad246
MD5 07c2ec133e4daa659a6dd772b035f934
BLAKE2b-256 a50e845fb932cbe7011bc8471cfd6b207a0e653e7fd712415e433fa9b4107dfb

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7db6e08a44f89b20491f3fc46fa7cfe2bab01c7519c318648687cce68bf968da
MD5 dc78cd1976076d38dddd930ce2fe57c2
BLAKE2b-256 41218bcd1318ce59725b3c133f2c7de2c4806fbfb6e9ca03b9f125ecd69e763f

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp313-cp313-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 dfb5bc019969659d46ad3e4db93bf4c1cebb787f9b7fd32ca66fc38beca6c861
MD5 d8e7c65d07bf0e13690baa5146307b10
BLAKE2b-256 1a78390017e85b26a491df9ac0b442bb33c82e422d280c308a61e057cdd56efc

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a452f600e314f107f6bc17e43905ea2f3aaeebf8b8b98350e861aacf84476382
MD5 832cc1a7cfb2ecf7d36c84201c94ce81
BLAKE2b-256 d06e069e28610b85d93341ce830b1470aa103d19ba0eded27ab718264041e2c1

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 be64a0bfc0ea436197da07e143630980a294cc55318250e2797655e68ffdc03f
MD5 79e241092a9c22442d28743d8c2db775
BLAKE2b-256 1ad8b97e532306a8d7e0aa5d5d9b236e42851c662eb19bfba055bc880fd5b0f4

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 f225765ccc22851ce51be2300a90d70091137d559344825a25950532b26a89c7
MD5 7362a933281757dbbeb3f0f2879ee562
BLAKE2b-256 13d4a51e9f5bbf7ab50d6e975431da79cd39fd99136231ed326e2bd10720fc78

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f597aea27ea4026d8a4e175dea074d316af1ccc72b61c18bda87b53b59ddb29d
MD5 01e56a1574749a79be14e38dc5ed3cb4
BLAKE2b-256 ae59995c89214322d4705043e4beb8e05461c490f04be213c3f6f0d76caa99a6

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 046cc66f0adbf7e149361ccaa76a0e1478ed865490d1288eb91ef5007d4de590
MD5 841018b1039413c031a3502f6fec2502
BLAKE2b-256 88d5e7998ed6558debc5029f7d6f1dc60bee494ff41d2a77dc20df464a885abf

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b490d6c0e8b7048d1b58dfb79db561ae1879cb3bde3012d024ef374c0308469
MD5 5211ca5cccf33fe489a9511dbf37cc7e
BLAKE2b-256 861f4b508886d3e545aab614c20dbd5f9b1dcb7645dc180942c77474c999cf45

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 db96f12cacea0ae8efb6bddbf3061c3536b3503187befda936c6a36c1da7124d
MD5 5525a807b810850826de788cb5098ffa
BLAKE2b-256 a9b063e4d4015d78db53933b600ba97268cd3205ff54199624e95e1f9d75d303

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 c12779e92582c041ab966c0dc0b72811e4516c99e15a66be998e40550506b090
MD5 1bbf5cd58ae59d2ef0349ed4d7539768
BLAKE2b-256 86abad02bd410921d5cff5032d3bec56718c89872b5549018bb66d7d86ae87be

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c8f8d9129afbe03b05562700b3a9d3b0333ebaae75e32c7013300b7c884f2896
MD5 1f898239b00a07c737e06af6e9881d07
BLAKE2b-256 4ca9dff391bf629ef27df455d32aec63e9c56bb85d6ff864de35f39ec56e3854

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 d0c0807843d75629f61876319d5715e6a4efcc0c7b55fdbaa970baa86e7d2b09
MD5 57b926c9b9aeb026a83c95d918263893
BLAKE2b-256 0310811a8cc58cfefd114b85197444b55ad97e9fa1905e452d92ee04cd61f80f

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fc16ee696c16aa57e35e588b5b3219224a43897589861bdd6e1e610f7b6197b2
MD5 082f68216b68bb0729ac04a0f5665e02
BLAKE2b-256 a6770492bf3a332d24ea986acb74c9b1258d17a2636e7f681ebd6db74de49db5

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 563ff9949ec699426f77c86e4a8ec414c8bc36d0a1ab3fa11a2c376a9a5cdf5e
MD5 7ea528a325333f716a34f3a717f8bcd8
BLAKE2b-256 d88e88f41b3e17e7707d5b98c8b16fa99036c3f8e98cc89b0910d0884db662ad

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 37ecdf16d23cec52f624b162b3100e67c63349da8a190756a926bf4cf2c39ca6
MD5 9eff82945417b6c09e073999c2bf7dbf
BLAKE2b-256 ec532968be9bf615cfc29d2c0ba0389789756d895efe822750f2f3b00dc41e95

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4ec50f8d473c7841cf68b73845dfc1cc2c5c88cf0b4478a6f623d92cfdd61405
MD5 c12ebf032f75f68eec32c97c02caa30e
BLAKE2b-256 14eaea2acaf398d748dec25cce9e801553ead6afad9f526ca306ef7d5ae8ee2f

See more details on using hashes here.

File details

Details for the file httpstan-4.13.0-cp310-cp310-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for httpstan-4.13.0-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 d74077e482391586da9510847bd56cb7feb6fbed8b32bfc741c9067f1bb5cd17
MD5 2730c49dade85663fe00bee0b2dda7f0
BLAKE2b-256 eb349df0d62d250c8ab58a137b4f957d1962072c4c3aa1abb51240bf3a2fad44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page