skillfed

uhi

Unified Histogram Interface: tools to help library authors work with histograms

uhi v1.1.1 430.4K downloads/30d#6,728 on PyPI21
Permissive license BSD-3-Clause Active released

What it is and what it does

UHI is a standards library that defines how histogram objects should behave across different scientific Python libraries. It provides type protocols—especially PlottableHistogram—that libraries like boost-histogram, hist, and uproot conform to, enabling code to work with histograms from multiple sources without knowing their concrete type. The package includes runtime-checkable protocols so you can use isinstance() to verify conformance, plus a utility to convert NumPy-style histogram tuples (counts, edges) into objects that match the standard interface.

The package is designed primarily as a dependency for library authors and type checkers rather than end-user code, though it does expose a few useful runtime tools. It depends only on numpy and typing-extensions, making it lightweight to include in projects that need histogram interoperability. The active maintenance and support for current Python versions (3.10+) ensures it stays aligned with modern scientific Python practices.

Use it for:

  • Type-check histogram objects from different libraries to ensure they conform to a common interface before passing them to plotting functions.
  • Adapt NumPy histogram tuples (counts, edges) into standardized PlottableHistogram objects for compatibility with libraries expecting the protocol.
  • Document and enforce histogram indexing conventions across a multi-library scientific computing project.
  • Support library development by providing reference protocols that new histogram implementations can conform to.
  • Enable runtime verification that a histogram object supports the expected methods and attributes without tight coupling to a specific library.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

UHI defines and documents a standard interface for histogram objects across libraries, providing type protocols for runtime checking and tools to adapt NumPy-style histogram tuples into a common format.

Yes, if you are building libraries that work with histograms from multiple sources or need to enforce histogram interface standards. Install as a type-checking or testing dependency in projects that depend on histogram libraries like boost-histogram or hist. Not necessary for end-user code that only uses a single histogram library, but adds minimal friction and provides real value in interoperability scenarios.

Install

uhi on PyPI

pip

pip install uhi

uv

uv add uhi

poetry

poetry add uhi

Installing uhi

Before you install

Low install friction with only numpy and typing-extensions as runtime dependencies. Actively maintained with recent releases; primarily designed as a type-checking and testing dependency for other libraries rather than a direct runtime requirement.

License in practice

BSD-3-Clause is permissive and places no significant restrictions on use or redistribution in commercial or open-source contexts.

Quickstart

pip install uhi

import uhi.typing.plotting
from uhi.numpy_plottable import ensure_plottable_histogram

# Check if an object conforms to PlottableHistogram protocol
isinstance(histogram_obj, uhi.typing.plotting.PlottableHistogram)

# Adapt NumPy-style histogram tuple to PlottableHistogram
plottable = ensure_plottable_histogram(counts, edges)

Requires Python 3.10 or later.

Verify before relying

  • Whether the runtime-usable components (numpy_plottable adapter, protocol runtime checking) are sufficient for direct use or if this is primarily a transitive dependency.
  • Performance characteristics when using isinstance() checks against PlottableHistogram at runtime in tight loops.

Package facts

License BSD-3-Clause (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 2 — numpy, typing-extensions
Maintenance actively maintained — 110 days since the last release
Last repo commit
First released
Downloads 430,415/month — #6,728 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: uhi-1.1.1-py3-none-any.whl

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Science/ResearchOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Scientific/EngineeringTyping :: Typed

Tags

histogram interface standardplottable histogram protocolcross-library histogram compatibilityhistogram type checkingnumpy histogram adapterhistogram indexing standardscikit-hep histogram tools
histogram-interoptype-protocolsscikit-hep

More Scientific/Engineering packages