type-enforced
A pure python type enforcer for python type annotations
Decision gist · record as of 2026-08-14
Yes, if you need runtime type validation for development or testing. The package is lightweight, actively maintained, has no dependencies, and works with modern Python. Best suited for catching type errors during development or in non-performance-critical code paths; consider static type checkers like mypy for production-grade type safety without runtime overhead.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.11 or higher; earlier Python versions require older package versions with reduced feature support.
- Low friction installation with no runtime dependencies.
- Active maintenance with recent release (71 days ago) and steady repository activity.
License · maintenance · safety
permissive license (permissive) — MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects.
last release 2026-06-04 (71 days) · last repo commit 2026-07-02 · 62 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 295,015 downloads/mo, #7,933 on PyPI
Alternatives
Verify before relying
pip install type_enforced
import type_enforced
@type_enforced.Enforcer(enabled=True, strict=True)
def my_fn(a: int, b: int | str = 2) -> None:
pass
my_fn(1, "test") # passes
my_fn("invalid", 2) # raises TypeError- Performance overhead compared to static type checkers or other runtime enforcers at scale
- Whether sampling via iterable_sample_pct is sufficient for production type safety guarantees
- Support for forward references and string annotations in all contexts
What it is and what it does
Type Enforced is a pure-Python runtime type checker that validates function and method signatures against their type annotations at execution time. It works as a decorator that can be applied to functions, methods, and classes, checking both input arguments and return values against their declared types. The package supports standard Python types, union types (both `int | str` and `typing.Union` syntax), nested generics like `dict[str, list[int]]`, and many typing module constructs including `Optional`, `Literal`, and `Any`.
The decorator offers configurable behavior: strict mode raises exceptions on type mismatches, non-strict mode logs warnings instead, and clean traceback mode hides internal stack frames for clarity. For large iterables, you can sample a percentage of items rather than checking all of them to reduce overhead. It requires Python 3.11 or higher for full feature support, though older versions can use earlier package releases with limited capabilities.
Use it for
- Add runtime type safety to Python functions during development and debugging without modifying core logic
- Validate API endpoint inputs and outputs in web frameworks to catch type errors before they propagate
- Enforce type contracts in dataclass-based data pipelines to catch schema violations early
- Gradually migrate untyped Python codebases by decorating functions incrementally with runtime checks
- Disable type checking in production (via `enabled=False`) while keeping it active in test environments
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you need runtime type validation for development or testing.
The package is lightweight, actively maintained, has no dependencies, and works with modern Python. Best suited for catching type errors during development or in non-performance-critical code paths; consider static type checkers like mypy for production-grade type safety without runtime overhead.
Install
type-enforced on PyPI
Before you install
Low friction installation with no runtime dependencies. Active maintenance with recent release (71 days ago) and steady repository activity.
Requires Python 3.11 or higher; earlier Python versions require older package versions with reduced feature support.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects.
Quickstart
pip install type_enforced
import type_enforced
@type_enforced.Enforcer(enabled=True, strict=True)
def my_fn(a: int, b: int | str = 2) -> None:
pass
my_fn(1, "test") # passes
my_fn("invalid", 2) # raises TypeError
Verify before relying
- Performance overhead compared to static type checkers or other runtime enforcers at scale
- Whether sampling via iterable_sample_pct is sufficient for production type safety guarantees
- Support for forward references and string annotations in all contexts
Package facts
| License | permissive license permissive |
| Python support | Supports the current Python release >=3.11 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 71 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 295,015 / month, #7,933 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3 |
Evidence: type_enforced-2.6.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “enforce type hints decorator”
- type-enforcedEnforces Python type annotations at runtime using decorators,…
- beartypeBeartype is a runtime type checker that validates Python type hints…
- spectreeGenerates OpenAPI documents and validates HTTP requests and responses…
Give your agent the search over MCP, or paste the wish link into any chat.
More Quality Assurance packages
Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.
Install it if you want to measure test completeness or enforce coverage thresholds in your project.
Ruff is a Python linter and code formatter written in Rust that combines linting, formatting, and code fixing into a single tool, replacing Flake8, Black, isort, and related utilities.
Pexpect spawns and controls interactive console applications by sending input and matching output patterns, automating tasks that would otherwise require manual interaction.
Black reformats Python source code to a consistent style by parsing entire files and rewriting them according to an opinionated, deterministic set of rules, eliminating manual formatting decisions.
pytest-xdist distributes pytest tests across multiple CPU cores or machines to speed up test execution, with the simplest usage being `pytest -n auto` to spawn workers equal to available CPUs.
Install it if your test suite takes long enough that parallelization would save meaningful time.
Validates AWS CloudFormation templates in YAML or JSON format against resource provider schemas and best practices, checking property values and configuration correctness.
Install it if you work with CloudFormation templates.
See also typing-utils · typing-inspect · typing-json · tach · annotated-types · typepy · mypy-extensions · beartype · eval-type-backport · typing-validation