pygls: The Generic Language Server Framework

2.1.1 · active · verified Sat Apr 11

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.

Warnings

Install

Imports

Quickstart

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).

from pygls.lsp.server import LanguageServer
from lsprotocol.types import (
    TEXT_DOCUMENT_COMPLETION, CompletionItem, CompletionList, CompletionParams
)

server = LanguageServer('example-server', 'v0.1')

@server.feature(TEXT_DOCUMENT_COMPLETION)
def completions(params: CompletionParams):
    """Returns completion items."""
    document = server.workspace.get_text_document(params.text_document.uri)
    current_line = document.lines[params.position.line].strip()

    items = []
    if current_line.endswith('hello.'):
        items = [
            CompletionItem(label='world'),
            CompletionItem(label='friend'),
        ]
    return CompletionList(is_incomplete=False, items=items)

if __name__ == '__main__':
    # Starts the language server using standard I/O (stdin/stdout)
    server.start_io()

view raw JSON →