pygls (pronounced like 'pie glass') is a pythonic generic implementation of the Language Server Protocol, serving as a foundation for writing custom Language Servers. It enables the creation of language servers with minimal code, supporting STDIO, TCP/IP, and WebSocket communication. Currently at version 2.1.1, pygls maintains an active development and release cadence, with recent updates in March 2026.
pip install pyglsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a minimal pygls language server that provides 'world' and 'friend' as completion items when the user types 'hello.' in a document. The server communicates via standard I/O (STDIO).
Update all LSP type and method imports to `from lsprotocol import types` and use names like `types.TEXT_DOCUMENT_COMPLETION`.
Refactor custom LSP models to use `attrs` decorators and fields instead of Pydantic models.
Upgrade your Python environment to 3.9 or higher.
Review and update usage of LSP types, especially complex or nested ones, to align with the new standardized names from `lsprotocol` v2025.x.
Update command handler signatures to accept arguments as individual parameters (e.g., `def my_command(arg1, arg2):`) instead of a single `*args` or `params` list, and consider adding type annotations.
Add `logging.basicConfig(...)` to your server's startup code (e.g., `logging.basicConfig(level=logging.INFO, filename='pygls.log')`).
Upgrade `pygls` to a recent version (e.g., `pip install --upgrade pygls lsprotocol`) and update your imports. For LSP types, import directly from `lsprotocol.types` (e.g., `from lsprotocol import types`), and for server components, `from pygls.server import LanguageServer` or `from pygls.lsp.server import LanguageServer` depending on the `pygls` version.
Ensure you are importing `LanguageServer` from the correct path for `pygls` v2.x. The correct import is typically `from pygls.lsp.server import LanguageServer` (as per `pygls` v2.1.1 documentation). Also, ensure `pygls` is updated to a compatible version: `pip install --upgrade pygls`.
Carefully review the type annotations for your server command arguments to ensure they precisely match the expected LSP message structure. For complex types or custom classes, you might need to register custom converters with `cattrs` or simplify the argument types to basic LSP types or primitive Python types that `cattrs` can handle automatically. Ensure `lsprotocol` is also updated: `pip install --upgrade lsprotocol`.
Examine the client-side code sending the LSP messages to ensure that all required fields in the LSP objects (e.g., `Position`, `Range`, `TextDocumentIdentifier`) are correctly populated with the expected types and values, especially `line` and `character` as integers. Use detailed logging (`logging.basicConfig(level=logging.DEBUG)`) in your `pygls` server to inspect the incoming raw JSON messages for discrepancies. Upgrade `pygls` and `lsprotocol` to the latest versions to benefit from any parsing improvements: `pip install --upgrade pygls lsprotocol`.
Run 'pip install pygls' to install the library.