Beartype is a Python library that validates type annotations while a program is executing. Unlike conventional static type checkers, which examine source code without running it, Beartype can detect mismatches between declared types and the actual objects encountered during execution.
The library is intended for situations where runtime checking provides additional confidence, such as validating inputs from dynamically typed components or detecting incorrect return values during testing. It can be introduced into selected functions or applied across larger portions of an application.
Beartype concentrates on keeping the overhead of type checking low. Its checks complement conventional static analysis rather than replace it, particularly when a program interacts with untyped libraries, external data or other components whose behaviour cannot be fully determined ahead of time.
This is free and open source software.
Key Features
- Provides the @beartype decorator for checking annotated function parameters and return values during execution.
- Supports import hooks for applying type checking automatically across selected packages.
- Understands standard Python type annotations, including unions, generic containers and annotated types.
- Provides custom validators through typing.Annotated and the beartype.vale API.
- Offers procedural APIs for checking arbitrary objects against specified type hints.
- Generates detailed exceptions identifying values that violate their declared types.
- Supports configurable checking strategies for container elements, balancing performance against validation coverage.
- Generates specialised checking logic to reduce the overhead of repeated runtime validation.
Website: github.com/beartype/beartype
Support:
Developer: Beartype authors
License: MIT License
Beartype is written in Python. Learn Python with our recommended free books and free tutorials.
Related Software
| Python Linters | |
|---|---|
| Ruff | Extremely fast Python linter and code formatter |
| ty | Fast Python type checker |
| Mypy | Static type checker for Python |
| Bandit | Find security issues in Python code |
| Pylint | Static code analyser |
| wemake-python-styleguide | Flake8 plugin |
| Tach | Enforces module dependencies and architectural boundaries |
| pycodestyle | Check Python code against style conventions in PEP 8 |
| Pyflakes | Checks Python source files for errors |
| Vulture | Find dead code |
| Pyrefly | Fast type checker and language server |
| Flake8 | Wrapper around PyFlakes and pycodestyle |
| Beartype | Near-real-time hybrid runtime-static type-checker |
| Radon | Computes various metrics from Python code |
| Pyright | Full-featured, standards-compliant static type checker |
| cython-lint | Lint Cython files |
| basedpyright | Fork of pyright |
| Refurb | Modernize Python codebases |
| Pylama | Code audit tool for Python |
| Prospector | Brings together the functionality of other Python analysis tools |
| deptry | Check for dependency issues |
| Fixit | Highly configurable linting framework |
| complexipy | Measures cognitive complexity in Python code |
| Zuban | High-performance Python type checker and language server |
| Pyroma | Rates how well a Python project compiles |
| pydoclint | Python docstring linter |
| Arid | Fast duplicate code detection for Python projects |
Read our verdict in the software roundup.
Explore our carefully curated directory of recommended free and open source software, covering every major software category.The directory forms part of our extensive collection of articles for Linux enthusiasts. It includes hundreds of detailed reviews, together with free and open source alternatives to proprietary software from companies such as Google, Microsoft, Apple, Adobe, IBM, Cisco, Oracle, and Autodesk. LinuxLinks also covers interesting projects worth exploring, Linux-compatible hardware, free programming books and tutorials, and much more. Know a useful free and open source Linux application that we haven’t covered? Tell us about it using our submission form. |


Please read our Comment Policy before commenting.