chex
Chex: Testing made fun, in JAX!
What it is and what it does
Chex is a testing and debugging library for JAX code that bridges the gap between Python's type system and JAX's array constraints. It provides shape, rank, dtype, and device assertions that work within JAX's tracing model, along with utilities to test code across variants (jitted vs non-jitted execution). The library also includes JAX-compatible dataclass implementations and helpers to detect unintended function re-tracing during JIT compilation.
The package is built on top of jax, jaxlib, numpy, and related dependencies. It's designed for machine learning practitioners and researchers who need to catch shape mismatches, type errors, and numerical issues early in development. Assertions can be customized with exception types and messages, and value assertions (those requiring actual tensor values) are supported within jitted functions via the chex.chexify() decorator.
Use it for:
- Add shape and dtype validation to JAX functions to catch dimension mismatches before they propagate through a training loop.
- Test the same JAX code path under both jitted and non-jitted execution to verify correctness across compilation modes.
- Detect unintended JIT re-tracing that causes performance degradation by asserting maximum trace counts.
- Validate that model parameters remain finite during training with custom error messages.
- Create JAX-compatible dataclasses that work seamlessly with tree operations.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Chex provides utilities for writing reliable JAX code, including assertions for tensor properties, debugging helpers, and test variants to validate code across different JAX execution modes.
Yes. Chex is actively maintained, has no known vulnerabilities, and provides essential utilities for JAX development. The low install friction, permissive license, and focus on catching common JAX pitfalls make it a practical addition to any JAX project. Install it if you write JAX code and want better visibility into shape, dtype, and execution-mode issues.
Install
chex on PyPI
pip
pip install chexuv
uv add chexpoetry
poetry add chexInstalling chex
Before you install
Low friction installation with six runtime dependencies including jax, jaxlib, and numpy. Active maintenance with a recent release 63 days ago and ongoing repository activity.
License in practice
Permissive license allows broad use, modification, and distribution with minimal restrictions.
Quickstart
pip install chex
import chex
import jax.numpy as jnp
@chex.dataclass
class Parameters:
x: chex.ArrayDevice
y: chex.ArrayDevice
parameters = Parameters(
x=jnp.ones((2, 2)),
y=jnp.ones((1, 2)),
)
chex.assert_equal_shape([parameters.x, parameters.y])
Requires Python 3.11 or later; jax and jaxlib must be installed and functional.
Verify before relying
- Whether all assertion types work identically in jitted vs non-jitted contexts without additional setup
- Performance overhead of value assertions when using chex.chexify() wrapper in production code
- Compatibility guarantees with specific JAX versions beyond the stated Python 3.11+ requirement
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — absl-py, typing_extensions, jax, jaxlib, numpy, toolz |
| Maintenance | actively maintained — 63 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,315,756/month — #3,144 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: chex-0.1.92-py3-none-any.whl
Keywords: jax, testing, debugging, python, machine learning
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
distraxDistrax provides JAX-native probability…
permissive · top 15,000 on PyPI
jaxJAX is a Python library for automatic…
permissive · top 1,000 on PyPI
jaxtypingProvides type annotations and runtime…
permissive · top 5,000 on PyPI
jaxlibjaxlib is the compiled XLA backend that enables…
permissive · top 5,000 on PyPI
jax-jumpyJax-jumpy provides a unified interface that…
permissive · top 15,000 on PyPI
mujoco-mjxA JAX-based reimplementation of the MuJoCo…
permissive · top 15,000 on PyPI
optaxOptax provides composable building blocks for…
permissive · top 5,000 on PyPI
re-assertProvides a helper class for regex assertions…
permissive · top 15,000 on PyPI
torchaxtorchax is a PyTorch backend that runs PyTorch…
permissive · top 15,000 on PyPI
etilsA modular collection of utility submodules for…
permissive · top 5,000 on PyPI