Code for creating Twisted JSON-RPC servers and clients.
Project description
Introduction
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.
Features
🚀 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
Installation
Install from PyPI using pip:
pip install txjsonrpc-ng
Or using Poetry:
poetry add txjsonrpc-ng
Requirements:
Python 3.10 or higher
Twisted 24.11 or higher
Quick Start
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()
Examples
More examples are available in the examples/ directory:
examples/web/ - HTTP-based JSON-RPC
examples/tcp/ - TCP/Netstring-based JSON-RPC
examples/ssl/ - SSL-secured JSON-RPC
examples/webAuth/ - Authenticated JSON-RPC
Documentation
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
License
txjsonrpc-ng is licensed under BSD and GPL. See LICENSE for details.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
Support
Issues: GitHub Issues
Source: GitHub Repository
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file txjsonrpc_ng-0.8.0.tar.gz.
File metadata
- Download URL: txjsonrpc_ng-0.8.0.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.9 Darwin/25.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9f542bb4ebfb8dd9a2e012503acd5d3a0fd0b5136fc29d8df2ca4d6abae915e
|
|
| MD5 |
5863db23ab5646ae9d236b8c329a70a4
|
|
| BLAKE2b-256 |
ffd639bebd54ca6d750b2ffccdafec61cac76875689d754e593d5a64c415372e
|
File details
Details for the file txjsonrpc_ng-0.8.0-py3-none-any.whl.
File metadata
- Download URL: txjsonrpc_ng-0.8.0-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.9 Darwin/25.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b50e0e3c66c8130340f7e71ddc82451e25ca7aa68deb1097e69b491a9ea77bcf
|
|
| MD5 |
16f7b723251d3548231a66cf1f4da4d0
|
|
| BLAKE2b-256 |
d2a011282bb1703707997a2c835d8dbd6b33dc0ad9587e6d868b005a51ac0890
|