All Projects → dwb → jsonrpc2-zeromq-python

dwb / jsonrpc2-zeromq-python

Licence: BSD-3-Clause license
JSON-RPC 2.0 over ZeroMQ in Python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to jsonrpc2-zeromq-python

JsonRpc.Standard
An asynchronous .NET Standard library for JSON RPC client & server implementation.
Stars: ✭ 27 (-48.08%)
Mutual labels:  json-rpc, json-rpc2, json-rpc-client, json-rpc-server
jsonrpcpp
C++ JSON-RPC 2.0 library
Stars: ✭ 97 (+86.54%)
Mutual labels:  json-rpc, json-rpc2
node-jsonrpc2
JSON-RPC 2.0 server and client library, with HTTP (with Websocket support) and TCP endpoints
Stars: ✭ 103 (+98.08%)
Mutual labels:  json-rpc, json-rpc2
xmlrpcwsc-dotnet
XML-RPC Web Service Client C# implementation
Stars: ✭ 30 (-42.31%)
Mutual labels:  json-rpc, json-rpc-client
rpcsrv
JSON-RPC server based on C++11 and libevent
Stars: ✭ 28 (-46.15%)
Mutual labels:  json-rpc, json-rpc-server
MetaTrader4-Bridge
Communication layer between MetaTrader 4 and your project.
Stars: ✭ 66 (+26.92%)
Mutual labels:  zeromq
Spooky
An HttpClient based Json RPC 2.0/XML-RPC client for .Net.
Stars: ✭ 16 (-69.23%)
Mutual labels:  json-rpc
ZeroMQ
🚀 Client/Server & Pub/Sub Examples with ZeroMQ & Boost
Stars: ✭ 33 (-36.54%)
Mutual labels:  zeromq
Rockets
REST and websockets C++ library
Stars: ✭ 39 (-25%)
Mutual labels:  json-rpc
pony-zmq
Pure Pony implementation of the ZeroMQ messaging library. 🐴 0️⃣ Ⓜ️ 🍀
Stars: ✭ 64 (+23.08%)
Mutual labels:  zeromq
coreipc
WCF-like service model API for communication over named pipes and TCP. .NET and node.js clients.
Stars: ✭ 22 (-57.69%)
Mutual labels:  json-rpc
distributedRL
A framework for easy prototyping of distributed reinforcement learning algorithms
Stars: ✭ 93 (+78.85%)
Mutual labels:  zeromq
dynamic-queue
The dynamic queue
Stars: ✭ 17 (-67.31%)
Mutual labels:  zeromq
distmq
Distributed Message Queue based on Raft
Stars: ✭ 32 (-38.46%)
Mutual labels:  zeromq
consensusj
Cryptocurrency components for JVM & Android (JSON client & server support, services, DSL, CLI)
Stars: ✭ 76 (+46.15%)
Mutual labels:  json-rpc
callosum
An RPC Transport Library for asyncio
Stars: ✭ 17 (-67.31%)
Mutual labels:  zeromq
webuntis
A API library that makes it easy to access the Webuntis JSON RPC 2.0 API
Stars: ✭ 22 (-57.69%)
Mutual labels:  json-rpc
napalm-logs
Cross-vendor normalisation for network syslog messages, following the OpenConfig and IETF YANG models
Stars: ✭ 131 (+151.92%)
Mutual labels:  zeromq
Ether1
Official Go implementation of The Etho Protocol
Stars: ✭ 41 (-21.15%)
Mutual labels:  json-rpc
Bynar
Server remediation as a service
Stars: ✭ 53 (+1.92%)
Mutual labels:  zeromq

JSON-RPC 2.0 Over ZeroMQ

Travis build status

Written by Dan Brown. See the the LICENSE file for licensing information.

This is a library in Python enabling JSON-RPC 2.0 over ZeroMQ. It includes support for both clients and servers.

This is packaged as a standard Python project, so just install using python setup.py install, or with pip.

Supports Python 2.7 and 3.3+.

Servers

from jsonrpc2_zeromq import RPCServer

class EchoServer(RPCServer):

    def handle_echo_method(self, msg):
        return msg

s = EchoServer("tcp://127.0.0.1:57570")
s.run()

This creates a server listening on a ZeroMQ REP socket – so only methods are allowed, not notifications. See the RPCNotificationServer as well, which will listen on a ROUTER socket and allow notifications.

Each server is a Python Thread, so the call to run() can be replaced by start() to have it running in a background thread.

Clients

from jsonrpc2_zeromq import RPCClient

c = RPCClient("tcp://127.0.0.1:57570")
print c.echo("Echo?")

# Assuming the above compliant server, should print "Echo?"

There are various classes, assuming different JSON-RPC 2.0 and ZeroMQ characteristics. The above, for example, will connect a REQ socket to the given endpoint.

Notifications

Given a server that accepts notifications:

from jsonrpc2_zeromq import RPCNotificationServer

class EventReceiver(RPCNotificationServer):

    def handle_event_method(self, event_type, event_data):
        print "Got event!\nType: {0}\nData: {1}\n".format(event_type, event_data)

s = EventReceiver("tcp://127.0.0.1:60666")
s.run()

You can then send notifications thus:

from jsonrpc2_zeromq import RPCNotifierClient

c = RPCNotifierClient("tcp://127.0.0.1:60666")
c.notify.event('birthday!', 'yours!')

Also included are NotificationOnlyPullServer and NotifierOnlyPushClient which are designed for sending only notifications one-way over PUSH and PULL sockets.

There is also a client, NotificationReceiverClient, that is able to handle notifications returned back to it from a server. This is useful for situations where you "subscribe", via a standard RPC call, to events from the server, and they are returned back to the client as notifications when they occur. There is not currently a corresponding server class for this pattern. Here is a (one-sided) example:

from jsonrpc2_zeromq import NotificationReceiverClient

class EventSubscriber(NotificationReceiverClient):

    def handle_event_notification(self, event_type, event_data):
        print "Got event!\nType: {0}\nData: {1}\n".format(event_type, event_data)

c = EventSubscriber("tcp://127.0.0.1:60666")
c.subscribe()
c.wait_for_notifications()

Logging

The standard Python logging module is used for logging. It doesn't output anything by default. Either retrieve the built-in library logger with logging.getLogger('jsonrpc2_zeromq') or pass your own Logger instance into a client or server's __init__ with the logger keyword argument.

Currently there are some helpful messages outputted at the DEBUG level, server exceptions on ERROR, and a server start message on INFO.

Testing

Tests are included. Run python setup.py test in the project root.

History

2.0
  • Python 3.3+ support
1.1.2
  • Allow newer (v14) pyzmq.
  • Don't raise EINTR in server recv loop.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].