src package

Submodules

src.ubii_client_node module

class src.ubii_client_node.UbiiClientNode(name='pythonNodeV2', service_endpoint='http://localhost:8102/services/binary', topicdata_endpoint='ws://localhost:8104')[source]

Bases: object

This class represents the python client node v.2 https://github.com/SandroWeber/ubii-node-python-v2 for the UBI-Interact framework https://github.com/SandroWeber/ubi-interact/wiki.

Variables:

events

Four Events (‘onPublishError’, ‘onReadError’, ‘onServiceCallError’, ‘onConnectionError’) for error handling, each event can be subscribed to with a callback that takes exactly one Exception as parameter. Whenever an Error occurs the associated events gets called.

”Events”:

def handleExc(e):
    print(e)

node = UbiiClientNode()
node.events.onConnectionError += handleExc

call_service(request: ServiceRequest) Future[source]

Makes a service request to the masternode.

This happens asynchronous but returns a future with the ServiceReply from the masternode once finished or None if the process raised an exception.

Parameters:

request (ServiceRequest) – The ServiceRequest sent to the masternode.

Returns:

The Future with the ServiceReply or with None.

Return type:

Future

getId()[source]
Returns:

The id the node got from the masternode if connected, None else.

Return type:

str or None

init()[source]
initClientSpecs()[source]
async initNetwork()[source]
isConnected()[source]
Returns:

The connection status with the masternode.

Return type:

bool

publish(record: TopicDataRecord)[source]

Publishes the topicDataRecord in the next interval.

Ads the TopicDataRecord to a list of TopicDataRecords that will be sent to the masternode in the next publish interval. If the list already contains a TopicDataRecord with the specified topic the TopicDataRecord in the list will be overwritten with this one. The process of sending the TopicDataRecord to the masternode happens asynchronous in a different thread.

Parameters:

record (TopicDataRecord) – The TopicDataRecord to publish.

publishImmediately(data: TopicDataRecord)[source]

Publishes the topicDataRecord instantly.

Sends the TopicDataRecord directly to the masternode. The process of sending the topic to the masternode happens asynchronous in a different thread.

Parameters:

data (TopicDataRecord) – The TopicDataRecord to publish.

publishList(recordList: TopicDataRecordList)[source]

Publishes the elements of the TopicDataRecordList in the next interval.

Ads every TopicDataRecord from the TopicDataRecordList to a list of TopicDataRecords that will be sent to the masternode in the next publish interval. If the list already contains a TopicDataRecord with the specified topic the TopicDataRecord in the list will be overwritten with this one. The process of sending the TopicDataRecords to the masternode happens asynchronous in a different thread.

Parameters:

recordList (TopicDataRecordList) – The TopicDataRecordList with the topics to publish

setPublishFrequency(frequency)[source]

Changes the frequency the node sends the published topicdata to the masternode.

Parameters:

frequency (float) – the time interval.

stopNode()[source]

Needs to be called when the node is no longer used in any form to disconnect it from the masternode and to stop background threads. The disconnection process happens asynchronous in a different thread.

subscribeRegex(regex: str, callback: Callable[[TopicDataRecord], None]) SubscriptionToken[source]

Subscribes to a regular expression.

Whenever a topicDataRecord is published at the masternode for a topic that fits this regular expression that topicDataRecord will be sent to this node and the callback passed is invoked for this topicDataRecord. The process to subscribe at the masternode happens asynchronous in a different thread.

Parameters:
  • regex (str) – The regular expression that should be subscribed to.

  • callback (Callable[[TopicDataRecord], None]) – The callback that takes exactly one TopicDataRecord as parameter and returns nothing.

Returns:

The SubscriptionToken that contains a unique token id, the regex, the callback, and the SubscriptionTokenTYPE.

Return type:

SubscriptionToken

subscribeTopic(topic: str, callback: Callable[[TopicDataRecord], None]) SubscriptionToken[source]

Subscribes to a topic.

Whenever a topicDataRecord is published at the masternode for this topic, that topicData will be sent to this nodeand the callback passed is invoked for this topicDataRecord. The process to subscribe at the masternode happens asynchronous in a different thread.

Parameters:
  • topic (str) – The topic that should be subscribed to

  • callback – The callback that takes exactly one TopicDataRecord as parameter and returns nothing

Returns:

The SubscriptionToken that contains a unique token id, the regex, the callback, and the SubscriptionTokenTYPE.

Return type:

SubscriptionToken

unsubscribe(token: SubscriptionToken) bool[source]

Unsubscribes the subscription token.

