Pyre-check

0.9.25 · active · verified Thu Apr 16

Pyre-check is a performant static type checker for Python, developed by Meta (formerly Facebook). It is compliant with PEP 484 and designed to analyze large codebases incrementally, providing quick feedback. It operates with a client-server architecture and includes Pysa, a security-focused static analysis tool. The library is actively maintained with regular updates.

Common errors

Warnings

Install

Quickstart

This quickstart demonstrates setting up a basic Python project, installing `pyre-check` in a virtual environment, initializing its configuration, and running a simple type check to identify errors. The primary interaction with Pyre-check is through its command-line interface.

import os

project_name = "my_pyre_project"
os.system(f"mkdir {project_name} && cd {project_name}")

# Simulate project directory
os.chdir(project_name)

# Setup virtual environment and install pyre-check
os.system("python3 -m venv .venv")
os.system("source .venv/bin/activate") # In a real shell, this would activate the venv
os.system("pip install pyre-check")

# Initialize Pyre configuration
os.system("pyre init --no-watchman-comments --no-touch-pysa") # simplified for quickstart

# Create a Python file with a type error
with open("test_file.py", "w") as f:
    f.write("""
def greet(name: str) -> str:
    return f"Hello, {name}"

i: int = 'string' # This will cause a type error
print(greet(42)) # This will also cause a type error
""")

# Run Pyre to check for type errors
print("\n--- Running Pyre Check ---")
os.system("pyre")

# In a real environment, you'd deactivate with 'deactivate'
# os.system("deactivate")

view raw JSON →