Skip to content

Getting Started

bearshape turns annotations like F32[N, C] into runtime-validated contracts by generating small runtime hint classes for arrays and trees. Beartype validates those hints through __instancecheck__(), and bearshape provides readable failures through __instancecheck_str__().

The root bearshape module is intentionally lightweight: it exports dimension symbols, tree structure symbols, DtypeSpec, the custom array factories, and the memo helpers. Backend modules such as bearshape.numpy, bearshape.jax, bearshape.torch, and bearshape.cupy add concrete array aliases once you install those dependencies.

Start here

  • Installation — Python requirements, backend-specific install commands, and optional dependency boundaries.
  • Quick Start — Your first @beartype-checked function, cross-argument consistency, and return validation.
  • Static Typing — What passes on pyright, mypy, and ty, and what still needs targeted runtime-only workarounds.

What bearshape gives you

  • Standard @beartype support. No custom decorator is required for normal shape checking.
  • Cross-argument memo binding. If one parameter binds N = 32, later parameters and the return annotation must agree.
  • Backend-specific array aliases for NumPy, JAX, PyTorch, and CuPy.
  • Like and ScalarLike input contracts for data-conversion APIs.
  • Explicit memo tools for tricky call stacks, async functions, and manual is_bearable() checks.

Where to go next

  • Dimensions explains named, fixed, variadic, broadcastable, anonymous, symbolic, and Value(...)-based shape tokens.
  • Array Types covers dtype families, structured dtypes, endianness, and backend differences.
  • Tree Annotations covers leaf validation plus structure matching for pytrees.