Convert Figma logo to code with AI

palantir logopython-language-server

An implementation of the Language Server Protocol for Python

2,607
283
2,607
186

Top Related Projects

13,105

Static Type Checker for Python

5,757

Awesome autocompletion, static analysis and refactoring library for python

Fork of the python-language-server project, maintained by the Spyder IDE team and the community

Language Server Protocol (LSP) support for vim and neovim.

Quick Overview

The palantir/python-language-server is an implementation of the Language Server Protocol for Python. It provides language intelligence features such as auto-completion, go-to-definition, and real-time error checking for Python code. This server can be integrated with various code editors and IDEs to enhance the Python development experience.

Pros

  • Implements the Language Server Protocol, making it compatible with multiple editors and IDEs
  • Provides advanced language features like auto-completion, code navigation, and error detection
  • Supports both Python 2 and Python 3
  • Actively maintained and regularly updated

Cons

  • May have performance issues with very large codebases
  • Some features might not work as well as in dedicated Python IDEs
  • Configuration can be complex for some setups
  • Occasional stability issues reported by some users

Getting Started

To use the Python Language Server, you need to install it and configure your editor to use it. Here's a basic setup using pip:

pip install python-language-server[all]

For VS Code users, install the "Python" extension, which includes support for the Python Language Server.

For Vim/Neovim users with coc.nvim:

  1. Install coc.nvim
  2. Run :CocInstall coc-pyright in Vim/Neovim

For other editors, refer to their specific documentation on how to set up a language server.

Note: The exact setup may vary depending on your editor and specific requirements. Always check the most recent documentation for up-to-date instructions.

Competitor Comparisons

13,105

Static Type Checker for Python

Pros of Pyright

  • Faster performance, especially for large codebases
  • More accurate type checking and inference
  • Better support for modern Python features and type annotations

Cons of Pyright

  • Steeper learning curve for configuration and customization
  • Less extensive plugin ecosystem compared to Python Language Server
  • May require more manual type annotations for optimal results

Code Comparison

Python Language Server:

from jedi import Script

script = Script(source, path)
completions = script.complete(line, column)

Pyright:

from pyright import LanguageServerProtocol

lsp = LanguageServerProtocol()
completions = lsp.completion(document_uri, position)

Both projects aim to provide language server functionality for Python, but they differ in their approach and focus. Python Language Server relies heavily on the Jedi library for code analysis, while Pyright is built from the ground up with a focus on static type checking.

Pyright offers superior performance and type inference capabilities, making it particularly well-suited for large-scale Python projects. However, Python Language Server may be easier to set up and integrate with existing tools due to its longer history and wider adoption.

Ultimately, the choice between these two language servers depends on the specific needs of your project, with Pyright being the better option for those prioritizing type checking and performance, while Python Language Server might be preferable for simpler setups or projects with existing integrations.

5,757

Awesome autocompletion, static analysis and refactoring library for python

Pros of Jedi

  • Lightweight and fast, with minimal dependencies
  • Excellent autocompletion and static analysis capabilities
  • Can be used as a standalone library or integrated into various editors

Cons of Jedi

  • Limited language server protocol (LSP) support
  • Less comprehensive feature set compared to Python Language Server

Code Comparison

Jedi:

import jedi

script = jedi.Script("import os\nos.")
completions = script.complete(1, 3)

Python Language Server:

from pyls import language_server

server = language_server.LanguageServer()
server.start_io()

Jedi focuses on providing a simple API for code intelligence, while Python Language Server offers a more comprehensive LSP implementation. Jedi is ideal for lightweight integrations and quick autocompletion tasks, whereas Python Language Server is better suited for full-featured IDE-like experiences.

Both projects have their strengths, and the choice between them depends on the specific requirements of the development environment and the desired level of integration with other tools and editors.

Fork of the python-language-server project, maintained by the Spyder IDE team and the community

Pros of python-lsp-server

  • More active development and maintenance
  • Better support for modern Python features
  • Improved plugin ecosystem and extensibility

Cons of python-lsp-server

  • Potentially higher resource usage due to additional features
  • May have a steeper learning curve for configuration

Code Comparison

python-language-server:

from pyls import hookimpl

@hookimpl
def pyls_completions(document, position):
    # Completion logic here

python-lsp-server:

from pylsp import hookimpl

@hookimpl
def pylsp_completions(config, workspace, document, position):
    # Enhanced completion logic here

The code comparison shows that python-lsp-server provides more context parameters in its hookimpl, allowing for more sophisticated completion implementations.

python-lsp-server is a fork of python-language-server, aiming to continue its development and improve upon its foundation. It offers better compatibility with recent Python versions and a more robust plugin system. However, it may require more resources and have a slightly more complex setup process. Both projects serve as language servers for Python, but python-lsp-server is generally considered the more up-to-date and feature-rich option for modern Python development environments.

Language Server Protocol (LSP) support for vim and neovim.

Pros of LanguageClient-neovim

  • Multi-language support: Works with various language servers, not limited to Python
  • Neovim integration: Designed specifically for Neovim, offering seamless integration
  • Actively maintained: Regular updates and community support

Cons of LanguageClient-neovim

  • Setup complexity: Requires more configuration compared to python-language-server
  • Performance: May be slower for large projects due to its multi-language nature
  • Learning curve: Users need to understand Language Server Protocol (LSP) concepts

Code Comparison

LanguageClient-neovim configuration:

let g:LanguageClient_serverCommands = {
    \ 'python': ['pyls'],
    \ 'rust': ['rustup', 'run', 'stable', 'rls'],
    \ 'javascript': ['javascript-typescript-stdio'],
    \ }

python-language-server usage:

from pyls.__main__ import main
main()

