20

What are my options for integrating Python with SignalR?

The Python code is a part of large 3rd party product, not a matter of language preference. SignalR server provides subscriptions to existing .NET products.

We would like to reuse .NET SignalR server with Python.

Den
  • 1,827
  • 3
  • 25
  • 46
  • 8
    What is the reason for down-voting? How can I improve my question that describes an actual real-world work programming problem? – Den Jun 17 '13 at 13:23

2 Answers2

11

There is a SignalR client available on the python package index named "signalr-client" which supports some basic SignalR functionality Source

It is compatible with Python v2 and v3.

Functionality supported includes:

  • Connecting to SignalR Hub
  • Invoking SignalR Method
  • Event handler to process SignalR Notifications

It requires the following modules installed via pip:

  • gevent
  • sseclient
  • websocket-client

Sample usage as per link:

#create a connection
connection = Connection(url, session)

#start a connection
connection.start()

#add a handler to process notifications to the connection
connection.handlers += lambda data: print 'Connection: new notification.', data

#get chat hub
chat_hub = connection.hub('chat')

#create new chat message handler
def message_received(message):
    print 'Hub: New message.', message

#receive new chat messages from the hub
chat_hub.client.on('message_received', message_received)

#send a new message to the hub
chat_hub.server.invoke('send_message', 'Hello!')

#do not receive new messages
chat_hub.client.off('message_received', message_received)

#close the connection
connection.close()
Philippe
  • 1,287
  • 11
  • 23
Malcolm McCaffery
  • 2,468
  • 1
  • 22
  • 43
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Mp0int Nov 04 '15 at 08:19
  • 1
    Well you need to download the library from this link, so the link essentially is the answer, not enough space to describe how to write an Python SignalR client in the available space for answers – Malcolm McCaffery Nov 04 '15 at 08:21
  • This could be a command, or you can be add essential parts to the answer like which *some basic signalR functionalities* are suppoerted and it become an answer. – Mp0int Nov 04 '15 at 08:41
  • 1
    Update: signalr-client v0.0.6 is compatible with Python 2 and 3. – HEADLESS_0NE Mar 01 '16 at 16:57
  • 1
    signalr-python project seems dead to me. Try signalrcore on PyPi. – Ytsen de Boer Sep 22 '20 at 08:13
3

I can think of a few ways and they are all theoretical (and probably bad ideas to begin with):

  • IPC - host the python app and the signalr app as different processes and somehow pipe information back and forth using some kind of ipc mechanism (named pipes, tcp, something else).
  • Use IronPython (which probably isn't really an option).
  • Port a lightweight verison of SignalR to python (https://github.com/davidfowl/SignalR.Lite). Probably won't work the same way but maybe you don't need all the features.

Or you can hope to find a library in python that does something similar.

davidfowl
  • 37,120
  • 7
  • 93
  • 103