Home

Awesome

<img alt="boost-histogram logo" width="402" src="https://raw.githubusercontent.com/scikit-hep/boost-histogram/develop/docs/_images/BoostHistogramPythonLogo.png"/>

boost-histogram for Python

Actions Status Documentation Status

PyPI version Conda-Forge PyPI platforms DOI

GitHub Discussion Gitter Scikit-HEP

Python bindings for Boost::Histogram (source), a C++14 library. This is one of the fastest libraries for histogramming, while still providing the power of a full histogram object. See what's new.

Other members of the boost-histogram family include:

Usage

Slideshow of features. See expandable text below if the image is not readable.

<details><summary>Text intro (click to expand)</summary>
import boost_histogram as bh

# Compose axis however you like; this is a 2D histogram
hist = bh.Histogram(
    bh.axis.Regular(2, 0, 1),
    bh.axis.Regular(4, 0.0, 1.0),
)

# Filling can be done with arrays, one per dimension
hist.fill(
    [0.3, 0.5, 0.2],
    [0.1, 0.4, 0.9],
)

# NumPy array view into histogram counts, no overflow bins
values = hist.values()

# Make a new histogram with just the second axis, summing over the first, and
# rebinning the second into larger bins:
h2 = hist[::sum, :: bh.rebin(2)]
</details>

We support the uhi PlottableHistogram protocol, so boost-histogram/Hist histograms can be plotted via any compatible library, such as mplhep.

Cheatsheet

<details><summary>Simplified list of features (click to expand)</summary> </details>

Installation

You can install this library from PyPI with pip:

python3 -m pip install boost-histogram

All the normal best-practices for Python apply; Pip should not be very old (Pip 9 is very old), you should be in a virtual environment, etc. Python 3.7+ is required; for older versions of Python (3.5 and 2.7), 0.13 will be installed instead, which is API equivalent to 1.0, but will not be gaining new features. 1.3.x was the last series to support Python 3.6.

Binaries available:

The easiest way to get boost-histogram is to use a binary wheel, which happens when you run the above command on a supported platform. Wheels are produced using cibuildwheel; all common platforms have wheels provided in boost-histogram:

SystemArchPython versionsPyPy versions
ManyLinux201464-bit3.7, 3.8, 3.9, 3.10, 3.11, 3.123.7, 3.8, 3.9, 3.10
ManyLinux2014ARM643.7, 3.8, 3.9, 3.10, 3.11, 3.123.7, 3.8, 3.9, 3.10
MuslLinux_1_164-bit3.7, 3.8, 3.9, 3.10, 3.11, 3.12
macOS 10.9+64-bit3.7, 3.8, 3.9, 3.10, 3.11, 3.123.7, 3.8, 3.9, 3.10
macOS Universal2Arm643.8, 3.9, 3.10, 3.11, 3.12
Windows32 & 64-bit3.7, 3.8, 3.9, 3.10, 3.11, 3.12
Windows64-bit3.7, 3.8, 3.9, 3.10

If you are on a Linux system that is not part of the "many" in manylinux or musl in musllinux, such as ClearLinux, building from source is usually fine, since the compilers on those systems are often quite new. It will just take longer to install when it is using the sdist instead of a wheel. All dependencies are header-only and included.

Conda-Forge

The boost-histogram package is available on conda-forge, as well. All supported variants are available.

conda install -c conda-forge boost-histogram

Source builds

For a source build, for example from an "SDist" package, the only requirements are a C++14 compatible compiler. The compiler requirements are dictated by Boost.Histogram's C++ requirements: gcc >= 5.5, clang >= 3.8, or msvc >= 14.1. You should have a version of pip less than 2-3 years old (10+).

Boost is not required or needed (this only depends on included header-only dependencies). You can install directly from GitHub if you would like.

python -m pip install git+https://github.com/scikit-hep/boost-histogram.git@develop

Developing

See CONTRIBUTING.md for details on how to set up a development environment.

Contributors

