Mypyc Runtime Library
librt is the Mypyc runtime library, providing efficient C implementations of various Python standard library classes and functions. Mypyc leverages this library to produce faster C extensions when compiling Python code. It is primarily an internal dependency for `mypyc` and `mypy` (since version 1.19.0 for fixed-format cache serialization). The current version is 0.8.1, with development occurring in the main `mypy` repository and releases synced to the `librt` PyPI package.
Warnings
- breaking librt does not officially support PyPy. If your project targets PyPy and has `librt` as a dependency (e.g., through `mypy` for type checking), you may need to skip it in your CI matrix for PyPy environments.
- gotcha librt's Application Binary Interface (ABI) is not explicitly versioned, and changes to it can lead to compatibility issues with `mypyc`-compiled extensions. This can cause breakage if `librt` is updated independently of `mypyc` or the compiled application.
- gotcha librt is primarily an internal runtime component. Direct imports or reliance on its internal API in user-facing Python code are discouraged, as these interfaces are subject to change without standard deprecation warnings.
- deprecated Mypy 1.19.0 introduced `librt` as a dependency for its fixed-format cache serialization. Older versions of `mypy` (before 1.19.0) did not require `librt` for this purpose, relying instead on JSON-based caching.
Install
-
pip install librt
Imports
- librt
This library is primarily an internal runtime dependency for mypyc-compiled code and recent versions of mypy. Direct import of its internal symbols by end-user applications is generally not intended.
Quickstart
# librt is implicitly used by mypyc-compiled modules.
# A typical quickstart involves using mypyc, which then utilizes librt.
# First, ensure librt (and mypy, which includes mypyc) are installed.
# pip install mypy mypyc
# example_module.py
# This module will be compiled by mypyc, which relies on librt at runtime.
def factorial(n: int) -> int:
result = 1
for i in range(1, n + 1):
result *= i
return result
if __name__ == '__main__':
# In a real scenario, this would be compiled and imported as a C extension.
# For illustration, let's just run it as normal Python.
# To compile: mypyc example_module.py
# This creates a C extension (e.g., example_module.cpython-XYZ.so) that depends on librt.
print(f'Factorial of 5: {factorial(5)}')