Registry / serialization / python-lsp-jsonrpc

python-lsp-jsonrpc

JSON →
library1.1.2pypypi✓ verified 25d ago

python-lsp-jsonrpc is a Python 3.8+ server implementation of the JSON RPC 2.0 protocol. This library was extracted from the Python LSP Server project to provide a standalone JSON-RPC core. It is currently at version 1.1.2 and receives updates as needed for bug fixes and minor feature enhancements.

pip install -U python-lsp-jsonrpc
INSTALL
IMPORT
SIG · PYTHON-LSP-JSONRPC
P
python-lsp-jsonrpc
serializationpythonv1.1.2
Install
1.6s avg
Import
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 21.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JSONRPCServer
from jsonrpc.server import JSONRPCServer
from python_lsp_jsonrpc.server import JSONRPCServer
The PyPI package `python-lsp-jsonrpc` is imported via the top-level module `jsonrpc`.
JSONRPCMethodManager
from jsonrpc.manager import JSONRPCMethodManager
from python_lsp_jsonrpc.manager import JSONRPCMethodManager
The PyPI package `python-lsp-jsonrpc` is imported via the top-level module `jsonrpc`.

This quickstart demonstrates a basic JSON-RPC server handling two methods: `sum` and `notify_exit`. The server communicates over standard I/O, expecting JSON-RPC requests on stdin and sending responses to stdout. To run, save as `server.py` and execute `python server.py`. You can then send JSON-RPC requests via a client (e.g., using `echo '{"jsonrpc": "2.0", "method": "sum", "params": {"a": 1, "b": 2}, "id": 1}' | python server.py`).

import logging import sys from jsonrpc.manager import JSONRPCMethodManager from jsonrpc.server import JSONRPCServer logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) handler = logging.StreamHandler(sys.stderr) handler.setFormatter(logging.Formatter('%(levelname)s: %(message)s')) logger.addHandler(handler) class ExampleManager(JSONRPCMethodManager): def sum(self, a, b): logger.info(f"Received sum request for {a}, {b}") return a + b def notify_exit(self): logger.info("Received exit notification.") sys.exit(0) def main(): manager = ExampleManager() server = JSONRPCServer(manager) logger.info("Starting JSON RPC server (STDIO). Send JSON RPC requests via stdin.") server.serve_forever() if __name__ == '__main__': main()
Debug
Known issues
breakingAs of version 1.1.0, support for Python 3.7 and 3.6 has been dropped. Users on these Python versions must either upgrade their Python environment or pin to a previous version of `python-lsp-jsonrpc`.
fix
Upgrade to Python 3.8 or newer, or pin `python-lsp-jsonrpc<1.1.0`.
affects: >=1.1.0
breakingVersion 1.0.0 introduced a package rename. This library is a fork of Palantir's `python-jsonrpc-server` and has been renamed to `python-lsp-jsonrpc`. Code referencing the old package name will break.
fix
Update package installations (`pip install python-lsp-jsonrpc`) and all import statements from `python_jsonrpc_server` to `jsonrpc`.
affects: >=1.0.0
gotchaThe PyPI package name is `python-lsp-jsonrpc`, but the top-level Python import module is `jsonrpc`. Attempting to import from `python_lsp_jsonrpc` will result in an `ImportError`.
fix
Ensure all import statements use `from jsonrpc.server import ...` or `from jsonrpc.manager import ...`.
affects: All versions
gotchaWhile `python-lsp-jsonrpc` is compatible with both `ujson` (for performance) and Python's built-in `json` library, ensure consistent usage if relying on specific `ujson` features or performance characteristics, as tests have specifically addressed compatibility.
fix
If `ujson` is desired, ensure it is installed (`pip install ujson`). Otherwise, no specific action is needed as the standard `json` library is used by default.
affects: All versions
Upgrade
Version history
1.1.2latest on PyPI · released Sep 23, 2023
Audit
Dependencies
ujsonoptionalOptional dependency for faster JSON serialization/deserialization. The library is compatible with both 'ujson' and the standard 'json' library.
Agent activity
16 hits · last 30 days
node
12
OpenAI (training)
1
Resources
python-lsp-jsonrpc — pip install python-lsp-jsonrpc · libregistry