We would like to acknowledge the contributors that made this project possible (emoji key):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tr> <td align="center"><a href="http://iscinumpy.gitlab.io"><img src="https://avatars1.githubusercontent.com/u/4616906?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Henry Schreiner</b></sub></a><br /><a href="#maintenance-henryiii" title="Maintenance">🚧</a> <a href="https://github.com/scikit-hep/boost-histogram/commits?author=henryiii" title="Code">💻</a> <a href="https://github.com/scikit-hep/boost-histogram/commits?author=henryiii" title="Documentation">📖</a></td> <td align="center"><a href="https://github.com/HDembinski"><img src="https://avatars0.githubusercontent.com/u/2631586?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hans Dembinski</b></sub></a><br /><a href="#maintenance-HDembinski" title="Maintenance">🚧</a> <a href="https://github.com/scikit-hep/boost-histogram/commits?author=HDembinski" title="Code">💻</a></td> <td align="center"><a href="http://lovelybuggies.github.io"><img src="https://avatars3.githubusercontent.com/u/29083689?v=4?s=100" width="100px;" alt=""/><br /><sub><b>N!no</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/commits?author=LovelyBuggies" title="Tests">⚠️</a> <a href="https://github.com/scikit-hep/boost-histogram/commits?author=LovelyBuggies" title="Documentation">📖</a></td> <td align="center"><a href="https://github.com/jpivarski"><img src="https://avatars0.githubusercontent.com/u/1852447?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jim Pivarski</b></sub></a><br /><a href="#ideas-jpivarski" title="Ideas, Planning, & Feedback">🤔</a></td> <td align="center"><a href="https://github.com/nsmith-"><img src="https://avatars3.githubusercontent.com/u/6587412?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Nicholas Smith</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/issues?q=author%3Ansmith-" title="Bug reports">🐛</a></td> <td align="center"><a href="http://www-pnp.physics.ox.ac.uk/~huffman/"><img src="https://avatars3.githubusercontent.com/u/45843291?v=4?s=100" width="100px;" alt=""/><br /><sub><b>physicscitizen</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/issues?q=author%3Aphysicscitizen" title="Bug reports">🐛</a></td> <td align="center"><a href="https://www.linkedin.com/in/chanchal-kumar-maji-9230a9145/"><img src="https://avatars1.githubusercontent.com/u/31502077?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Chanchal Kumar Maji</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/commits?author=ChanchalKumarMaji" title="Documentation">📖</a></td> </tr> <tr> <td align="center"><a href="https://ddavis.io/"><img src="https://avatars2.githubusercontent.com/u/3202090?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Doug Davis</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/issues?q=author%3Adouglasdavis" title="Bug reports">🐛</a></td> <td align="center"><a href="https://github.com/pgrimaud"><img src="https://avatars1.githubusercontent.com/u/1866496?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Pierre Grimaud</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/commits?author=pgrimaud" title="Documentation">📖</a></td> <td align="center"><a href="https://github.com/beojan"><img src="https://avatars0.githubusercontent.com/u/3727925?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Beojan Stanislaus</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/issues?q=author%3Abeojan" title="Bug reports">🐛</a></td> <td align="center"><a href="https://github.com/Popinaodude"><img src="https://avatars2.githubusercontent.com/u/20911987?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Popinaodude</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/issues?q=author%3APopinaodude" title="Bug reports">🐛</a></td> <td align="center"><a href="https://github.com/colizz"><img src="https://avatars2.githubusercontent.com/u/44885400?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Congqiao Li</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/issues?q=author%3Acolizz" title="Bug reports">🐛</a></td> <td align="center"><a href="https://github.com/alexander-held"><img src="https://avatars0.githubusercontent.com/u/45009355?v=4?s=100" width="100px;" alt=""/><br /><sub><b>alexander-held</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/issues?q=author%3Aalexander-held" title="Bug reports">🐛</a></td> <td align="center"><a href="https://github.com/chrisburr"><img src="https://avatars3.githubusercontent.com/u/5220533?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Chris Burr</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/commits?author=chrisburr" title="Documentation">📖</a></td> </tr> <tr> <td align="center"><a href="https://keybase.io/kgizdov"><img src="https://avatars.githubusercontent.com/u/3164953?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Konstantin Gizdov</b></sub></a><br /><a href="#platform-kgizdov" title="Packaging/porting to new platform">📦</a> <a href="https://github.com/scikit-hep/boost-histogram/issues?q=author%3Akgizdov" title="Bug reports">🐛</a></td> <td align="center"><a href="http://theoryandpractice.org"><img src="https://avatars.githubusercontent.com/u/4458890?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kyle Cranmer</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/commits?author=cranmer" title="Documentation">📖</a></td> <td align="center"><a href="http://amangoel.me"><img src="https://avatars.githubusercontent.com/u/10528392?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aman Goel</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/commits?author=amangoel185" title="Documentation">📖</a> <a href="https://github.com/scikit-hep/boost-histogram/commits?author=amangoel185" title="Code">💻</a></td> <td align="center"><a href="http://jay-gohil.me"><img src="https://avatars.githubusercontent.com/u/59703162?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jay Gohil</b></sub></a><br /><a href="https://github.com/scikit-hep/boost-histogram/commits?author=gohil-jay" title="Documentation">📖</a></td> </tr> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the all-contributors specification.

Talks and other documentation/tutorial sources

The official documentation is here, and includes a quickstart.


Acknowledgements

This library was primarily developed by Henry Schreiner and Hans Dembinski.

Support for this work was provided by the National Science Foundation cooperative agreement OAC-1836650 (IRIS-HEP) and OAC-1450377 (DIANA/HEP). Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the National Science Foundation.