txjsonrpc-ng is an asynchronous JSON-RPC library for Python built on Twisted. It allows you to create async Python JSON-RPC servers and clients either over HTTP or directly on TCP with the Netstring protocol.
- 🚀 Asynchronous: Built on Twisted for high-performance async I/O
- 🌐 Multiple Transports: HTTP and TCP (Netstring) support
- 📋 Protocol Versions: Supports JSON-RPC pre-1.0, 1.0, and 2.0
- 🔒 Authentication: Built-in authentication support
- 🔍 Introspection: Built-in method introspection (listMethods, methodHelp, methodSignature)
- 📚 jsonrpclib: Similar to Python's xmlrpclib for easy migration
Install from PyPI using pip:
pip install txjsonrpc-ngOr using Poetry:
poetry add txjsonrpc-ngRequirements:
- Python 3.10 or higher
- Twisted 24.11 or higher
Server Example (HTTP)
from twisted.web import server
from twisted.internet import reactor
from txjsonrpc_ng.web.jsonrpc import Handler
class ExampleHandler(Handler):
def jsonrpc_echo(self, message):
"""Echo the message back"""
return message
def jsonrpc_add(self, a, b):
"""Add two numbers"""
return a + b
if __name__ == '__main__':
r = ExampleHandler()
reactor.listenTCP(8080, server.Site(r))
print("JSON-RPC server running on http://localhost:8080/")
reactor.run()Client Example (HTTP)
from twisted.internet import reactor
from txjsonrpc_ng.web.jsonrpc import Proxy
def printResult(result):
print("Result:", result)
reactor.stop()
def printError(error):
print("Error:", error)
reactor.stop()
if __name__ == '__main__':
proxy = Proxy('http://localhost:8080/')
d = proxy.callRemote('add', 5, 3)
d.addCallback(printResult)
d.addErrback(printError)
reactor.run()More examples are available in the examples/ directory:
examples/web/- HTTP-based JSON-RPCexamples/tcp/- TCP/Netstring-based JSON-RPCexamples/ssl/- SSL-secured JSON-RPCexamples/webAuth/- Authenticated JSON-RPC
- Installation: See
docs/INSTALL.txt - Usage Guide: See
docs/USAGE.txt - Specifications: See
docs/specs/for JSON-RPC protocol versions - Contributing: See
CONTRIBUTING.md - Security: See
SECURITY.md
txjsonrpc-ng is licensed under BSD and GPL. See LICENSE for details.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
- Issues: GitHub Issues
- Source: GitHub Repository