Skip to content

Python

Python support is built in. Open a folder with Python files and you get completions, diagnostics, go to definition, formatting and debugging.

Feature Provided by
Language server basedpyright
Linting and formatting ruff
Debugging debugpy

Tyrn does not ship a Python interpreter. Install one first, for example with uv, Homebrew or python.org, and check that python3 --version works in your terminal.

Language servers

By default basedpyright and ruff run for Python files. pyright, pylsp and ty are also built in but off by default. To change the set, list servers by name in the Python language settings. A ! turns a server off and "..." keeps the remaining defaults.

settings.json
{
"languages": {
"Python": {
"language_servers": ["ty", "!basedpyright", "..."]
}
}
}

Basedpyright

basedpyright is the default type checker and language server.

You can configure it in two ways. Project settings such as typeCheckingMode go in pyrightconfig.json or in [tool.basedpyright] in pyproject.toml, so they apply in every editor. Editor-level options go in settings.json:

settings.json
{
"lsp": {
"basedpyright": {
"settings": {
"basedpyright": {
"analysis": {
"diagnosticMode": "workspace",
"inlayHints": { "callArgumentNames": false }
}
}
}
}
}
}
pyproject.toml
[tool.basedpyright]
typeCheckingMode = "strict"
ignore = ["**/__pycache__"]

Virtual environments

Tyrn finds virtual environments in your project, such as .venv, and uses the selected one for the language server and for running code. To pick another, run toolchain: select from the command palette. To add an environment by path, press cmd-k cmd-m.

The terminal activates a virtual environment in the working directory automatically. See Terminal.

Code formatting & linting

Formatting runs through ruff, and organizing imports runs as a code action on format. These are the defaults:

settings.json
{
"languages": {
"Python": {
"formatter": { "language_server": { "name": "ruff" } },
"code_actions_on_format": { "source.organizeImports.ruff": true }
}
}
}

Format with cmd-shift-i. To format on every save, set "format_on_save": "on" for Python.

To use another formatter, such as black:

settings.json
{
"languages": {
"Python": {
"formatter": {
"external": {
"command": "black",
"arguments": ["--stdin-filename", "{buffer_path}", "-"]
}
}
}
}
}

Ruff reads pyproject.toml or ruff.toml in your project for rules and style. To stop ruff from linting, add "!ruff" to language_servers.

Debugging

Press f4 to start the debugger. If no configuration fits, add one to .tyrn/debug.json:

.tyrn/debug.json
[
{
"label": "Python: current script",
"adapter": "Debugpy",
"request": "launch",
"program": "./main.py"
},
{
"label": "Python: Flask",
"adapter": "Debugpy",
"request": "launch",
"module": "app",
"env": { "FLASK_APP": "app", "FLASK_DEBUG": "1" }
}
]

See Debugger for more.