Skip to main content

LSP Types

PyPI version Python Tests License: MIT

Publish the excellent work of Sublime LSP as a PyPI package.

lsp-types-splash

LSP Types is a Python package that aims to provide a fully typed interface to Language Server Protocol (LSP) interactions. It can be used to simply utilize the types, or to interact with an LSP server over stdio.

The library has minimal dependencies (tomlkit for TOML config serialization).

Installation

pip install lsp-types

Usage

Using the LSP types:

import lsp_types

# Use the types

Using an LSP process through stdio:

[!TIP] Recommend using basedpyright for extended features.

from lsp_types.process import LSPProcess, ProcessLaunchInfo

process_info = ProcessLaunchInfo(cmd=[
    "pyright-langserver", "--stdio"
])

async with LSPProcess(process_info) as process:
    # Initialize the process
    ...

    # Grab a typed listener
    diagnostics_listener = process.notify.on_publish_diagnostics(timeout=1.0)

    # Send a notification (`await` is optional. It ensures messages have been drained)
    await process.notify.did_open_text_document(...)

    # Wait for diagnostics to come in
    diagnostics = await diagnostics_listener

LSPProcess.stop() is terminal — including the implicit stop() when the async with block exits. Calling start() on a stopped process raises RuntimeError instead of relaunching the server, and requests and notifications sent through it raise RuntimeError too (notifications are no longer dropped with a warning). The messages name the state they came from (LSP process has been stopped vs. LSP process has not been started). Construct a new LSPProcess when you need to restart a server.

LSPs

The following LSPs are available out of the box:

  • Pyright
  • Pyrefly
  • ty - Astral's fast Python type checker
  • Zuban - Rust-based type checker + LSP by the author of Jedi

Pyrefly CLI tools

This library drives Pyrefly's LSP server (pyrefly lsp), but Pyrefly also ships a broader standalone CLI worth knowing about (verified with Pyrefly 1.2.0):

Command What it does
pyrefly init Scaffold a pyrefly.toml (or [tool.pyrefly] in pyproject.toml), or migrate an existing mypy/pyright config to Pyrefly
pyrefly check Full type check of a file or project
pyrefly snippet <CODE> Type-check an inline code snippet
pyrefly infer Automatically add inferred type annotations to a file or directory
pyrefly coverage Type-coverage reporting commands
pyrefly suppress Add ignore comments for existing errors, or remove unused ignores
pyrefly stubgen Generate .pyi stub files from Python source
pyrefly dump-config Print Pyrefly's resolved configuration
pyrefly tsp Start a TSP (Type Server Protocol) server (new in 1.2.x)

Run pyrefly <command> --help for details, or see the Pyrefly docs.

Feature Support Matrix

Legend

Symbol Meaning
:white_check_mark: Fully supported
:warning: Partial support (see notes)
:x: Not supported
:grey_question: Not tested / Not exposed in API

Features by Backend

Last verified: Pyrefly 1.2.0, ty 0.0.75, Zuban 0.9.2 (basedpyright: CI only, unpinned npm install -g basedpyright)

Feature Pyright Pyrefly ty Zuban Notes
Diagnostics :white_check_mark: :white_check_mark: :white_check_mark: :white_check_mark:
Hover :white_check_mark: :white_check_mark: :white_check_mark: :white_check_mark: ty shows type only, not variable name
Completion :white_check_mark: :white_check_mark: :white_check_mark: :white_check_mark:
Completion Resolution :white_check_mark: :x: :x: :white_check_mark: Pyrefly: no-op (returns item unchanged); ty: not supported (-32601)
Signature Help :white_check_mark: :white_check_mark: :white_check_mark: :white_check_mark:
Rename :white_check_mark: :white_check_mark: :white_check_mark: :white_check_mark:
Semantic Tokens :white_check_mark:* :white_check_mark:** :white_check_mark: :white_check_mark: *basedpyright recommended; **Pyrefly: legend not advertised (see docs)
Go to Definition :grey_question: :grey_question: :grey_question: :grey_question: Not exposed in Session API
Find References :grey_question: :grey_question: :grey_question: :grey_question: Not exposed in Session API
Code Actions :grey_question: :grey_question: :grey_question: :grey_question: Not exposed in Session API
Formatting :grey_question: :grey_question: :grey_question: :grey_question: Not exposed in Session API

See Feature Verification Guide for methodology on maintaining this table.

For detailed documentation:

Pyright Example

from lsp_types import Session
from lsp_types.pyright.backend import PyrightBackend

async def test_pyright_session():
    code = """\
def greet(name: str) -> str:
    return 123
"""

    session = await Session.create(PyrightBackend(), initial_code=code)
    diagnostics = await session.get_diagnostics()

    assert diagnostics != []

    code = """\
def greet(name: str) -> str:
    return f"Hello, {name}"
"""

    await session.update_code(code)
    diagnostics = await session.get_diagnostics()
    assert diagnostics == []

    await session.shutdown()

After shutdown(), a session's operational methods raise RuntimeError; its captured server and semantic-token metadata remain readable. Calling shutdown() while other operations are in flight is safe: it waits up to five seconds for them to finish, and if any are still running it stops the language server process instead of returning it to the pool, keeping stale operations out of the next session's protocol stream. (One narrow exception: cancelling an operation ends its in-flight accounting even if a notification write it already queued is still being flushed.)

Development

  • Requires Python 3.12+.
  • Requires uv for dev dependencies.

Generate latest types in one go:

make generate-latest-types

Download the latest json schema:

make download-schemas

Generate the types:

make generate-types

Copy the lsp_types/types.py file to your project.

NOTE: Do not import types that begin with __. These types are internal types and are not meant to be used.

TODOs

  • Support server request handlers.

Metadata

Release files for lsp-types 0.23.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lsp-types 0.23.0
File Size Uploaded
lsp_types-0.23.0.tar.gz 92.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lsp-types 0.23.0
File Interpreter ABI Platform
lsp_types-0.23.0-py3-none-any.whl Python 3 none any Details

Total release size: 194.1 kB

Release files / lsp_types-0.23.0.tar.gz

Download URL lsp_types-0.23.0.tar.gz
Size 92.9 kB
Tags Source
SHA-256 checksum
How to use checksums
46d97a6be3605cc2dad96d431df85e2ba220c87ec7a358c200e3e406a8873b8a
BLAKE2b-256 checksum
How to use checksums
1aeaf45aeec208941757e5d59e984519349d558d2f4ddfce22737bb8e4899c0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 31, 2026.

Transparency log

Release files / lsp_types-0.23.0-py3-none-any.whl

Download URL lsp_types-0.23.0-py3-none-any.whl
Size 101.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f3dd079e1a741ef61f057d02703727879b0306ce6cdeb2adf95396074e013ad
BLAKE2b-256 checksum
How to use checksums
9b37b8f3fa9bcf6741d67dacae3232930a3dd42dd0bb8a9a17e4ceafda3fabb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 31, 2026.

Transparency log

Release history Release notifications | RSS feed

0.24.1

2 release files

0.24.0

2 release files

This release

0.23.0 This release

2 release files

0.22.1

2 release files

0.21.1

2 release files

0.21.0

2 release files

0.20.0

2 release files

0.19.0

2 release files

0.18.2

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.2

2 release files

0.14.1

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.5

2 release files

0.12.4

2 release files

0.12.3

2 release files

0.12.2

2 release files

0.12.1

2 release files

0.12.0

2 release files

0.9.0

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page