numerary
Python hacks for type-checking numbers
What it is and what it does
numerary solves the problem of type-checking numeric interfaces that need to work with more than just int and float. Python's numeric tower and standard library types like Decimal and Fraction lack proper integration with the type system, leaving developers unable to write functions that accept arbitrary numeric types without breaking type-checking or resorting to overly broad annotations. numerary provides composable, runtime-checkable Protocol definitions—such as RealLike, IntegralLike, SupportsIntegralOps, and SupportsAbs—that let you declare numeric requirements precisely and have them work correctly with both type checkers and runtime isinstance checks.
The package is built on the Supports pattern from the standard library's typing module, extended with a caching protocol metaclass to handle edge cases where standard library types have inconsistent operator definitions. It targets developers writing numeric libraries, scientific code, or domain-specific interfaces that need to accept diverse numeric types while maintaining type safety. The single runtime dependency is beartype, and the package supports Python 3.8 through 3.11 on both CPython and PyPy.
Use it for:
- Define a function that accepts any real number type and type-check it correctly without forcing callers to convert.
- Build a numeric library that works with standard library numbers and third-party types, catching operator incompatibilities.
- Compose custom protocols by mixing SupportsAbs, SupportsDivmod, and other operator protocols to express precise requirements.
- Validate at runtime that an object truly supports the numeric operations your code needs, catching silent failures.
- Document numeric interfaces for scientific or financial code where type distinctions matter for correctness.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides runtime-checkable protocols and type hints for working with numeric types beyond Python's built-in int and float, enabling type-safe interfaces that accept members of the numeric tower and other numeric primitives.
Yes. If you write numeric code or libraries that need to accept diverse numeric types while maintaining type safety, numerary solves a real gap in Python's type system. It has low install friction, active maintenance, no known vulnerabilities, and a permissive license. The trade-off is that it's still marked Beta and requires deliberate use of its protocols—it won't magically fix existing code, but it will let you write new numeric interfaces correctly.
Install
numerary on PyPI
pip
pip install numeraryuv
uv add numerarypoetry
poetry add numeraryInstalling numerary
Before you install
Low friction: pure-Python wheel with a single runtime dependency on beartype. Actively maintained with a recent commit on 2026-02-27 and no known vulnerabilities.
License in practice
MIT License permits commercial and private use with minimal restrictions, requiring only license and copyright notice retention.
Quickstart
pip install numerary
from numerary import RealLike, IntegralLike
def process(arg: RealLike) -> IntegralLike:
return int(arg // 1)
Requires Python 3.8 or later; best used with a type checker like mypy to catch incompatibilities at development time.
Verify before relying
- Whether protocol implementations remain compatible with latest versions of third-party numeric libraries.
- Performance characteristics when composing multiple protocols or checking isinstance at runtime.
Package facts
| License | MIT License (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — beartype |
| Maintenance | actively maintained — 1,107 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 80,333/month — #14,298 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: numerary-0.4.4-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
typing-jsonProvides type-aware JSON serialization and…
permissive · top 15,000 on PyPI
jaxtypingProvides type annotations and runtime…
permissive · top 5,000 on PyPI
sumtypesProvides algebraic data types for Python,…
permissive · top 15,000 on PyPI
omnibase_spiDefines runtime-checkable Protocol contracts…
permissive · top 15,000 on PyPI
nptypingProvides type hints and runtime type checking…
permissive · top 15,000 on PyPI
optypeoptype provides single-method protocols and…
permissive · top 5,000 on PyPI
typishTypish provides runtime type checking and…
permissive · top 5,000 on PyPI
useful-typesProvides reusable type protocols and aliases…
unclear · top 15,000 on PyPI
infinityProvides an Infinity class that can be compared…
permissive · top 15,000 on PyPI
number-parserConverts numbers written in natural language…
permissive · top 15,000 on PyPI