Registry / type-stubs / jaxtyping

jaxtyping

JSON →
library0.3.11pypypi✓ verified 24d ago

jaxtyping provides type annotations and optional runtime checking for the shape and data type (dtype) of array-like objects across various numerical libraries such as JAX, NumPy, and PyTorch. It extends Python's type hinting system to express array dimensions, allowing for robust static analysis and helping to catch shape-related errors early. The current version is 0.3.9, and it maintains an active development pace with frequent updates.

pip install jaxtyping
INSTALL
IMPORT
SIG · JAXTYPING
J
jaxtyping
type-stubspythonv0.3.11
Install
1.8s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.000s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Array
from jaxtyping import Array
from jaxtyping import Array
Float
from jaxtyping import Float
from jaxtyping import Float
Int
from jaxtyping import Int
from jaxtyping import Int

This quickstart demonstrates how to use `jaxtyping` to annotate JAX arrays with shape and dtype information. It defines functions that perform matrix multiplication and array summation, using `Float` and `Int` types with string literal shapes. Crucially, it shows how to enable runtime checking with `set_array_typecheck_enabled(True)` to enforce these annotations, catching shape mismatches at runtime rather than relying solely on static analysis.

from jaxtyping import Array, Float, Int, set_array_typecheck_enabled import jax import jax.numpy as jnp # Enable runtime checks for demonstration set_array_typecheck_enabled(True) def matrix_multiply( A: Float[Array, 'rows cols'], B: Float[Array, 'cols other_cols'] ) -> Float[Array, 'rows other_cols']: """Multiplies two matrices, checking shapes at runtime.""" return jnp.matmul(A, B) def sum_array( x: Int[Array, '...'] ) -> Int[Array, '']: """Sums an array of integers.""" return jnp.sum(x) # --- Example Usage --- key = jax.random.PRNGKey(0) # Valid multiplication matrix_A = jax.random.normal(key, (3, 4)) matrix_B = jax.random.normal(key, (4, 5)) result = matrix_multiply(matrix_A, matrix_B) print(f"Valid matrix multiplication result shape: {result.shape}") # Invalid multiplication (runtime error if checks are enabled) try: matrix_C = jax.random.normal(key, (3, 5)) _ = matrix_multiply(matrix_A, matrix_C) except Exception as e: print(f"Caught expected error for invalid shapes: {e.__class__.__name__}: {e}") # Integer array sum int_array = jnp.array([1, 2, 3], dtype=jnp.int32) int_sum = sum_array(int_array) print(f"Integer array sum: {int_sum}")
Debug
Known issues
gotchajaxtyping annotations are purely static by default. To enable runtime shape and dtype checking, you must explicitly call `jaxtyping.set_array_typecheck_enabled(True)` somewhere at the start of your program. Without this, shape errors will only be caught by static type checkers.
fix
Add `from jaxtyping import set_array_typecheck_enabled; set_array_typecheck_enabled(True)` to your application's entry point if you desire runtime validation.
affects: All versions
breakingThe `DType` type (used for annotating the data type of an array) was removed in version 0.3.0. This was done to simplify the API and resolve conflicts with PEP 646. Code using `DType` will no longer work.
fix
Replace `DType` annotations with direct Python type hints like `float`, `int`, or JAX/NumPy dtypes (e.g., `jnp.float32`) within the `Array` type, e.g., `Array[float, '...']` instead of `Array[DType[float], '...']`.
affects: >=0.3.0
deprecatedThe `jaxtyping.set_active` function, previously used to enable/disable runtime checks, has been deprecated. It has been replaced by `jaxtyping.set_array_typecheck_enabled` for clearer intent.
fix
Update calls from `jaxtyping.set_active(True/False)` to `jaxtyping.set_array_typecheck_enabled(True/False)`.
affects: >=0.2.x
Upgrade
Version history
0.3.11latest on PyPI · released Jun 13, 2026
Audit
Dependencies
jaxoptionalRequired for JAX array type checking.
numpyoptionalRequired for NumPy array type checking.
torchoptionalRequired for PyTorch tensor type checking.
Agent activity
34 hits · last 30 days
node
26
OpenAI (training)
1
Resources
jaxtyping — pip install jaxtyping · libregistry