{"id":935,"library":"pyright","title":"Pyright for Python","description":"Pyright for Python is a command-line wrapper that simplifies the installation and execution of Microsoft's Pyright static type checker within a Python environment. Pyright itself is a fast, standards-compliant type checker written in TypeScript and executed via Node.js. This wrapper handles the complexities of downloading and managing Node.js and the Pyright npm package, allowing Python developers to use Pyright without needing a separate Node.js installation. The project is actively maintained with frequent releases, typically aligned with upstream Pyright updates.","status":"active","version":"1.1.408","language":"python","source_language":"en","source_url":"https://github.com/RobertCraigie/pyright-python","tags":["type checking","static analysis","linter","developer tool"],"install":[{"cmd":"pip install pyright","lang":"bash","label":"Standard installation"},{"cmd":"pip install pyright[nodejs]","lang":"bash","label":"Recommended: Includes Node.js binaries for reliability"}],"dependencies":[{"reason":"Pyright (the core type checker) is written in TypeScript and runs on Node.js. The Python wrapper automatically manages its download and execution.","package":"Node.js","optional":false},{"reason":"Used by the wrapper to install the Pyright npm package.","package":"npm","optional":false}],"imports":[],"quickstart":{"code":"import os\n\n# Create a dummy Python file to check\nwith open(\"my_module.py\", \"w\") as f:\n    f.write(\"def greet(name: str) -> int:\\n    return f'Hello, {name}'\\n\\nresult = greet('World')\\n\")\n\n# Run pyright via the command line (typical usage)\n# This is equivalent to `pyright my_module.py` in the terminal\nimport subprocess\n\ntry:\n    # Using python -m pyright to ensure the installed package's executable is found\n    process = subprocess.run(\n        ['python', '-m', 'pyright', 'my_module.py'],\n        capture_output=True,\n        text=True,\n        check=False  # Do not raise an exception for non-zero exit codes\n    )\n    print(\"Pyright Output:\\n\" + process.stdout)\n    if process.stderr:\n        print(\"Pyright Errors:\\n\" + process.stderr)\n    if process.returncode != 0:\n        print(f\"Pyright exited with code {process.returncode}. Errors found.\")\n    else:\n        print(\"Pyright completed with no errors.\")\nexcept FileNotFoundError:\n    print(\"Error: 'pyright' command not found. Ensure pyright is installed and in PATH.\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n\n# Clean up the dummy file\nos.remove(\"my_module.py\")","lang":"python","description":"This quickstart demonstrates how to run Pyright on a simple Python file. The `pyright` Python package primarily provides a command-line executable. Programmatic invocation within Python is typically done by calling the `pyright` command via `subprocess`."},"warnings":[{"fix":"Use `pip install pyright[nodejs]` for installation. Ensure network access for Node.js download if not already present in PATH.","message":"The `pyright-python` wrapper handles Node.js installation via `nodeenv` by default. This can be less reliable than a direct Node.js installation, especially in restricted CI/CD environments or without `bash` availability. For more robust Node.js handling, install with the `nodejs` extra (`pip install pyright[nodejs]`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Configure Pyright to explicitly use your project's virtual environment. Add a `[tool.pyright]` section to your `pyproject.toml` or create a `pyrightconfig.json` with `venvPath = \".\"` and `venv = \".venv\"` (adjust `.venv` to your actual virtual environment directory name). Alternatively, configure pre-commit to install your dependencies into its hook environment.","message":"When using `pyright-python` with `pre-commit`, it often runs in an isolated virtual environment, which can prevent Pyright from detecting your project's installed dependencies. This leads to 'unknown import' errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always explicitly include common exclusion paths (e.g., `node_modules`, `__pycache__`, your virtual environment directory) when providing a custom `exclude` list in your Pyright configuration.","message":"Manually defining an `exclude` option in `pyrightconfig.json` or `pyproject.toml` *replaces* Pyright's default excluded paths (like `node_modules`, `__pycache__`, virtual environments). Failing to re-include these common exclusions can cause massive slowdowns or hangs as Pyright attempts to analyze irrelevant files.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult Pyright's documentation for its native support for advanced type features. For libraries with known MyPy plugins, verify Pyright's compatibility or consider workarounds like `type: ignore` comments if needed. This may be a reason to use MyPy if deeply integrated with such libraries.","message":"Pyright does not support a plugin system, unlike some other type checkers (e.g., MyPy). This means it may not fully understand or correctly type-check code that relies on MyPy-specific plugins (e.g., for complex ORMs like Django or some Pydantic features), potentially leading to false positives or missed errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'activ':77 'align':83 'allow':62 'analysi':91 'check':89 'checker':25,39 'command':10 'command-lin':9 'complex':51 'compliant':37 'develop':64,93 'download':53 'environ':29 'execut':18,44 'fast':34 'frequent':80 'handl':49 'instal':16,73 'line':11 'linter':92 'maintain':78 'manag':55 'microsoft':20 'need':69 'node.js':46,56,72 'npm':60 'packag':61 'project':75 'pyright':1,4,22,30,59,67,86 'python':3,6,28,63 'releas':81 'separ':71 'simplifi':14 'standard':36 'standards-compli':35 'static':23,90 'tool':94 'type':24,38,88 'typescript':42 'typic':82 'updat':87 'upstream':85 'use':66 'via':45 'within':26 'without':68 'wrapper':12,48 'written':40","created_at":"2026-03-29T06:08:29.159996+00:00","updated_at":"2026-04-16T19:46:14.900079+00:00","problems":[{"fix":"Ensure `pyright` is installed via `pip install pyright` and that your virtual environment is activated. On Windows, ensure the `Scripts` directory of your Python environment is in the PATH.","cause":"The `pyright` executable is not found in the system's PATH, typically because the Python package was not installed or the virtual environment where it's installed is not active.","error":"pyright: command not found"},{"fix":"Check your internet connection and proxy settings. Ensure the user has write permissions in the installation directory. You might try `pip install --no-cache-dir pyright` to force a fresh download.","cause":"The `pyright` Python wrapper encountered an issue downloading Node.js or installing the underlying Pyright npm package, often due to network connectivity problems, firewall restrictions, or insufficient permissions.","error":"Failed to install Pyright"},{"fix":"Try clearing the `pyright` cache (usually in `~/.pyright` or `AppData/Local/pyright` on Windows) and reinstalling `pyright` via `pip install --force-reinstall pyright`. Ensure sufficient disk space and permissions.","cause":"The `pyright` wrapper successfully downloaded a Node.js archive but failed to extract it properly, or the extracted executable is missing or not accessible, preventing `pyright` from running.","error":"[Errno 2] No such file or directory: '/path/to/.pyright/node/node'"},{"fix":"Ensure the module is installed (`pip install some_module`) in the environment Pyright is checking. If using a virtual environment, verify `venvPath` and `venv` in your `pyrightconfig.json` or add the module's path to `extraPaths`.","cause":"Pyright cannot find the specified module because it's either not installed in the Python environment being analyzed or the `pyrightconfig.json` (or `pyproject.toml`) is not correctly configured to include the necessary paths or virtual environment.","error":"ReportMissingImports: Import \"some_module\" could not be resolved"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"pyright","cli_version":"* Install prebuilt node (26.1.0) ..... done.","type":"library","homepage":null,"github":"https://github.com/RobertCraigie/pyright-python","docs":null,"changelog":null,"pypi":"https://pypi.org/project/pyright/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["type-stubs","testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-03-29","next_check":"2026-06-27","install_tag":null}}