Skip to main content

Zero-dependency Python library for Language Server Protocol types

Project description

LSP Types

PyPI version Python Tests License: MIT

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

image

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.

It is a goal to maintain zero-dependency status for as long as possible.

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 Example

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

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

    assert diagnostics != []

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

    assert await pyright_session.update_code(code) == 2

    diagnostics = await pyright_session.get_diagnostics()
    assert diagnostics == []

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-schemas

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.

Project details


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.12.5.tar.gz (66.6 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.12.5-py3-none-any.whl (69.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for lsp_types-0.12.5.tar.gz
Algorithm Hash digest
SHA256 f0e54c8a1d13863d369223e25d1547024e7747c6aedbfe0d46e94233e2416717
MD5 6a2e107e1988b3f11406277442573d98
BLAKE2b-256 833f0b78f945d3e766c4484f670602874d7d765e7bf335ef92200d4df85baf9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for lsp_types-0.12.5.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.12.5-py3-none-any.whl.

File metadata

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

File hashes

Hashes for lsp_types-0.12.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ce3e71811e3cea118b67d7fbf2cd0b89fe6fcc3ac6bff4ad769b76c0a2fef6bb
MD5 7347423bc85c26d948c106581c735e0e
BLAKE2b-256 b0bda512b387d2dd15264422caab0c63a5e8bd2288803be2435e0e68590a2bcf

See more details on using hashes here.

Provenance

The following attestation bundles were made for lsp_types-0.12.5-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 Pingdom Monitoring Sentry Error logging StatusPage Status page