The code comparison shows that LanguageClient-neovim requires more configuration to set up multiple language servers, while python-language-server is more straightforward for Python-specific use cases. LanguageClient-neovim offers greater flexibility, but python-language-server provides a simpler setup for Python development.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Python Language Server

.. image:: https://github.com/palantir/python-language-server/workflows/Linux%20tests/badge.svg :target: https://github.com/palantir/python-language-server/actions?query=workflow%3A%22Linux+tests%22

.. image:: https://github.com/palantir/python-language-server/workflows/Mac%20tests/badge.svg :target: https://github.com/palantir/python-language-server/actions?query=workflow%3A%22Mac+tests%22

.. image:: https://github.com/palantir/python-language-server/workflows/Windows%20tests/badge.svg :target: https://github.com/palantir/python-language-server/actions?query=workflow%3A%22Windows+tests%22

.. image:: https://img.shields.io/github/license/palantir/python-language-server.svg :target: https://github.com/palantir/python-language-server/blob/master/LICENSE

A Python 2.7 and 3.5+ implementation of the Language Server Protocol_.

Installation

The base language server requires Jedi_ to provide Completions, Definitions, Hover, References, Signature Help, and Symbols:

pip install python-language-server

If the respective dependencies are found, the following optional providers will be enabled:

  • Rope_ for Completions and renaming
  • Pyflakes_ linter to detect various errors
  • McCabe_ linter for complexity checking
  • pycodestyle_ linter for style checking
  • pydocstyle_ linter for docstring style checking (disabled by default)
  • autopep8_ for code formatting
  • YAPF_ for code formatting (preferred over autopep8)

Optional providers can be installed using the extras syntax. To install YAPF_ formatting for example:

pip install 'python-language-server[yapf]'

All optional providers can be installed using:

pip install 'python-language-server[all]'

If you get an error similar to 'install_requires' must be a string or list of strings then please upgrade setuptools before trying again.

pip install -U setuptools

3rd Party Plugins

Installing these plugins will add extra functionality to the language server:

* pyls-mypy_ Mypy type checking for Python 3
* pyls-isort_ Isort import sort code formatting
* pyls-black_ for code formatting using Black_

Please see the above repositories for examples on how to write plugins for the Python Language Server. Please file an
issue if you require assistance writing a plugin.

Configuration
-------------

Configuration is loaded from zero or more configuration sources. Currently implemented are:

* pycodestyle: discovered in ~/.config/pycodestyle, setup.cfg, tox.ini and pycodestyle.cfg.
* flake8: discovered in ~/.config/flake8, setup.cfg, tox.ini and flake8.cfg

The default configuration source is pycodestyle. Change the `pyls.configurationSources` setting to `['flake8']` in
order to respect flake8 configuration instead.

Overall configuration is computed first from user configuration (in home directory), overridden by configuration
passed in by the language client, and then overriden by configuration discovered in the workspace.

To enable pydocstyle for linting docstrings add the following setting in your LSP configuration:
```
"pyls.plugins.pydocstyle.enabled": true
```

See `vscode-client/package.json`_ for the full set of supported configuration options.

.. _vscode-client/package.json: vscode-client/package.json

Language Server Features
------------------------

Auto Completion:

.. image:: https://raw.githubusercontent.com/palantir/python-language-server/develop/resources/auto-complete.gif

Code Linting with pycodestyle and pyflakes:

.. image:: https://raw.githubusercontent.com/palantir/python-language-server/develop/resources/linting.gif

Signature Help:

.. image:: https://raw.githubusercontent.com/palantir/python-language-server/develop/resources/signature-help.gif

Go to definition:

.. image:: https://raw.githubusercontent.com/palantir/python-language-server/develop/resources/goto-definition.gif

Hover:

.. image:: https://raw.githubusercontent.com/palantir/python-language-server/develop/resources/hover.gif

Find References:

.. image:: https://raw.githubusercontent.com/palantir/python-language-server/develop/resources/references.gif

Document Symbols:

.. image:: https://raw.githubusercontent.com/palantir/python-language-server/develop/resources/document-symbols.gif

Document Formatting:

.. image:: https://raw.githubusercontent.com/palantir/python-language-server/develop/resources/document-format.gif

Development
-----------

To run the test suite:

``pip install .[test] && pytest``

Develop against VS Code
=======================

The Python language server can be developed against a local instance of Visual Studio Code.

Install `VSCode <https://code.visualstudio.com/download>`_

.. code-block:: bash

    # Setup a virtual env
    virtualenv env
    . env/bin/activate

    # Install pyls
    pip install .

    # Install the vscode-client extension
    cd vscode-client
    yarn install

    # Run VSCode which is configured to use pyls
    # See the bottom of vscode-client/src/extension.ts for info
    yarn run vscode -- $PWD/../

Then to debug, click View -> Output and in the dropdown will be pyls.
To refresh VSCode, press `Cmd + r`

License
-------

This project is made available under the MIT License.

.. _Language Server Protocol: https://github.com/Microsoft/language-server-protocol
.. _Jedi: https://github.com/davidhalter/jedi
.. _Rope: https://github.com/python-rope/rope
.. _Pyflakes: https://github.com/PyCQA/pyflakes
.. _McCabe: https://github.com/PyCQA/mccabe
.. _pycodestyle: https://github.com/PyCQA/pycodestyle
.. _pydocstyle: https://github.com/PyCQA/pydocstyle
.. _YAPF: https://github.com/google/yapf
.. _autopep8: https://github.com/hhatto/autopep8
.. _pyls-mypy: https://github.com/tomv564/pyls-mypy
.. _pyls-isort: https://github.com/paradoxxxzero/pyls-isort
.. _pyls-black: https://github.com/rupert/pyls-black
.. _Black: https://github.com/ambv/black