Skip to main content

Code for creating Twisted JSON-RPC servers and clients.

Project description

PyPI version Python versions License Quality gate Coverage Reliability rating OpenSSF Scorecard

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

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

txjsonrpc_ng-0.8.1.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

txjsonrpc_ng-0.8.1-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file txjsonrpc_ng-0.8.1.tar.gz.

File metadata

  • Download URL: txjsonrpc_ng-0.8.1.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.14.4 Darwin/25.4.0

File hashes

Hashes for txjsonrpc_ng-0.8.1.tar.gz
Algorithm Hash digest
SHA256 7113f6273557a5f76b5e02a0f4c48c10c97d55193a487fa4ab4aa812aa7cb73c
MD5 f5035301a7fa0288f229193471fb9c2a
BLAKE2b-256 44f6cec3defceb9515191146eb83cc40106f1ebc40a0f9a55d1e899de7eff502

See more details on using hashes here.

File details

Details for the file txjsonrpc_ng-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: txjsonrpc_ng-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.14.4 Darwin/25.4.0

File hashes

Hashes for txjsonrpc_ng-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f7ee79333df24854b761ef50e89c65dbef8b161296fee18b530bd08be9a9bea0
MD5 1b13235d7163d688e894980f166e7e27
BLAKE2b-256 e724246316e9eb9b9d43c8b746f862ad7df56fa8fadafea2875f0171970bac29

See more details on using hashes here.

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