httpstan


Namehttpstan JSON
Version 4.12.0 PyPI version JSON
download
home_pagehttps://mc-stan.org
SummaryHTTP-based interface to Stan, a package for Bayesian inference.
upload_time2024-02-07 00:36:03
maintainer
docs_urlNone
authorAllen Riddell
requires_python>=3.9,<4.0
licenseISC
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ========
httpstan
========

.. image:: https://raw.githubusercontent.com/stan-dev/logos/master/logo.png
    :alt: Stan logo
    :height: 333px
    :width: 333px
    :scale: 40 %

|pypi|

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 <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
=======

.. These instructions appear in both README.rst and installation.rst

::

    $ 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.

.. _shim: https://en.wikipedia.org/wiki/Shim_%28computing%29
.. _CmdStan: http://mc-stan.org/interfaces/cmdstan.html
.. _PyStan: http://mc-stan.org/interfaces/pystan.html
.. _Stan: http://mc-stan.org/
.. _`OpenAPI documentation for httpstan`: api.html

.. |pypi| image:: https://img.shields.io/pypi/v/httpstan.svg
    :target: https://pypi.org/project/httpstan/
    :alt: pypi version


            

Raw data

            {
    "_id": null,
    "home_page": "https://mc-stan.org",
    "name": "httpstan",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Allen Riddell",
    "author_email": "riddella@indiana.edu",
    "download_url": "",
    "platform": null,
    "description": "========\nhttpstan\n========\n\n.. image:: https://raw.githubusercontent.com/stan-dev/logos/master/logo.png\n    :alt: Stan logo\n    :height: 333px\n    :width: 333px\n    :scale: 40 %\n\n|pypi|\n\nHTTP-based REST interface to Stan, a package for Bayesian inference.\n\nAn HTTP 1.1 interface to the Stan_ C++ package, **httpstan** is a shim_ that\nallows users to interact with the Stan C++ library using a REST API. The\npackage is intended for use as a universal backend for frontends which know how\nto make HTTP requests. The primary audience for this package is developers.\n\nIn addition to providing the essential functionality of the command-line interface\nto Stan (CmdStan_) over HTTP, **httpstan** provides the following features:\n\n* Automatic caching of compiled Stan models\n* Automatic caching of samples from Stan models\n* Parallel sampling\n\nDocumentation: `https://httpstan.readthedocs.org <https://httpstan.readthedocs.org>`_.\n\nRequirements\n============\n\n- Linux or macOS\n- C++ compiler: gcc \u22659.0 or clang \u226510.0.\n\nBackground\n==========\n\n**httpstan** is a shim_ allowing clients able to make HTTP-based requests to\ncall functions in the Stan C++ library's ``stan::services`` namespace.\n**httpstan** was originally developed as a \"backend\" for a Stan interface\nwritten in Python, PyStan_.\n\nStability and maintainability are two overriding goals of this software package.\n\nInstall\n=======\n\n.. These instructions appear in both README.rst and installation.rst\n\n::\n\n    $ python3 -m pip install httpstan\n\nIn order to install httpstan from PyPI make sure your system satisfies the requirements:\n\n- Linux or macOS\n- x86-64 CPU\n- C++ compiler: gcc \u22659.0 or clang \u226510.0.\n\nIf your system uses a different kind of CPU, you should be able to install from source using the following commands:\n\n::\n\n    # Build shared libraries\n    make\n\n    # Build the httpstan wheel on your system\n    python3 -m pip install poetry\n    python3 -m poetry build\n\n    # Install the wheel\n    python3 -m pip install dist/*.whl\n\n\nUsage\n=====\n\nAfter installing ``httpstan``, running the module will begin listening on\nlocalhost, port 8080::\n\n    python3 -m httpstan\n\nIn a different terminal, make a POST request to\n``http://localhost:8080/v1/models`` with Stan program code to compile the\nprogram::\n\n    curl -H \"Content-Type: application/json\" \\\n        --data '{\"program_code\":\"parameters {real y;} model {y ~ normal(0,1);}\"}' \\\n        http://localhost:8080/v1/models\n\nThis request will return a model name along with all the compiler output::\n\n    {\"compiler_output\": \"In file included from \u2026\", \"stanc_warnings\": \"\", \"name\": \"models/xc2pdjb4\"}\n\n(The model ``name`` depends on the platform and the version of Stan.)\n\nDrawing samples from this model using default settings requires two steps: (1)\nlaunching the sampling operation and (2) retrieving the output of the operation\n(once it has finished).\n\nFirst we make a request to launch the sampling operation::\n\n    curl -H \"Content-Type: application/json\" \\\n        --data '{\"function\":\"stan::services::sample::hmc_nuts_diag_e_adapt\"}' \\\n        http://localhost:8080/v1/models/xc2pdjb4/fits\n\nThis request instructs ``httpstan`` to draw samples from the normal\ndistribution described in the model. The function name picks out a specific\nfunction in the ``stan::services`` namespace found in the Stan C++ library (see\nthe Stan C++ documentation for details).  This request will return immediately\nwith a reference to a long-running fit operation::\n\n    {\"name\": \"operations/gkf54axb\", \"done\": false, \"metadata\": {\"fit\": {\"name\": \"models/xc2pdjb4/fits/gkf54axb\"}}}\n\nOnce the operation is complete, the \"fit\" can be retrieved. The name of the fit,\n``models/xc2pdjb4/fits/gkf54axb``, is included in the ``metadata`` field of the operation.\nThe fit is saved as sequence of JSON-encoded messages. These messages are strung together\nwith newlines. To retrieve these messages, saving them locally in the file\n``myfit.jsonlines``, make the following request::\n\n    curl http://localhost:8080/v1/models/xc2pdjb4/fits/gkf54axb > myfit.jsonlines\n\nThe Stan \"fit\", saved in ``myfit.jsonlines``, aggregates all messages. By reading\nthem one by one you can recover all messages sent by the Stan C++ library.\n\nCitation\n========\n\nWe appreciate citations as they let us discover what people have been doing\nwith the software. Citations also provide evidence of use which can help in\nobtaining grant funding.\n\nTo cite httpstan in publications use:\n\nRiddell, A., Hartikainen, A., & Carter, M. (2021). httpstan (4.4.0). https://pypi.org/project/httpstan\n\nOr use the following BibTeX entry::\n\n    @misc{httpstan,\n      title = {httpstan (4.4.0)},\n      author = {Riddell, Allen and Hartikainen, Ari and Carter, Matthew},\n      year = {2021},\n      month = mar,\n      howpublished = {PyPI}\n    }\n\nPlease also cite Stan.\n\nLicense\n=======\n\nISC License.\n\n.. _shim: https://en.wikipedia.org/wiki/Shim_%28computing%29\n.. _CmdStan: http://mc-stan.org/interfaces/cmdstan.html\n.. _PyStan: http://mc-stan.org/interfaces/pystan.html\n.. _Stan: http://mc-stan.org/\n.. _`OpenAPI documentation for httpstan`: api.html\n\n.. |pypi| image:: https://img.shields.io/pypi/v/httpstan.svg\n    :target: https://pypi.org/project/httpstan/\n    :alt: pypi version\n\n",
    "bugtrack_url": null,
    "license": "ISC",
    "summary": "HTTP-based interface to Stan, a package for Bayesian inference.",
    "version": "4.12.0",
    "project_urls": {
        "Documentation": "https://httpstan.readthedocs.io",
        "Homepage": "https://mc-stan.org",
        "Repository": "https://github.com/stan-dev/httpstan"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b26bc87d4447b781c022b23f784f822e614e23b09b066c2f16de254f9a691e4",
                "md5": "8e5a285f3262026024dc5a113197d1ee",
                "sha256": "10674be45e91834f7ab3d813e4086af5147e016490e4a7016c48d2196baedfe5"
            },
            "downloads": -1,
            "filename": "httpstan-4.12.0-cp310-cp310-macosx_11_0_x86_64.whl",
            "has_sig": false,
            "md5_digest": "8e5a285f3262026024dc5a113197d1ee",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.9,<4.0",
            "size": 37039012,
            "upload_time": "2024-02-07T00:36:03",
            "upload_time_iso_8601": "2024-02-07T00:36:03.321622Z",
            "url": "https://files.pythonhosted.org/packages/5b/26/bc87d4447b781c022b23f784f822e614e23b09b066c2f16de254f9a691e4/httpstan-4.12.0-cp310-cp310-macosx_11_0_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "75c84917bdf2b41cae0dbbe1e4bd309e5ee2bcd50fba0c04d6715220e465d9f2",
                "md5": "a4fca22f192be433205d5a59de08c6b3",
                "sha256": "a5dc681d0c414c41029774311381566983b74a1f02d4afdbd31ba4ae3abd8970"
            },
            "downloads": -1,
            "filename": "httpstan-4.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "a4fca22f192be433205d5a59de08c6b3",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.9,<4.0",
            "size": 45271702,
            "upload_time": "2024-02-07T00:29:26",
            "upload_time_iso_8601": "2024-02-07T00:29:26.023032Z",
            "url": "https://files.pythonhosted.org/packages/75/c8/4917bdf2b41cae0dbbe1e4bd309e5ee2bcd50fba0c04d6715220e465d9f2/httpstan-4.12.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "28088fa629ddf1e45ead2a886b280d7ff351fe0495a9a2b1367de76226121098",
                "md5": "f2ede4bc2d611b1185696b16647721ed",
                "sha256": "9f162b762821136c42dd83cb34813db691c01931464b351d4e49914992ce5c4d"
            },
            "downloads": -1,
            "filename": "httpstan-4.12.0-cp311-cp311-macosx_11_0_x86_64.whl",
            "has_sig": false,
            "md5_digest": "f2ede4bc2d611b1185696b16647721ed",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.9,<4.0",
            "size": 37035097,
            "upload_time": "2024-02-07T00:39:57",
            "upload_time_iso_8601": "2024-02-07T00:39:57.294806Z",
            "url": "https://files.pythonhosted.org/packages/28/08/8fa629ddf1e45ead2a886b280d7ff351fe0495a9a2b1367de76226121098/httpstan-4.12.0-cp311-cp311-macosx_11_0_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0269df7e2f09bf8f7a9c981556c8f96b7511669dc565ddb81c821ffbef090a47",
                "md5": "a1a68fcc121b39a316327ac094a03e56",
                "sha256": "57abf96d8235a6e7a07ace4d4fbd5ce72c5be042ff1738d1b927bc450af2ead2"
            },
            "downloads": -1,
            "filename": "httpstan-4.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "a1a68fcc121b39a316327ac094a03e56",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.9,<4.0",
            "size": 45276780,
            "upload_time": "2024-02-07T00:29:05",
            "upload_time_iso_8601": "2024-02-07T00:29:05.836125Z",
            "url": "https://files.pythonhosted.org/packages/02/69/df7e2f09bf8f7a9c981556c8f96b7511669dc565ddb81c821ffbef090a47/httpstan-4.12.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1657a13aa64187ff81994038e7caaa3139e48d2f9f9bc96cd4af919f7cdab6bb",
                "md5": "6faeabae805990a57a59f1d4442c1e84",
                "sha256": "87d4741f7f895fc94318f904fe420749d21401a822e6e95158618741d128ba45"
            },
            "downloads": -1,
            "filename": "httpstan-4.12.0-cp38-cp38-macosx_10_16_x86_64.whl",
            "has_sig": false,
            "md5_digest": "6faeabae805990a57a59f1d4442c1e84",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.9,<4.0",
            "size": 37032794,
            "upload_time": "2024-02-07T00:35:18",
            "upload_time_iso_8601": "2024-02-07T00:35:18.719552Z",
            "url": "https://files.pythonhosted.org/packages/16/57/a13aa64187ff81994038e7caaa3139e48d2f9f9bc96cd4af919f7cdab6bb/httpstan-4.12.0-cp38-cp38-macosx_10_16_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9a9f70a2bde3e23e578a4af37d00bd16518e71313dc210117eacf302c2aad55",
                "md5": "594147582a3b6ebde085a6d75e6ac701",
                "sha256": "7677ca51af1c464e2b040f4fee02e915ab32a5bf3b1373951c9329c94cba0707"
            },
            "downloads": -1,
            "filename": "httpstan-4.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "594147582a3b6ebde085a6d75e6ac701",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.9,<4.0",
            "size": 45274052,
            "upload_time": "2024-02-07T00:29:21",
            "upload_time_iso_8601": "2024-02-07T00:29:21.223400Z",
            "url": "https://files.pythonhosted.org/packages/c9/a9/f70a2bde3e23e578a4af37d00bd16518e71313dc210117eacf302c2aad55/httpstan-4.12.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d645b08ee40f522b33caa94d53669444fdf22580a35a07d07f653923fc57f412",
                "md5": "c2b82ff361ff2e567a1135a92ae4feae",
                "sha256": "c4ebe188a12c08a53f29fcf3b657dad607e7bb9cac84c22457c7b1c3408725e4"
            },
            "downloads": -1,
            "filename": "httpstan-4.12.0-cp39-cp39-macosx_10_16_x86_64.whl",
            "has_sig": false,
            "md5_digest": "c2b82ff361ff2e567a1135a92ae4feae",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.9,<4.0",
            "size": 37039014,
            "upload_time": "2024-02-07T00:35:10",
            "upload_time_iso_8601": "2024-02-07T00:35:10.426074Z",
            "url": "https://files.pythonhosted.org/packages/d6/45/b08ee40f522b33caa94d53669444fdf22580a35a07d07f653923fc57f412/httpstan-4.12.0-cp39-cp39-macosx_10_16_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5bca073a26d457b840051e3d6313bf7ffde9453fa785b4e3d668e38ab71886c9",
                "md5": "d7b14921f014a38be03ffb333a3a4a4a",
                "sha256": "27faebf6bb7757d356f1c51377297ef3ab8e3fc32e8c5bf751ecedc3bcc7222e"
            },
            "downloads": -1,
            "filename": "httpstan-4.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "d7b14921f014a38be03ffb333a3a4a4a",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.9,<4.0",
            "size": 45273629,
            "upload_time": "2024-02-07T00:29:10",
            "upload_time_iso_8601": "2024-02-07T00:29:10.551077Z",
            "url": "https://files.pythonhosted.org/packages/5b/ca/073a26d457b840051e3d6313bf7ffde9453fa785b4e3d668e38ab71886c9/httpstan-4.12.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-07 00:36:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stan-dev",
    "github_project": "httpstan",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "httpstan"
}
        
Elapsed time: 0.47737s