or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration-system.mdindex.mdplugin-development.mdserver-management.mdutilities-helpers.mdworkspace-management.md
tile.json

tessl/pypi-python-lsp-server

Python Language Server Protocol implementation providing code intelligence features for Python development

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/python-lsp-server@1.13.x

To install, run

npx @tessl/cli install tessl/pypi-python-lsp-server@1.13.0

index.mddocs/

Python LSP Server

A comprehensive Python implementation of the Language Server Protocol that provides advanced code intelligence features for Python development. The server offers completion, definitions, hover information, references, signature help, symbols, linting, formatting, and extensive plugin architecture for extending functionality across multiple editors and IDEs.

Package Information

  • Package Name: python-lsp-server
  • Language: Python
  • Installation: pip install python-lsp-server
  • Entry Point: pylsp command-line interface

Core Imports

import pylsp
from pylsp import hookimpl, hookspec
from pylsp.python_lsp import PythonLSPServer

For plugin development:

from pylsp import hookimpl
from pylsp.config.config import Config
from pylsp.workspace import Workspace, Document

Basic Usage

Command Line Interface

# Start server with stdio
pylsp

# Start TCP server
pylsp --tcp --host 127.0.0.1 --port 2087

# Start WebSocket server
pylsp --ws --port 2087

# Enable verbose logging
pylsp -v

# Use custom log configuration
pylsp --log-config /path/to/log_config.json

Programmatic Server Usage

from pylsp.python_lsp import (
    PythonLSPServer,
    start_io_lang_server,
    start_tcp_lang_server,
    start_ws_lang_server
)
import sys

# Start stdio server
stdin, stdout = sys.stdin.buffer, sys.stdout.buffer
start_io_lang_server(stdin, stdout, False, PythonLSPServer)

# Start TCP server
start_tcp_lang_server("127.0.0.1", 2087, False, PythonLSPServer)

# Start WebSocket server
start_ws_lang_server(2087, False, PythonLSPServer)

Basic Plugin Development

from pylsp import hookimpl

@hookimpl
def pylsp_lint(config, workspace, document, is_saved):
    """Provide custom linting diagnostics."""
    return [{
        "range": {
            "start": {"line": 0, "character": 0},
            "end": {"line": 0, "character": 10}
        },
        "message": "Custom diagnostic message",
        "severity": 1  # Error
    }]

@hookimpl
def pylsp_completions(config, workspace, document, position, ignored_names):
    """Provide custom completions."""
    return [{
        "label": "custom_function",
        "kind": 3,  # Function
        "detail": "Custom completion",
        "documentation": "A custom completion item"
    }]

Architecture

The python-lsp-server is built on a modular plugin architecture using the Pluggy framework:

  • PythonLSPServer: Core LSP server implementation handling protocol communication
  • Workspace: Manages documents, configuration, and workspace-level operations
  • Document: Represents individual files with Jedi integration for Python intelligence
  • Plugin System: Pluggy-based hooks for extending functionality
  • Configuration: Hierarchical configuration system supporting workspace and plugin-specific settings
  • Built-in Plugins: Comprehensive set of plugins for linting, formatting, completion, and navigation

This architecture enables the server to provide consistent Python language intelligence while supporting extensive customization and third-party plugin development.

Capabilities

Server Management

Core server functionality including startup, configuration, and lifecycle management. Provides multiple server modes (stdio, TCP, WebSocket) and comprehensive CLI interface.

def start_io_lang_server(rfile, wfile, check_parent_process, handler_class): ...
def start_tcp_lang_server(bind_addr, port, check_parent_process, handler_class): ...
def start_ws_lang_server(port, check_parent_process, handler_class): ...

class PythonLSPServer:
    def __init__(self, rx, tx, check_parent_process=False, consumer=None, *, endpoint_cls=None): ...
    def start(self): ...
    def capabilities(self): ...

Server Management

Plugin Development

Comprehensive plugin system using Pluggy hooks for extending server functionality. Provides 40+ hook specifications covering all LSP features and server lifecycle events.

@hookimpl
def pylsp_lint(config, workspace, document, is_saved): ...
@hookimpl
def pylsp_completions(config, workspace, document, position, ignored_names): ...
@hookimpl
def pylsp_hover(config, workspace, document, position): ...
@hookimpl
def pylsp_definitions(config, workspace, document, position): ...

Plugin Development

Workspace Management

Document and workspace management with Jedi integration, configuration handling, and LSP workspace features including diagnostics publishing and progress reporting.

class Workspace:
    def get_document(self, doc_uri): ...
    def put_document(self, doc_uri, source, version=None): ...
    def update_document(self, doc_uri, change, version=None): ...
    def publish_diagnostics(self, doc_uri, diagnostics, doc_version=None): ...
    def apply_edit(self, edit): ...

class Document:
    def jedi_script(self, position=None, use_document_path=False): ...
    def word_at_position(self, position): ...
    def offset_at_position(self, position): ...

Workspace Management

Configuration System

Hierarchical configuration system supporting workspace-level, plugin-specific, and document-specific settings with integration to external configuration files.

class Config:
    def settings(self, document_path=None): ...
    def plugin_settings(self, plugin, document_path=None): ...
    def update(self, settings): ...
    def find_parents(self, path, names): ...

Configuration System

Utilities and Helpers

Comprehensive utility functions for LSP operations, text manipulation, URI handling, and Python-specific operations like path-to-module conversion.

def debounce(interval_s, keyed_by=None): ...
def find_parents(root, path, names): ...
def format_docstring(contents, markup_kind, signatures=None, signature_config=None): ...
def to_fs_path(uri): ...
def from_fs_path(path): ...

Utilities and Helpers