cmdstanjupyter
This extension provides syntax highlighting for Stan code in JupyterLab, as well as a %%stan magic command
to define Stan models in Jupyter notebooks and build them with CmdStanPy.
Requirements
- JupyterLab >= 4.0.0
Install
To install the extension, execute:
pip install cmdstanjupyter
Note: this does not install CmdStanPy for you, in case you are only interested
in Stan syntax highlighting and not the %%stan magic!
Install it separately using pip or conda!
Usage
To use the magic in your notebook, you need to lead the extension:
%load_ext cmdstanjupyter
To define a stan model inside a jupyter notebook, start a cell with the %%stan
magic. You can also provide a variable name, which is the variable name that
the cmdstanpy.CmdStanModel object will be assigned to. For example:
%%stan paris_female_births
data {
int male;
int female;
}
parameters {
real<lower=0, upper=1> p;
}
model {
female ~ binomial(male + female, p);
}
When you run this cell, cmdstanjupyter will create a cmdstanpy CmdStanModel object,
which will compile your model and allow you to sample from it.
If the above code was stored in a file births.stan, the following is equivalent:
%stanf births.stan paris_female_births
To use your compiled model:
fit = paris_female_births.sample(
data={'male': 251527, 'female': 241945},
)
Credits
The %magic is heavily based on the previous jupyterstan package. The highlighting code is inspired by jupyterlab-stata-highlight.
Metadata
Release files for cmdstanjupyter 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cmdstanjupyter-2.1.0.tar.gz | 90.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cmdstanjupyter-2.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 110.2 kB
Release files / cmdstanjupyter-2.1.0.tar.gz
| Download URL | cmdstanjupyter-2.1.0.tar.gz |
|---|---|
| Size | 90.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e5fa21ecc73f842d6881cef4f379bd97c3ab97da94cb3b5f2a10df8c6c80bbf
|
|
BLAKE2b-256 checksum How to use checksums |
fd6b8ed1917e5110aa79b142196c65a08127158056fc9803024d3a12f07aa850
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / cmdstanjupyter-2.1.0-py3-none-any.whl
| Download URL | cmdstanjupyter-2.1.0-py3-none-any.whl |
|---|---|
| Size | 19.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1564121ac0a5e97ee49b68e8cc991da08976287c9fa4a9a9cccbf170a49715d4
|
|
BLAKE2b-256 checksum How to use checksums |
4dbdfb0bd8723e699193a19d6b5cd11ead27cae12f7126da86dad9e795dc32a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|