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 (tomli-w 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

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

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

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: basedpyright 1.39.9, Pyrefly 1.1.1, ty 0.0.61, Zuban 0.9.0

Feature Pyright Pyrefly ty Zuban Notes
Diagnostics :white_check_mark: :white_check_mark: :warning: :white_check_mark: ty requires files on disk
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: :warning: :white_check_mark: ty requires files on disk
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: :warning: :white_check_mark: ty: requires files on disk
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()

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lsp_types-0.21.1.tar.gz (79.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lsp_types-0.21.1-py3-none-any.whl (87.5 kB view details)

Uploaded Python 3

File details

Details for the file lsp_types-0.21.1.tar.gz.

File metadata

  • Download URL: lsp_types-0.21.1.tar.gz
  • Upload date:
  • Size: 79.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for lsp_types-0.21.1.tar.gz
Algorithm Hash digest
SHA256 ed8d6644ea7e79f5f556ee7c04ad690a60e517e07200293512c635c82edd0878
MD5 a3d38bd8f2ebffbf5df54c53c20e2eaa
BLAKE2b-256 d0127067b1e8e813762d627468baa85098242b6761e97ae2c5c347c419125467

See more details on using hashes here.

Provenance

The following attestation bundles were made for lsp_types-0.21.1.tar.gz:

Publisher: publish.yml on Mazyod/lsp-python-types

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lsp_types-0.21.1-py3-none-any.whl.

File metadata

  • Download URL: lsp_types-0.21.1-py3-none-any.whl
  • Upload date:
  • Size: 87.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for lsp_types-0.21.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a93002dcfaeefff5a6d8119905b1d40caf7b23d26cb02bad942fbb844296278a
MD5 b1a2bed5eb0eee9ea84576ecf405ffff
BLAKE2b-256 74c8f004d01057ac30531b000f827037a2ea9ec7473cb3c9c5466c429ea8c8c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for lsp_types-0.21.1-py3-none-any.whl:

Publisher: publish.yml on Mazyod/lsp-python-types

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page