# pyright: Python Static Type Checker by Microsoft


pyright is a static type checker and [language server](https://pydevtools.com/handbook/explanation/what-is-a-python-language-server.md) for Python, built and maintained by Microsoft. It reads type annotations, infers types for code that has none, and reports mismatches before the code runs.

pyright is written in TypeScript and runs on Node.js. The CLI and language server are MIT-licensed and ship on both PyPI and npm, so `uv add --dev pyright` works without a separate Node install.

pyright is the default type-analysis engine inside the [Pylance extension](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance) for Visual Studio Code. Pylance is closed-source. pyright's [open-source language server](https://github.com/microsoft/pyright/blob/main/docs/features.md#language-server-support) already provides completions, signature help, and rename refactoring; Pylance adds features such as semantic highlighting and inlay hints.

## Evaluate pyright for a project {#when-to-use-pyright}

pyright provides type feedback in the editor, including VS Code through Pylance. Its type inference catches bugs in unannotated code that [mypy](https://pydevtools.com/handbook/reference/mypy.md) skips by default.

Teams can keep mypy in CI and use Pylance in the editor; their diagnostics can differ. For the full trade-off table, see [How do Python type checkers compare?](https://pydevtools.com/handbook/explanation/how-do-mypy-pyright-and-ty-compare.md).

The handbook recommends [Pyrefly](https://pydevtools.com/handbook/reference/pyrefly.md) for new projects. Pylance can also use Pyrefly as its analysis backend through the Type Server Protocol. [ty](https://pydevtools.com/handbook/reference/ty.md) is another alternative; compare the required typing features and diagnostics on project code.

## Inspect the analysis features {#key-features}

- Type inference on unannotated code: pyright checks all code by default, including functions with no annotations, using inferred types. Four strictness levels (`off`, `basic`, `standard`, `strict`) control how aggressively it reports.
- Flow analysis: tracks variable types through control flow paths, narrowing types after `isinstance` checks, `is None` guards, and similar patterns.
- Parallel checking: `pyright --threads <count>` splits analysis across worker threads.
- Watch mode: `pyright --watch` rechecks files as they change, giving continuous feedback during development.
- Typing support: supports Python typing constructs such as generics, protocols, TypedDict, and control-flow narrowing.
- Type stub integration: works with typeshed and custom stub files, and `--verifytypes` reports how complete a `py.typed` package's public API is.

## Configure project checks {#configuration}

pyright reads configuration from `pyrightconfig.json` or `pyproject.toml` (under `[tool.pyright]`). If both exist, `pyrightconfig.json` takes precedence.

```toml {filename="pyproject.toml"}
[tool.pyright]
pythonVersion = "3.12"
typeCheckingMode = "standard"
reportMissingTypeStubs = false
```

The `typeCheckingMode` setting controls overall strictness:

| Mode | Behavior |
|---|---|
| `off` | Disables type-checking rules; syntax and semantic diagnostics remain |
| `basic` | Core type-checking rules |
| `standard` | CLI default. Enables additional rules beyond `basic` |
| `strict` | Reports missing parameter annotations and unknown types; return types can still be inferred |

Any other value is rejected with `Config "typeCheckingMode" entry must contain "off", "basic", "standard", or "strict".`, and pyright falls back to `standard`. The `all` and `recommended` modes documented in some comparisons belong to [basedpyright](https://pydevtools.com/handbook/reference/basedpyright.md), not pyright.

pyright also supports execution environments for per-directory settings, which is useful for monorepos where different packages need different configurations:

```json {filename="pyrightconfig.json"}
{
  "executionEnvironments": [
    { "root": "src/backend", "pythonVersion": "3.11" },
    { "root": "src/scripts", "pythonVersion": "3.12" }
  ]
}
```

## Install and run pyright {#installation-and-usage}

pyright ships on PyPI, so [uv](https://pydevtools.com/handbook/reference/uv.md) can install and run it with no Node.js setup. The PyPI package uses the `node` already on `PATH` and otherwise downloads its own build through `nodeenv` into `~/.cache/pyright-python` the first time it runs.

The quickest way to run pyright is with [uvx](https://pydevtools.com/handbook/reference/uvx.md):

```bash
uvx pyright src/
```

For project use, add pyright as a development dependency:

```bash
uv add --dev pyright
uv run pyright src/
```

`uv tool install pyright` installs it globally instead, along with the `pyright-langserver` entry point that editors need.

Diagnostics name the file, position, and rule that fired:

```console
$ uv run pyright src/
src/demo.py
  src/demo.py:5:5 - error: Argument of type "Literal['1']" cannot be assigned to parameter "a" of type "int" in function "add"
    "Literal['1']" is not assignable to "int" (reportArgumentType)
1 error, 0 warnings, 0 informations
```

Common command-line options:

```bash
# Check with a specific config file
pyright --project ./pyrightconfig.json

# Watch mode for continuous checking
pyright --watch

# Split checking across worker threads
pyright --threads 2 src/

# Output as JSON for CI integration
pyright --outputjson src/
```

## Connect an editor {#editor-integration}

VS Code: install the [Pylance extension](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance), which uses pyright by default and shares its completions, signature help, auto-imports, and rename refactoring. Pylance also supports [Pyrefly as a selectable backend](https://devblogs.microsoft.com/python/announcing-tsp/). Pylance is free but closed-source, and its license restricts it to official Microsoft VS Code builds.

[Cursor recommends Cursor Pyright](https://pydevtools.com/handbook/how-to/how-to-configure-cursor-for-a-uv-project.md), while [Positron](https://pydevtools.com/handbook/reference/positron.md) bundles Pyrefly. [Basedpyright](https://pydevtools.com/handbook/reference/basedpyright.md) provides an open-source alternative for VSCodium and other LSP editors.

Other editors: pyright's open-source language server works anywhere LSP does. Start it with `pyright-langserver --stdio`. Neovim users configure it through `nvim-lspconfig`; Emacs users through Eglot or lsp-mode.

## Assess the benefits {#pros}

- Checks unannotated code by default, catching bugs that [mypy](https://pydevtools.com/handbook/reference/mypy.md) skips
- VS Code integration through Pylance
- Granular configuration with per-directory execution environments for monorepos
- MIT-licensed and published to both PyPI and npm, so `uv add --dev pyright` needs no separate Node install

## Account for the limitations {#cons}

- Aggressive inference on unannotated code can produce false positives in highly dynamic code
- Needs a Node.js runtime, which the PyPI package downloads on first run and which offline or air-gapped CI has to provide up front
- No plugin API, so the django-stubs and SQLAlchemy plugin behavior mypy users rely on has no equivalent
- Pylance is closed-source and VS Code-only; its additional features, such as semantic highlighting and inlay hints, are not part of pyright's open-source server

## Control suppressions and CI failures {#suppressions-and-exit-codes}

Use `# pyright: ignore[reportAssignmentType]` for a targeted suppression. `# type: ignore` suppresses all diagnostics on the line, even when its brackets contain another checker's codes. Enable `reportUnnecessaryTypeIgnoreComment` to find obsolete ignores. See [pyright comment controls](https://microsoft.github.io/pyright/#/comments).

The CLI exits with `0` when no errors are reported and `1` for errors. Warnings alone exit with `0` unless `--warnings` is supplied. Fatal errors, unreadable configuration, and invalid arguments use other nonzero codes. See [pyright exit codes](https://microsoft.github.io/pyright/#/command-line?id=pyright-exit-codes).