The callback that was passed when subscribing is no longer executed when a topicDataRecord is received for this topic. When there are no more subscribers for a topic at this node, the node unsubscribes at the masternode and won’t receive any published topicData. The callback will be unsubscribed synchronous, but the process to unsubscribe at the masternode happens asynchronous in a different thread.

Parameters:

token (SubscriptionToken) – The subscriptionToken that was returned when subscribing.

Returns:

The success of the operation.

Return type:

bool

waitForConnection()[source]

Pauses the current thread until the node is connected to the masternode.

src.TopicDataBuffer module

class src.TopicDataBuffer.SubscriptionToken(id: int, topic: str, callback: Callable[[TopicDataRecord], None], type: SubscriptionTokenTYPE)[source]

Bases: object

class src.TopicDataBuffer.SubscriptionTokenTYPE(value)[source]

Bases: Enum

An enumeration.

REGEX = 2
TOPIC = 1
class src.TopicDataBuffer.TopicDataBuffer[source]

Bases: object

generateToken(topic: str, callback: Callable[[TopicDataRecord], None], type: SubscriptionTokenTYPE) SubscriptionToken[source]
getRegexSubscriptionTokens(regex: str) List[SubscriptionToken][source]
getTopicSubscriptionTokens(topic: str) List[SubscriptionToken][source]
notifySubscribers(topicDataRecord)[source]
publish(topicDataRecord: TopicDataRecord)[source]
pull(topic: str) TopicDataRecord[source]
remove(topic: str)[source]
subscribeRegex(regex: str, callback: Callable[[TopicDataRecord], None]) SubscriptionToken[source]
subscribeTopic(topic: str, callback: Callable[[TopicDataRecord], None]) SubscriptionToken[source]
unsubscribe(token: SubscriptionToken) bool[source]

src.TopicDataProxy module

class src.TopicDataProxy.TopicDataProxy(topicDataBuffer: TopicDataBuffer, networkClient: UbiiNetworkClient, node)[source]

Bases: object

getRegexSubscriptionTokens(regex: str) List[SubscriptionToken][source]
getTopicSubscriptionTokens(topic: str) List[SubscriptionToken][source]
onTopicDataRecord(record: TopicDataRecord)[source]
pull(topic: str) TopicDataRecord[source]
remove(topic: str)[source]
setPublishFrequency(frequency)[source]
stopNode()[source]
subscribeRegex(regex: str, callback: Callable[[TopicDataRecord], None]) SubscriptionToken[source]
subscribeTopic(topic: str, callback: Callable[[TopicDataRecord], None]) SubscriptionToken[source]
unsubscribe(token: SubscriptionToken) bool[source]

src.UbiiNetworkClient module

class src.UbiiNetworkClient.UbiiNetworkClient(serviceEndpoint, topicDataEndpoint, clientSpecs, node)[source]

Bases: object

callService(request: ServiceRequest) Future[source]
async init()[source]
publish(record: TopicDataRecord)[source]
publishImmediately(record: TopicDataRecord)[source]
async registerAsClient(client: Client) Client[source]
setPublishFrequency(frequency)[source]
stopNode()[source]
subscribeRegex(regex: str, callback: Callable[[TopicDataRecord], None])[source]
subscribeTopic(topic: str, callback: Callable[[TopicDataRecord], None])[source]
unsubscribe(topic: str, callback: Callable[[TopicDataRecord], None])[source]
unsubscribeRegex(regex: str, callback: Callable[[TopicDataRecord], None])[source]

src.ubii_service_client module

class src.ubii_service_client.UbiiServiceClient(endpoint, node)[source]

Bases: object

async send(request: ServiceRequest, timeout=None) ServiceReply[source]
async sendProto(request: ServiceRequest, timeout=None) ServiceReply[source]

src.ubii_topicdata_client module

class src.ubii_topicdata_client.UbiiTopicDataClient(endpoint, clientID, node)[source]

Bases: object

addRegexCallback(regex: str, callback: Callable[[TopicDataRecord], None])[source]
addTopicCallback(topic: str, callback: Callable[[TopicDataRecord], None])[source]
hasRegexCallbacks(regex: str)[source]
hasTopicDataCallbacks(topic: str) bool[source]
isSubscribed(topicRegex: str) bool[source]
publish(topicDataRecord: TopicDataRecord)[source]
removeAllRegexCallbacks(regex: str)[source]
removeRegexCallback(regex: str, callback: Callable[[TopicDataRecord], None])[source]
removeTopicCallback(topic: str, callback: Callable[[TopicDataRecord], None])[source]
removeTopicDataCallbacks(topic: str)[source]
async sendTopicData(record: TopicData)[source]
setPublishFrequency(frequency)[source]
stopNode()[source]