Please Wait

Loading..

Python SDK 1.0.6

Create amazing realtime applications easily with Yalgaar Python SDK

1 Connect To Yalgaar

Requirement :

Supports Python 3.4 and above

Download/install Yalgaar SDK into your machine.

pip install pyYalgaar
    OR
python -m pip install pyYalgaar

Import Yalgaar SDK into your program.

from yalgaar import Yalgaar

To connect to a Yalgaar client,use following method, it must have valid Client Key.

objYalgaar = Yalgaar()
objYalgaar.yalgaarConnect(clientKey, isSecure, connectionCallback, uuid = None, aesType = None, aesKey = None)

Parameter:

  • clientKey
    • Description: Yalgaar provided authentic client key for project.
    • DataType: string
  • isSecure
    • Description: Secure connection with SSL [True / False].
    • DataType: boolean (value must be true or false)
  • UUID
    • Description: Any unique user name or user id. UUID is CASE SENSITIVE and only alpha numeric, hyphens,@,underscore allowed and maximum length must be 50.
    • DataType: string
  • AESSecretKey
    • Description: Secret key use for encrypt/decrypt message.
    • DataType: string
  • AESType
    • Description: Type of AES algorithm use for encrypt/decrypt message. Support 128,192,256 for AES_128, AES_192, AES_256 respectively.
    • DataType: Numbers
  • connectionCallback
    • Description: callback function with int (error code) and String (error string) argument.

Note :

Here thread is created to process the network data. You can call objYalgaar.loop_forever() or objYalgaar.loop() continuously in your application if you don’t want to create a thread.



2 Publish Message

To publish message, use following method

objYalgaar.yalgaarPublish(channel, message)

Parameter:

  • channel
    • Description: Channel name on which message will be published. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • Data Type: string
  • message
    • Description: Data to be send on given channel.
    • DataType: string


3 Subscribe Message

To subscribe message, use following method.

objYalgaar.yalgaarSubscribe(channel/channels, SubscribeReturnMessageCallback, PresenceMessageCallback, ErrorMsgCallback)

Parameter:

  • channel/channels
    • Description: Single channel name or multiple channels name on which message will be subscribed. For multiple channel names use array. Channel name is CASE SENSITIVE. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: string (for multiple channels use array).
  • SubscribeReturnMessageCallback
    • Description: Callback function to consume received message with String(channel name) and String(message) argument.
  • PresenceMessageCallback
    • Description: Callback function to consume presence events such as join or leave with String (received data) argument.
  • ErrorMsgCallback
    • Description: Callback function to consume error message with String (error string) argument.


4 Unsubscribe Message

To unsubscribe message,use following method.

objYalgaar.yalgaarUnSubscribe(channel/channels)

Parameter:

  • channel/channels
    • Description: Single channel name or multiple channels name to be unsubscribe. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50. For multiple channel names use array
    • DataType: string


5 Get User List

To get list of all users subscribed with specific channel name, use following method.

objYalgaar.yalgaarUserList(Channel, UserListCallback, ErrorMsgCallback)

Parameter:

  • channel
    • Description: Valid channel name. Channel name is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: string
  • UserListCallback
    • Description: Callback is called when successfully get user list.
  • ErrorMsgCallback
    • Description: Callback function to consume error message with String (error string) argument.


6 Get Channel List

To get list of all channels subscribed by specified user, use following method.

objYalgaar.yalgaarChannelList(UUID, ChannelListCallback, ErrorMsgCallback)

Parameter:

  • UUID:
    • Description: Valid user Id. user Id is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: string
  • ChannelListCallback
    • Description: Callback is called when successfully get channel list.
  • ErrorMsgCallback
    • Description: Callback function to consume error message with String (error string) argument.


7 Get Message History

To get the already published messages, use following method

objYalgaar.yalgaarHistory(channel, MessageCount, HistoryMessageCallback, ErrorMsgCallback)

Parameter:

  • channel
    • Description: Valid channel name. Channel name is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: string
  • messageCount
    • Description: How many messages that you want to fetch. Maximum 100 messages allow at a time.
    • Data Type: integer
  • $historyMessageCallback
    • Description: Callback is called when successfully get message history list.
  • $errorMsgCallback
    • Description: Callback function to consume error message with String (error string) argument.


You can publish/subscribe message like so :

from yalgaar import Yalgaar
def on_connect(code, error_str):
     print(error_str)

def on_message(topic, data):
     print(data)

def on_presence(data):
     print(data)

def on_error(data):
     print(data)

objYalgaar = Yalgaar()
objYalgaar.yalgaarConnect('ClientKey', False, on_connect, None, None, None)
objYalgaar.yalgaarSubscribe('YourChannel', on_message, on_presence, on_error)
objYalgaar.yalgaarPublish('YourChannel', 'This is Yalgaar Python SDK Example')
objYalgaar.loop_forever()

#following code can also be used instead of loop_forever API.
while True:
    objYalgaar.loop()