Open-source project
beartype/beartype avatar
beartype/beartype

beartype: runtime type checking for Python

Unbearably fast near-real-time pure-Python runtime-static type-checker.

3,519 stars98 forksPythonMIT

At a glance

What is it?
beartype is a pure-Python runtime type checker that enforces type hints at call time. It suits teams who want type errors caught during execution, not just in CI, but its exception-based model changes how failures surface in production.
Who is it for?
beartype fits teams that already annotate their code and want violations to surface as exceptions during execution, especially in test suites and at package boundaries. It is a poor fit for hot loops where every call is measured, since enforcement happens on each invocation.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 1 day ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 24, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • beartype/beartype3,519 ★ · +22
Star history
Repository2026-09-242026-11-24
beartype/beartype3.5k3.5k

22 Stars in the last 61 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

What beartype enforces that static checkers cannot

Static analyzers read annotations and report mismatches before the program runs. They cannot see what a function actually receives at call time, because that depends on data. beartype closes that gap: the README describes it as a "pure-Python PEP-compliant constant-time runtime type checker" that validates arguments and return values as calls happen. The audience is Python developers who annotate their code and want those annotations to do something during execution, not only during linting. That includes library authors checking inputs at a public boundary, test authors catching bad fixtures, and teams debugging a function that receives something unexpected from a caller they do not control. The project targets Python 3, and the README notes that Annotated is available from typing on Python 3.9.0 and later, with typing_extensions as the fallback below that.

The default constant-time strategy samples container elements rather than checking every element on every call. Use a validation method that exhaustively checks input when complete validation of an untrusted collection is required.

How the decorator and the claw import hook differ

There are two entry points, and they impose different costs. The @beartype decorator wraps a single callable. The README shows it applied to a function, with a violation producing a BeartypeCallHintParamViolation exception that names the parameter, the offending value, and the type hint it failed. The second entry point is the claw import hook. Calling beartype_this_package() at the top of a package's __init__ submodule makes beartype implicitly type-check all annotated classes, callables, and variable assignments across all submodules of that package. That is a much larger surface, and it happens without touching each function. The README also shows beartype_all(conf=BeartypeConf(violation_type=UserWarning)), which extends checking to other packages but downgrades their violations to warnings while your own package still raises exceptions. That split is the interesting design choice: you get signal from dependencies without your application crashing on someone else's bug. The cost is that the hook runs at import time, so anything it wraps is wrapped for the life of the process.

Installing beartype and checking a first function

The README gives the install command directly. It pulls the package from PyPI and places it in the active environment.

bash
pip install beartype

After that, the smallest useful step is decorating one function. The README's example takes a list of strings and prints them; calling it with a list of bytes raises an exception naming the parameter and the failing item.

python
from beartype import beartype

@beartype
def quote_wiggum(lines: list[str]) -> None:
    print('\n '.join(lines))

quote_wiggum(["Okay, folks. Show's over!"])

Passing bytes instead of strings produces a BeartypeCallHintParamViolation. The message is specific: it identifies the parameter, the value, and the type hint that was violated. That specificity is the reason to use this over a bare assert.

To apply checking across an entire package rather than one function, the README puts two lines at the top of the package's __init__ submodule.

python
from beartype.claw import beartype_this_package
beartype_this_package()

With that in place, every annotated callable in every submodule of the package is checked. The README does not document a rollback or disable path for the import hook, so the decision is effectively made when the package is imported.

Validators extend hints beyond types

Type hints describe shapes, not values. The README addresses that with beartype.vale.Is, a validator factory used inside Annotated. A validator is a lambda that the runtime evaluates against the actual value. The README's example builds ListOfStrings as Annotated[list[str], Is[lambda lst: bool(lst)]], which matches a non-empty list of strings. The inner hint checks element types while the lambda checks emptiness. Under the default O(1) strategy, beartype samples a randomly selected container item rather than exhaustively checking every item on each call, so a mixed-type list may pass a particular call. This is the part of beartype that goes past what a static checker can express, because the constraint lives in code rather than in the type system. It also means the lambda runs on every call that reaches the validator, so a validator that does real work adds real cost. The README does not quantify that cost.

