Full-featured, well-typed, and easy-to-use LSP client
Project description
LSP Client
A production-ready, async-first Python client for the Language Server Protocol (LSP). Built for developers who need fine-grained control, container isolation, and extensibility when integrating language intelligence into their tools.
Why lsp-client?
lsp-client is engineered for developers building production-grade tooling that requires precise control over language server environments:
- 🧩 Intelligent Capability Management: Zero-overhead mixin system with automatic registration, negotiation, and availability checks. Only access methods for registered capabilities.
- 🎨 Ergonomic API Design: Every capability method is designed for developer productivity. The SDK handles complex LSP response types (like
LocationvsLocationLink), providing consistent, high-level Python objects instead of raw JSON-RPC structures. - 🎯 Universal LSP Support: Full 3.17 specification coverage. Supports all standard client requests, notifications, and server-to-client interactions. If a capability exists in the LSP spec, you can use or implement it here.
- 🐳 Container-First Architecture: Containers as first-class citizens with workspace mounting, path translation, and lifecycle management. Pre-built images available, seamless switching between local and container environments.
- 🛡️ Fail-Safe Capability Validation: Sophisticated pre-flight checks ensure that the server's capabilities perfectly match the client's requirements before the first request is ever sent. Catch configuration mismatches at startup rather than during runtime.
- ⚡ Production-Ready & Modern: Explicit environment control with no auto-downloads. Built with async patterns, comprehensive error handling, retries, and full type safety.
Quick Start
Installation
uv add lsp-client
Local Language Server
The following code snippet can be run as-is, try it out:
# NOTE: install pyrefly with `uv tool install pyrefly` first
import anyio
from lsp_client import Position, PyreflyClient
async def main():
async with PyreflyClient() as client:
refs = await client.request_references(
file_path="example.py",
position=Position(10, 5)
)
for ref in refs:
print(f"Reference at {ref.uri}: {ref.range}")
anyio.run(main)
Containerized Language Server
import anyio
from pathlib import Path
from lsp_client import Position, PyrightClient
from lsp_client.clients.pyright import PyrightContainerServer
async def main():
workspace = Path.cwd()
async with PyrightClient(
server=PyrightContainerServer(),
workspace=workspace
) as client:
# Find definition of a symbol
definitions = await client.request_definition_locations(
file_path="example.py",
position=Position(10, 5)
)
if definitions:
for def_loc in definitions:
print(f"Definition at {def_loc.uri}: {def_loc.range}")
anyio.run(main)
More Examples
The examples/ directory contains comprehensive usage examples:
pyright_container.py- Using Pyright in Docker for Python analysisrust_analyzer.py- Rust code intelligence with Rust-Analyzerpyrefly.py- Python linting and analysis with Pyreflyprotocol.py- Direct LSP protocol usage
Run examples with:
uv run examples/pyright_container.py
Client Definition
Defining a custom client is super easy with the capability mixin:
@define
class MyPythonClient(
Client,
WithRequestHover, # textDocument/hover
WithRequestDefinition, # textDocument/definition
WithRequestReferences, # textDocument/references
WithNotifyDidChangeConfiguration, # workspace/didChangeConfiguration
# ... and other capabilities as needed
):
def create_default_servers(self) -> DefaultServers:
return DefaultServers(
# support both local ...
local=LocalServer(program="pylsp", args=["--stdio"]),
# ... and containerized server!
container=ContainerServer(image="ghcr.io/observerw/lsp-client/python-lsp-server")
)
def create_initialization_options(self) -> dict:
return {"plugins": {"pyflakes": {"enabled": True}}} # custom init options
def check_server_compatibility(self, info: lsp_type.ServerInfo | None) -> None:
return # Custom compatibility checks if needed
Current Supported Language Servers
| Language Server | Module Path | Language | Container Image |
|---|---|---|---|
| Pyright | lsp_client.clients.pyright |
Python | ghcr.io/lsp-client/pyright:latest |
| Basedpyright | lsp_client.clients.basedpyright |
Python | ghcr.io/lsp-client/basedpyright:latest |
| Pyrefly | lsp_client.clients.pyrefly |
Python | ghcr.io/lsp-client/pyrefly:latest |
| Ty | lsp_client.clients.ty |
Python | ghcr.io/lsp-client/ty:latest |
| Rust Analyzer | lsp_client.clients.rust_analyzer |
Rust | ghcr.io/lsp-client/rust-analyzer:latest |
| Deno | lsp_client.clients.deno |
TypeScript/JavaScript | ghcr.io/lsp-client/deno:latest |
| TypeScript Language Server | lsp_client.clients.typescript |
TypeScript/JavaScript | ghcr.io/lsp-client/typescript:latest |
| Gopls | lsp_client.clients.gopls |
Go | ghcr.io/lsp-client/gopls:latest |
Container images are automatically updated weekly to ensure access to the latest language server versions.
Key Benefits
- Method Safety: You can only call methods for capabilities you've registered. No runtime surprises from unavailable capabilities.
- Automatic Registration: The mixin system automatically handles client registration, capability negotiation, and availability checks behind the scenes.
- Zero Boilerplate: No manual capability checking, no complex initialization logic, no error handling for missing capabilities.
- Type Safety: Full type annotations ensure you get compile-time guarantees about available methods.
- Composability: Mix and match exactly the capabilities you need, creating perfectly tailored clients.
Advanced Features
Resilient Server Selection
lsp-client implements a prioritized server loading strategy to ensure your tool works across different environments without manual configuration:
- Explicit Server: If you provide a specific
Serverinstance, it will be used first. - Local Environment: It checks if the required language server is already installed in the local system path.
- Container Fallback: If no local server is found, it automatically falls back to a containerized version (using Docker), ensuring zero-setup for end users.
- Auto-Install: As a last resort, it can attempt to automatically install the server locally if an installation hook is defined.
Fine-Grained Capability Control
The mixin-based architecture allows you to define exactly what your client supports. This is not just for organization; it directly affects the Initialize request sent to the server, ensuring the server only sends relevant notifications and doesn't waste resources on unused features.
Transparent Path Translation
When using containerized servers, lsp-client automatically handles path translation between your host machine and the container. You work with local paths, and the client ensures the server sees the correct container-relative paths.
Smart Configuration Management
lsp-client features a sophisticated configuration system designed for production use:
- Sensible Defaults: Every built-in client comes pre-configured with optimized settings. Features like inlay hints, auto-imports, and advanced diagnostics are enabled out-of-the-box.
- Hierarchical Overrides: Use
ConfigurationMapto manage global settings and path-based overrides (e.g., different linting rules fortests/vssrc/). - Deep Merging: Settings are merged recursively, allowing you to override specific sub-keys without losing the rest of the default configuration.
- Automatic Sync: The SDK automatically handles
workspace/didChangeConfigurationnotifications, ensuring the language server always has the latest settings without a restart.
Highly Customizable Architecture
The library is built with extensibility as a core principle. You are never locked into the default behavior:
- Capability Overriding: You can easily customize how the client handles specific LSP requests or notifications by overriding the capability methods. Want to filter diagnostics or transform hover content before it reaches your application? Just override the corresponding method in your custom client.
- Middleware Support: Intercept and modify outgoing requests or incoming responses to implement custom logic like caching, logging, or request debouncing.
- Custom Servers: Beyond the built-in local and container servers, you can implement your own
Serverclass to connect to language servers over custom transports (e.g., WebSockets, named pipes, or remote SSH).
Contributing
We welcome contributions! Please see our Contributing Guide for details on:
- Adding new language server support
- Extending protocol capabilities
- Container image updates
- Development workflow
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built on the Language Server Protocol specification
- Uses lsprotocol for LSP type definitions
- Architecture inspired by multilspy and other LSP clients
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lsp_client-0.3.2.tar.gz.
File metadata
- Download URL: lsp_client-0.3.2.tar.gz
- Upload date:
- Size: 58.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0ed12ff570035c77e708df6bf3f7b0673292f9b08b4a07e6ca69878e5b9f2b4
|
|
| MD5 |
9607ad2305799c37330a2a4b81e61962
|
|
| BLAKE2b-256 |
b89a3be8e1e35da7e1d260ff905176892e0c7c56a936aceea2e44e4296cb9d33
|
Provenance
The following attestation bundles were made for lsp_client-0.3.2.tar.gz:
Publisher:
release.yml on lsp-client/lsp-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lsp_client-0.3.2.tar.gz -
Subject digest:
a0ed12ff570035c77e708df6bf3f7b0673292f9b08b4a07e6ca69878e5b9f2b4 - Sigstore transparency entry: 826934593
- Sigstore integration time:
-
Permalink:
lsp-client/lsp-client@a24b6ef350a1627c39a7af28fc36861216b195d1 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/lsp-client
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a24b6ef350a1627c39a7af28fc36861216b195d1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lsp_client-0.3.2-py3-none-any.whl.
File metadata
- Download URL: lsp_client-0.3.2-py3-none-any.whl
- Upload date:
- Size: 115.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22c6c05e06fc64274785e5bbcd6334ff82e0cb892d98cdbd2e1b5cf8824cc6e7
|
|
| MD5 |
1223efba002066048b7f692f494bfdfe
|
|
| BLAKE2b-256 |
374314b44ac6ae9de890cb9269fed4e469da57f3d3abe723485b3cbf8605e065
|
Provenance
The following attestation bundles were made for lsp_client-0.3.2-py3-none-any.whl:
Publisher:
release.yml on lsp-client/lsp-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lsp_client-0.3.2-py3-none-any.whl -
Subject digest:
22c6c05e06fc64274785e5bbcd6334ff82e0cb892d98cdbd2e1b5cf8824cc6e7 - Sigstore transparency entry: 826934672
- Sigstore integration time:
-
Permalink:
lsp-client/lsp-client@a24b6ef350a1627c39a7af28fc36861216b195d1 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/lsp-client
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a24b6ef350a1627c39a7af28fc36861216b195d1 -
Trigger Event:
push
-
Statement type: