Skip to main content

Python

info

You can enable the extra with the :LazyExtras command. Plugins marked as optional will only be configured if they are installed.

Alternatively, you can add it to your lazy.nvim imports
lua/config/lazy.lua
require("lazy").setup({
spec = {
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
{ import = "lazyvim.plugins.extras.lang.python" },
{ import = "plugins" },
},
})

Options

Additional options for this extra can be configured in your lua/config/options.lua file:

lua/config/options.lua
-- LSP Server to use for Python.
-- Set to "basedpyright" to use basedpyright instead of pyright.
vim.g.lazyvim_python_lsp = "pyright"

Below you can find a list of included plugins and their default settings.

caution

You don't need to copy the default settings to your config. They are only shown here for reference.

nvim-treesitter

opts = function(_, opts)
if type(opts.ensure_installed) == "table" then
vim.list_extend(opts.ensure_installed, { "ninja", "python", "rst", "toml" })
end
end

nvim-lspconfig

opts = {
servers = {
pyright = {
enabled = lsp == "pyright",
},
basedpyright = {
enabled = lsp == "basedpyright",
},
[lsp] = {
enabled = true,
},
ruff = {
keys = {
{
"<leader>co",
function()
vim.lsp.buf.code_action({
apply = true,
context = {
only = { "source.organizeImports" },
diagnostics = {},
},
})
end,
desc = "Organize Imports",
},
},
},
},
setup = {
ruff = function()
LazyVim.lsp.on_attach(function(client, _)
if client.name == "ruff" then
-- Disable hover in favor of Pyright
client.server_capabilities.hoverProvider = false
end
end)
end,
},
}

neotest-python

opts = nil

nvim-dap-python

opts = {}

venv-selector.nvim

opts = function(_, opts)
if LazyVim.has("nvim-dap-python") then
opts.dap_enabled = true
end
return vim.tbl_deep_extend("force", opts, {
name = {
"venv",
".venv",
"env",
".env",
},
})
end

nvim-cmp

opts = function(_, opts)
opts.auto_brackets = opts.auto_brackets or {}
table.insert(opts.auto_brackets, "python")
end

neotest (optional)

opts = {
adapters = {
["neotest-python"] = {
-- Here you can specify the settings for the adapter, i.e.
-- runner = "pytest",
-- python = ".venv/bin/python",
},
},
}

nvim-dap (optional)

opts = nil