Client library for scirocco proyect.

pip install scirocco-pyclient==v2.1.3


Scirocco Pyclient

Build Status

This is a handy library to interact with the scirocco-server project. If you dont know about it , please read first that project docs.

Please if you want contribute to this project read this


This client library has two main install methods.

From source:

 git clone
 python3 install

From pip3:

 pip3 install scirocco-pyclient

Using the client

The response object

Every operation in this client will return the same response object , representing the state of the operation as well as the resultant message payload representation.

Instantiating the client

You must instantiate the HTTPClient by passing three params. Respectively they are:

  • scirocco-server endpoint (take care about http/https schema).
  • Your pre-stablished by convention node id (hexadecimal string, will be a mongo Objectid in future).
  • The master auth token for gain access to that scirocco-server instance.
from sciroccoclient.httpclient import HTTPClient

scirocco = HTTPClient('http://localhost', 'af123', 'DEFAULT_TOKEN')

Pushing messages

Pushing messages is simple as populate scirocco message object.

from sciroccoclient.messages import SciroccoMessage

# Preparing our fixed message properties.

msg = SciroccoMessage()
msg.node_destination = 'af123'

# Pushing an object

msg.payload = {"type": "message"}

#Pushing a string message payload

msg.payload = 'message'

# Pushing binary payload

with open('file.bin', 'rb') as f:
    msg.payload =
    msg.payload_type = '.bin'

# Pushing scheduled messages, 4 days in future (All in UTC).
from datetime import datetime, timedelta

msg.payload = 'This is an scheduled message.'
msg.scheduled_time = datetime.utcnow() + timedelta(days=4)

Some tips about above code are:

  • payload_type property is a 50 characters free field for determining how data must be handled in the consumer part. If not setted scirocco will populate it with detected mime type.
  • Scheduled messages, are messages that are not available to consumers until reaching scheduled_time in time frame. Warning , this is not the "consuming time", only the moment that are marked as "available" to consumers.

Receiving messages

You will receive messages in the same data type as you send it, except for binary type. You will push binary , and the item is stored as binary , but you will receive it in base64 representation.

response_object = scirocco.pull()

# print message metadata

# print the message payload.

If no pending messages the client will return None else, it will return a response object which contains metadata and payload. The message will change its status to 'processing', so it cannot be accesible by other 'pull' operation.

The on_receive callback

If you want to make a process that listens for incoming messages, you only need to generate a callback function that encapsulates all the logic that must process each message and create a consumer.

Callback function requirements are:

  • Must have two positional arguments
    • First for receiving the client it self for further operations, like ack current message.
    • Second argument will be the message received, in the form of SciroccoMessage Object .
def callback(client, message):


Above example blocks the process and waits for messages, that its contents will be throw into stdout.

If you do not want this behaviour and want this to be asynchronous you can specify at second parameter and let the program continue its execution. This will return the Thread object, ( for let you control thread execution.

on_receive_thread = scirocco.on_receive(callback, True)
print("Im ready, send me a message.")

# shutting down the consumer - thread

By default, the pull interval is set to 0.5 seconds. its important tune it according your needs. Remember that , at this time this is not a real time solution so dont abuse so much the server !

scirocco.on_receive(callback, False, 2) # last param its the pull interval, in this case augmented to 2 seconds.

If you want exiting the program from inside the callback function, you need to use the SciroccoInterruptOnReceiveCallbackError exception.This will shutdown the thread in your custom circunstances.

def callback(client, message):

    # do your stuff here      

    if message.payload['shutdown']:
        raise SciroccoInterruptOnReceiveCallbackError


Confirming messages (ack operation)

When you deal with IPC (inter process communications) or interdependant operations in different processes, you need to mark the message as "processed" for further operations in other processes.

You only need to save the id of the message that will be confirmed from response object ( in its pull operation to confirm the message by id. For example if we want to confirm '5823a70203c123003de4229b' message id , the code will be :


Reviewing a message

If you only need to watch the status of a message/es , call for get function, passing as parameter the id of message. Like this.


Getting all messages incoming/sended to/by this node

You optionally can pass a first argument to limit the returned results. Anyway, it will be limited by a server side config parameter.


# Limiting results by 10 (ordered by creation date)

Updating a message

As first parameter the id of the message. As second parameter the new data payload.

scirocco.update_one(msg_id, new_payload)

Deleting a message

You must specify as first parameter id of the message to be permanent removed from the system no matters its state. Cannot be undone.


Deleting all messages

Delete from the system all messages incoming/sended to/by this node. This operation only may be executed if you want a total reset of the node and its actions. Cannot be undone.


Running tests

For running all tests you will need and instance of scirocco-server project up and running at localhost.

git clone
cd scirocco-pyclient
python3 test