Naughty imps messing with your imports while you're renaming your files.
pyimp.nvim is a tiny Neovim helper plus Rust LSP sidecar for ty. It listens for workspace/willRenameFiles and rewrites Python imports before files or package directories are renamed.
It exists to provide file/package rename refactoring that ty does not currently implement itself. See astral-sh/ty#1560.
- Updates Python imports on file renames.
- Updates imports on package/directory renames.
- Supports absolute and relative imports.
- Handles
src/layouts and namespace packages. - Runs as a sidecar to an already-attached
tyclient.
{
"AlexanderFarkas/pyimp.nvim",
ft = "python",
build = "./scripts/install.sh",
config = function()
require("pyimp").setup()
end,
}The install script downloads a prebuilt pyimp-lsp release binary into bin/pyimp-lsp. If no matching release binary is available, it falls back to cargo build --release and copies the built binary into bin/.
For Snacks explorer rename persistence, use snacks-rename-fix.nvim.
If you want to provide your own binary:
{
"AlexanderFarkas/pyimp.nvim",
ft = "python",
config = function()
require("pyimp").setup({
cmd = { "/path/to/pyimp-lsp" },
})
end,
}- Neovim with LSP file-operation support.
tyconfigured as your Python LSP client.curlorwgetfor release downloads.- Rust toolchain only if a prebuilt binary is unavailable.
Push a version tag to build release binaries:
git tag v0.1.1
git push origin v0.1.1GitHub Actions publishes macOS and Linux tarballs named like:
pyimp-lsp-aarch64-apple-darwin.tar.gz
pyimp-lsp-x86_64-unknown-linux-gnu.tar.gz
pyimp-lsp-aarch64-unknown-linux-gnu.tar.gz
pyimp.nvim does not replace ty. It starts only after a ty client attaches and reuses ty's root/workspace folders.