Where beartype is the wrong tool

Runtime checking is not free, and beartype's own description of itself as constant-time does not mean zero-time. Every decorated call performs validation before the function body runs. In a tight loop that executes millions of times, that per-call work is a real addition, and the decorator is the wrong choice for the innermost function. The claw hook amplifies this: it wraps annotated callables across an entire package, including ones you did not intend to instrument. A second limitation is the failure mode. Violations raise exceptions. In a request handler, an unexpected argument type that a static checker would have flagged before deploy now becomes a 500 at runtime. The beartype_all example exists precisely because checking other people's code can be too aggressive; the README's own framing treats warnings as the safer default for dependencies. If your codebase has no annotations, beartype has nothing to check, and adding annotations purely to satisfy it is a separate project. Static analyzers remain the better fit when the goal is to fail a build rather than fail a call.

Alternatives and how they differ in approach

mypy is the natural comparison and the one people search for. It reads your source, follows annotations, and reports errors without executing anything. It can catch an inconsistency in a branch that never runs in your test suite. beartype cannot, because it only sees calls that actually happen. The trade is reversed for dynamic data: mypy cannot know that a JSON payload will arrive with an integer where a string was declared, and beartype can. typeguard occupies similar ground to beartype, also enforcing hints at runtime through decoration and import hooks; the difference is in the implementation surface and the validator mechanism, since beartype's Is validators let constraints be expressed inline in the annotation. pydantic is a different category. It validates data at model boundaries, typically when parsing input into a structured object, and it is designed around that boundary rather than around arbitrary callables. If your problem is validating an API payload, pydantic is the more direct tool. If your problem is that a function deep in your code received the wrong type from an internal caller, beartype addresses it and pydantic does not.

Licence and maintenance cost

beartype is MIT licensed, which permits commercial use, modification, and redistribution provided the copyright notice and permission notice are retained. That is a permissive licence with no copyleft obligation on your own code. It does not, on its own, tell you whether the project will keep working with future Python releases. The repository shows a test suite, a tox configuration, and separate mypy, pyright, and pytest configuration files, which indicates the maintainers test against multiple type checkers and environments. The most recent release listed is a release candidate, v0.23.0rc1, dated 2026-09-12, with the last push to the repository on 2026-09-23. An rc means the version is not yet final, so pinning to a stable release such as v0.22.9 is the more conservative choice for production. The upgrade cost is mostly annotation work: because beartype validates whatever hints you write, hints that were previously decorative become executable constraints, and a hint that was wrong but never enforced will start raising.

Editorial conclusion

beartype fits teams that already annotate their code and want violations to surface as exceptions during execution, especially in test suites and at package boundaries. It is a poor fit for hot loops where every call is measured, since enforcement happens on each invocation. Before adopting, verify how the claw import hook interacts with your package layout and whether the default exception type is acceptable in production paths.

Frequently asked questions

Does Python have runtime type checking?

Not built in. The standard library provides annotations but does not enforce them. beartype adds enforcement by decorating callables or by installing an import hook that checks annotated code as it loads.

How does beartype compare to mypy?

mypy is a static checker: it reads source without running it. beartype validates types at call time, so it catches mismatches that depend on runtime data, which a static pass cannot see. The two are complementary rather than replacements.

What is an alternative to beartype?

typeguard also enforces type hints at runtime, using decoration and import hooks. pydantic is a different approach entirely, validating data at model boundaries rather than at arbitrary callables.

Official sources

  1. beartype/beartype on GitHub
  2. License: MIT
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/beartype-beartype.svg)](https://hysenlabs.com/projects/beartype-beartype)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/beartype-beartype.svg)](https://hysenlabs.com/projects/beartype-beartype)

Was this useful?