Using ty with the helix editor
The folks at Astral have released ty, which they define as:
An extremely fast Python type checker and language server, written in Rust.
You can read more in the blog post announcing it.
Today, I set it up with helix. To make it work, we first have to install it. Using uv, it’s as easy as typing:
uv tool install ty@latest
Then, edit your ~/.config/helix/languages.toml and add the following:
[language-server.ty]
command = "ty"
args = ["server"]
[[language]]
name = "python"
scope = "source.python"
injection-regex = "python"
file-types = ["py","pyi","py3","pyw",".pythonstartup",".pythonrc"]
shebangs = ["python"]
roots = [".", "pyproject.toml"]
comment-token = "#"
language-servers = ["ty"]
indent = { tab-width = 4, unit = " " }
auto-format = true
At this point, you can start using it, but there are a few handy things to know:
- By default,
tywill search for first-party modules in the project’s root directory or thesrcdirectory, if present. - If they are located elsewhere, you need to update your
pyproject.tomllike so:
[tool.ty.environment]
root = ["./app"]
- Third-party modules are searched for within a virtual environment, determined by:
- An environment variable called
VIRTUAL_ENV. - A
.venvdirectory in the project root or working directory. - The
--pythonor--venvflag when invoking it. - A configuration in
pyproject.toml:
- An environment variable called
[tool.ty.environment]
python = "./custom-venv-location/.venv"
That’s it. Now, when editing files with hx, you should get all of ty’s goodness!