--- id: type-enforced version: "2.6.0" license: unclear license_treatment: permissive maintenance: active --- # type-enforced — A pure python type enforcer for python type annotations License: permissive · Maintenance: active · Downloads: 295.0K/mo ## 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 above — verify before relying. Enforces Python type annotations at runtime using decorators, validating function inputs, outputs, and nested generic types without requiring a compiler or external dependencies. 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 pip install type-enforced uv add type-enforced poetry add type-enforced ## Installing type-enforced Before you install: Low friction installation with no runtime dependencies. Active maintenance with recent release (71 days ago) and steady repository activity. 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 Requires Python 3.11 or higher; earlier Python versions require older package versions with reduced feature support. 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: not declared (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 295.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags runtime type checking python, enforce type hints decorator, python type validation, runtime type enforcement, type annotation checker, python type guard, validate function signatures, type-checking, runtime-validation, decorator [View on SkillFed](https://skillfed.io/packages/type-enforced) · [View on PyPI](https://pypi.org/project/type-enforced/)