Skip to main content
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
python -m pip install "poetry~=1.8"
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.

Metadata

Release files for httpstan 4.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for httpstan 4.17.0
File
httpstan-4.17.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details
httpstan-4.17.0-cp314-cp314-macosx_14_0_arm64.whl CPython 3.14 CPython 3.14 macOS 14.0+ ARM64 Details
httpstan-4.17.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
httpstan-4.17.0-cp313-cp313-macosx_14_0_arm64.whl CPython 3.13 CPython 3.13 macOS 14.0+ ARM64 Details
httpstan-4.17.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
httpstan-4.17.0-cp312-cp312-macosx_14_0_arm64.whl CPython 3.12 CPython 3.12 macOS 14.0+ ARM64 Details

Total release size: 207.8 MB

Release files / httpstan-4.17.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL httpstan-4.17.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 34.9 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c118898d4f6c0f724748a8fcefab1a27f79d6c76a717e1e1e89838dd3719f3d2
BLAKE2b-256 checksum
How to use checksums
47e8572094f499f847dabd516e520f014ae447c43e13ef059a4ac738263e588b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / httpstan-4.17.0-cp314-cp314-macosx_14_0_arm64.whl

Download URL httpstan-4.17.0-cp314-cp314-macosx_14_0_arm64.whl
Size 34.4 MB
Tags CPython 3.14 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
5a6cb7afec68f81b2595b4cfacaa53c09386ad8bf9dec477ac79a141e7516658
BLAKE2b-256 checksum
How to use checksums
170f229d591e715f1707a639ccd688965bb8b548f68491f1200379e9f32ba48e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.0

Release files / httpstan-4.17.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL httpstan-4.17.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 34.8 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b05349967ad19a6970d4392732653b8ad98839cb3cb7a7e8a493ae70a264988e
BLAKE2b-256 checksum
How to use checksums
83243dc1da7d3075e40377dd51bde9d7e98e899236efe727994ccb3f3fc8d004
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.20

Release files / httpstan-4.17.0-cp313-cp313-macosx_14_0_arm64.whl

Download URL httpstan-4.17.0-cp313-cp313-macosx_14_0_arm64.whl
Size 34.4 MB
Tags CPython 3.13 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
f1559fce9ae4aaff28e5faaad368591a43d158869b378fc0ed2fea9731ee8510
BLAKE2b-256 checksum
How to use checksums
2f1af9f7d4682aefd7821bedeb47fde1c61f1bdd294bd71c870d6ac16dddbb5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.9

Release files / httpstan-4.17.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL httpstan-4.17.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 34.9 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7f73e29a415718ddc45e4703c0253a9d4adc6a21aa7110ccf36821a0f94202cd
BLAKE2b-256 checksum
How to use checksums
b205e30d9b5ddcf4cc9f8460d24890044ce67d81bb147998e084f85e1c05fb57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / httpstan-4.17.0-cp312-cp312-macosx_14_0_arm64.whl

Download URL httpstan-4.17.0-cp312-cp312-macosx_14_0_arm64.whl
Size 34.4 MB
Tags CPython 3.12 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
ce276d71c7bfe82f1c3f84f19a472dbccbbd3f23b265f7d09b68dd611457fad3
BLAKE2b-256 checksum
How to use checksums
a1db47052dec5699c94cd2fad338ee1d1bd5f44e486665dade4f4a4de604b7b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

4.17.0 This release

6 release files

4.11.0

8 release files

4.10.1

8 release files

4.9.1

8 release files

4.9.0

8 release files

4.8.2

11 release files

4.8.1

6 release files

4.8.0

6 release files

4.7.2

11 release files

4.7.1

6 release files

4.7.0

6 release files

4.6.1

11 release files

4.6.0

6 release files

4.5.0

6 release files

4.4.2

9 release files

4.4.1

8 release files

4.4.0

9 release files

4.3.2

6 release files

4.3.1

8 release files

4.3.0

8 release files

4.2.1

4 release files

4.1.0

6 release files

4.0.0

6 release files

2.3.0

5 release files

2.2.0

5 release files

2.1.0

4 release files

2.0.5

4 release files

2.0.4

4 release files

2.0.3

4 release files

2.0.2

2 release files

2.0.1

2 release files

1.1.4

1 release file

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

5 release files

0.10.1

5 release files

0.9.0

1 release file

0.8.0

4 release files

0.7.6

4 release files

0.7.5

4 release files

0.7.3

0.7.2

4 release files

0.7.1

4 release files

0.7.0

4 release files

0.6.1

4 release files

0.6.0

4 release files

0.5.0

1 release file

0.4.0

2 release files

0.3.1

2 release files

0.3.0

1 release file

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page