python-lsp-black

raw JSON →
2.0.0 verified Fri May 01 auth: no python

A Black plugin for the Python LSP Server (python-lsp-server). Formats Python code using Black on save or on demand. Current version 2.0.0 requires python-lsp-server and Black >= 23.11.0. Initial release cadence was ~yearly, now slower.

pip install python-lsp-black
error ModuleNotFoundError: No module named 'pylsp'
cause python-lsp-server not installed
fix
pip install python-lsp-server
error black failed to start: Entry point 'black' not found in config
cause Config still uses old entry point name 'pylsp_black' with python-lsp-black v2.0.0
fix
Update your config: replace 'pylsp_black' with 'black' or reinstall python-lsp-black to ensure entry points are registered.
breaking Entrypoint name changed from 'pylsp_black' to 'black' in v2.0.0. Existing configuration using 'pylsp.plugins.pylsp_black' must be updated to 'pylsp.plugins.black'.
fix In your LSP configuration, change 'pylsp.plugins.pylsp_black' to 'pylsp.plugins.black'.
gotcha This plugin automatically disables autopep8 and yapf formatters to avoid conflicts. If you need those, remove python-lsp-black or configure pylsp to re-enable them manually.
fix Set pylsp.plugins.autopep8.enabled = True and pylsp.plugins.yapf.enabled = True in your config after installing python-lsp-black (not recommended).
gotcha Python 3.7 support dropped in v2.0.0.
fix Use Python 3.8 or later, or pin to python-lsp-black <2.0.0 (last 1.3.0).

After installation, black formatting is available. No explicit import needed.

# Ensure python-lsp-server and python-lsp-black are installed
# Then, in your editor with LSP client configured for pylsp,
# Black formatting should work automatically.
# You can configure via pylsp settings, e.g.:
# pylsp.plugins.black.line_length = 88