{"id":4728,"library":"python-lsp-server","title":"Python LSP Server","description":"Python LSP Server (`pylsp`) provides a Language Server Protocol (LSP) implementation for Python. It offers features like autocompletion, linting, formatting, refactoring, and more, integrating with various editors and IDEs. It is currently at version 1.14.0 and maintains an active release cadence with frequent minor updates and occasional major versions introducing new features or breaking changes.","status":"active","version":"1.14.0","language":"en","source_language":"en","source_url":"https://github.com/python-lsp/python-lsp-server","tags":["lsp","language-server","python","developer-tools","ide","linting","formatting","refactoring"],"install":[{"cmd":"pip install python-lsp-server","lang":"bash","label":"Install core server"},{"cmd":"pip install 'python-lsp-server[all]'","lang":"bash","label":"Install with common plugins (flake8, pylint, black, etc.)"}],"dependencies":[{"reason":"Required for Rope-based refactoring features (e.g., rename) after `rope_rename` plugin was removed in v1.11.0.","package":"pylsp-rope","optional":true}],"imports":[{"note":"The `python-lsp-server` is typically run as a standalone process (e.g., by an editor). Direct Python imports are rare for end-user applications but `pylsp.cli.main` can be used to launch the server programmatically.","symbol":"main","correct":"from pylsp.cli import main"}],"quickstart":{"code":"import subprocess\nimport sys\nimport os\nimport time\nimport shutil\n\n# The Python LSP Server is primarily meant to be run as a separate process\n# and communicated with via stdin/stdout using the Language Server Protocol.\n# This example shows how to launch it programmatically for testing or custom integration.\n\nprint(\"Launching python-lsp-server in a subprocess...\")\n\ntry:\n    # Using `sys.executable -m pylsp` ensures the correct Python environment is used.\n    # We redirect stdout/stderr to pipes to prevent it from blocking the console.\n    # For real use, stdout would carry LSP messages to a client.\n    process = subprocess.Popen(\n        [sys.executable, '-m', 'pylsp', '--log-level', 'WARNING'], # Adjust log-level as needed\n        stdin=subprocess.PIPE, # Server expects LSP messages here\n        stdout=subprocess.PIPE, # Server sends LSP messages here\n        stderr=subprocess.PIPE, # Server logs errors/debug info here\n        text=True, # Handle stdin/stdout as text\n        bufsize=0 # Unbuffered I/O for real-time LSP communication\n    )\n\n    print(\"Server process started.\")\n    print(\"It is now listening for LSP messages on stdin and sending responses on stdout.\")\n    print(\"This process will block waiting for input unless a client sends messages.\")\n    print(\"Waiting for 2 seconds to simulate runtime...\")\n    time.sleep(2)\n\n    # In a real scenario, you would send JSON-RPC LSP messages here, e.g.,\n    # process.stdin.write('Content-Length: ...\\r\\n\\r\\n{\"jsonrpc\": \"2.0\", ...}\\r\\n')\n    # process.stdin.flush()\n\n    print(\"Attempting to terminate the server.\")\n    process.terminate() # Send SIGTERM (or equivalent on Windows)\n    stdout, stderr = process.communicate(timeout=5) # Wait for it to exit and get output\n\n    print(f\"\\nServer exit code: {process.returncode}\")\n    if stdout:\n        print(\"\\n--- Server STDOUT (LSP messages) ---\")\n        print(stdout.strip())\n    if stderr:\n        print(\"\\n--- Server STDERR (Logs/Errors) ---\")\n        print(stderr.strip())\n\nexcept FileNotFoundError:\n    print(f\"Error: `pylsp` command or `sys.executable` not found. Is python-lsp-server installed?\")\nexcept subprocess.TimeoutExpired:\n    print(\"Server did not terminate gracefully within the timeout. Killing it.\")\n    process.kill()\n    stdout, stderr = process.communicate()\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    print(\"Quickstart demonstration complete.\")","lang":"python","description":"The Python LSP Server is commonly launched by an editor/IDE as a subprocess. This quickstart demonstrates how to programmatically start the server, which then listens on stdin/stdout for Language Server Protocol messages. In a real application, an LSP client would handle sending and receiving these JSON-RPC messages."},"warnings":[{"fix":"Install `pylsp-rope`: `pip install pylsp-rope`","message":"The built-in `rope_rename` plugin was removed in v1.11.0. If you relied on Rope-based rename functionality, you must now install the `pylsp-rope` third-party plugin separately.","severity":"breaking","affected_versions":">=1.11.0"},{"fix":"Upgrade to Python >=3.9 or pin `python-lsp-server<1.13.0`.","message":"Support for Python 3.8 was officially dropped in version 1.13.0. Users on Python 3.8 must use an older version of `python-lsp-server`.","severity":"breaking","affected_versions":">=1.13.0"},{"fix":"Install desired optional dependencies, e.g., `pip install 'python-lsp-server[flake8,pylint,black]'` or `pip install 'python-lsp-server[all]'`.","message":"Many advanced features like linting (Flake8, Pylint), formatting (Black, Autopep8), and import sorting (isort) require their respective Python packages to be installed alongside `python-lsp-server` to function.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you are using `python-lsp-server` version 1.14.0 or newer if targeting Python 3.14.","message":"While v1.14.0 introduced fixes for Python 3.14 compatibility, older versions of `python-lsp-server` (pre-1.14.0) might exhibit issues or incomplete support when used with Python 3.14.","severity":"gotcha","affected_versions":"<1.14.0"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}