Home Explore Blog CI



zed

1st chunk of `docs/src/languages/python.md`
81cee07de78d2a0c1a8f3822c7d130dc1fd3f3c5cb0a52500000000100000a8d
# Python

Python support is available natively in Zed.

- Tree-sitter: [tree-sitter-python](https://github.com/tree-sitter/tree-sitter-python)
- Language Servers:
  - [microsoft/pyright](https://github.com/microsoft/pyright)
  - [python-lsp/python-lsp-server](https://github.com/python-lsp/python-lsp-server) (PyLSP)

## Language Servers

Zed supports multiple Python language servers some of which may require configuration to work properly.

See: [Working with Language Servers](https://zed.dev/docs/configuring-languages#working-with-language-servers) for more information.

## Virtual Environments in the Terminal {#terminal-detect_venv}

Zed will detect Python virtual environments and automatically activate them in terminal if available.
See: [detect_venv documentation](../configuring-zed.md#terminal-detect_venv) for more.

## PyLSP

[python-lsp-server](https://github.com/python-lsp/python-lsp-server/), more commonly known as PyLSP, by default integrates with a number of external tools (autopep8, mccabe, pycodestyle, yapf) while others are optional and must be explicitly enabled and configured (flake8, pylint).

See [Python Language Server Configuration](https://github.com/python-lsp/python-lsp-server/blob/develop/CONFIGURATION.md) for more.

## PyRight

### PyRight Configuration

The [pyright](https://github.com/microsoft/pyright) language server offers flexible configuration options specified in a JSON-formatted text configuration. By default, the file is called `pyrightconfig.json` and is located within the root directory of your project. Pyright settings can also be specified in a `[tool.pyright]` section of a `pyproject.toml` file. A `pyrightconfig.json` file always takes precedence over `pyproject.toml` if both are present.

For more information, see the Pyright [configuration documentation](https://microsoft.github.io/pyright/#/configuration).

### PyRight Settings

The [pyright](https://github.com/microsoft/pyright) language server also accepts specific LSP-related settings, not necessarily connected to a project. These can be changed in the `lsp` section of your `settings.json`.

For example, in order to:

- use strict type-checking level
- diagnose all files in the workspace instead of the only open files default
- provide the path to a specific Python interpreter

```json
{
  "lsp": {
    "pyright": {
      "settings": {
        "python.analysis": {
          "diagnosticMode": "workspace",
          "typeCheckingMode": "strict"
        },
        "python": {
          "pythonPath": ".venv/bin/python"
        }
      }
    }
  }
}
```

For more information, see the Pyright [settings documentation](https://microsoft.github.io/pyright/#/settings).

Title: Python Support in Zed: Language Servers and Configuration
Summary
Zed provides native support for Python, utilizing tree-sitter-python and language servers like Pyright and PyLSP. Zed automatically detects and activates Python virtual environments in the terminal. PyLSP integrates with various external tools, while Pyright offers configuration via `pyrightconfig.json` or `pyproject.toml`, and also accepts LSP-related settings in Zed's `settings.json` for customizing type-checking, diagnostic scope, and Python interpreter path.