Introduction to mypyc
mastermypyc is a compiler that transforms Python modules into fast C extensions using standard Python type hints. It is designed to provide performance gains while maintaining a high degree of compatibility with standard Python.
Key Characteristics
- Performance: Existing type-annotated code typically runs 1.5x to 5x faster. Code specifically tuned for mypyc can achieve 5x to 10x speedups.
- Type System: Uses
mypyfor type checking and inference. It supports most features in thetypingmodule, including generics, union types, and optional types. - Compatibility: Compiled modules can import any standard Python module or third-party library. You can run compiled modules as normal interpreted Python modules during development.
- Runtime Safety: Unlike standard Python where type hints are ignored at runtime, mypyc enforces type annotations at runtime, raising
TypeErrorif values do not match. This provides protection against certain types of memory corruption and bugs.