Pyrefly
Pyrefly is a fast type checker and language server for Python, developed by Meta and written in Rust. It provides lightning-fast static type checking along with powerful IDE features such as code navigation, semantic highlighting, and code completion. Pyrefly aims to catch type-related errors before runtime, improve code quality, and enhance the developer experience. It is available as a command-line tool and an IDE extension, with new releases typically every Monday and more frequent updates for new features and bug fixes.
Warnings
- breaking The `pyrefly-pre-commit` hook underwent significant changes from version 0.0.1 to 0.42.0. Users migrating from older versions need to update their pre-commit configuration.
- gotcha When upgrading Pyrefly (or its dependencies), new type errors might appear due to improved analysis or stricter checks. Addressing all at once can be impractical.
- gotcha The `pyrefly init` command may report a 'No Python files matched patterns' error if run in an empty directory. This is expected behavior and will resolve once Python files are added to the project.
- gotcha Support for integrating with specific build systems (e.g., Buck2) is currently unstable and may break without prior notice. These issues are generally lower priority than core type-checking functionality.
Install
-
pip install pyrefly -
conda install -c conda-forge pyrefly
Quickstart
# 1. Create a new project directory and navigate into it
# mkdir my_project && cd my_project
# 2. Install Pyrefly (assuming pip is installed and virtual environment is active)
# pip install pyrefly
# 3. Initialize Pyrefly configuration (creates pyproject.toml or pyrefly.toml)
# pyrefly init
# 4. Create a sample Python file with a type error (e.g., 'main.py')
# echo 'def greet(name: str) -> str:\n return f"Hello, {name}"\n\nprint(greet(42))' > main.py
# 5. Run Pyrefly to check for type errors
# pyrefly check
# Expected output for 'print(greet(42))' should show a type error, e.g.:
# main.py:3:11: Type mismatch: Expected `str` but got `int`