PYTHON API

The PYTHON Server API allows application to send real-time messages via the PushFYI server. The PYTHON API allow requests to be made synchronously.

PYTHON Server API has 2 main functions. In this documentation, we will examine the API usage and some of the best practices.

PushFYI - Interface Class

The PushFYI class is the entry point for any application to send receive real-time messages via the PushFYI WebSocket Gateway. This class wraps all the necessary methods to send real-time events.

This is not a singleton class and you can create more than one objects of this class.

Argument List:

SN parameters note
1 appsecret This parameter identifies your App when it connects to PushFYI. Since PushFYI can serve real-time messages to many apps simultaneously. This field allows PushFYI to distinguish between Apps, so that real-time messages from one App do not mix up with another App. The value of appsecret parameter is in UUID format. e.g. 123e4567-e89b-12d3-a456-426655440000
2 address URL of your pushfyi instance. e.g. 10.0.0.101
3 isSecure Boolean variable for secure and plain text connection. e.g.True for secure and False for plain text connection

Code Sample:


                                                      using libpushfyi;

    class DemoJSONPublish(object):
    
        if __name__ == '__main__':
		''' 
		 initialize the connection 
		 @param app_secret
		 @param cluster_address
		 @param isSecure
		'''
			p = Pushfyi("<your appsecret key>","<your pushfyi ip address>", "<secure connection>")
        
    
    

publish(channel, data)

The publish method allows a application to publish a realtime message synchronously on a given data channel. PushFYI data channels are logical names to which realtime messages are sent to.

This method allows you to send a single message on a given data channel.

Parameter List:

SN parameters note
1 channel The logical name of the data channel associated with an event.
2 data Data type string as template argument.

Code Sample:

  
						using libpushfyi;
    class DemoJSONPublish(object):
    
    '''
    A demo class to publish simple json data using python lib
    '''

    if __name__ == '__main__':  
    
    # pushyi constructor initialized here
    # param app_secretkey,clusteraddress,unsecure connection
    p = Pushfyi("<your appsecret key>","<your pushfyi ip address>", "<secure connection>")
    
    # creating simple json data to send over pushfyi
    data = {'name': 'userName', 'message': 'Message from userName'}
    json_data = json.dumps(data)
    
    # publishing json data on given channelName
    p.publish('channel_name', json_data)