Pubkeeper Python Client

The Python client is implemented on a Tornado IOLoop. We use Tornado since it provides a good IOLoop and WebSocket client. The client itself is contained in a thread. The act of instantiating the client will create a new Tornado IOLoop within that thread and start itself.

You will first instantiate a client object, providing a dictionary of configuration options. After which you will want to configure and add any brews you wish to use with this client. Next you can register, or obtain, brewer or patron objects. Once setup, a call to start() will begin the connection ad registration to the server. On applicaiton stop you will need to call stop() to properly ensure the thread is closed.

API Reference

__init__(config)

config—Configuration dictionary for the client

Deprecated Arguments

jwt—Token used to authenticate [Deprecated: 1.1.0]

Creating the client is simple, just provide the token issued from the server. You may also provide a dictionary of configuration options. See valid options here:

Optional configuration options

  • authenticate_timeout—Time to wait for a successful authentication to the server.
  • bridge_mode—Should this client be allowed to form bridges between brews.
  • daemon_thread—Whether to run the main PK client thread as a daemon thread or not. Defaults to True.

start(_async=None)

_async—Should this client operate in asynchronous mode? If disabled, after a deadline a RuntimeError will be raised if we do not establish an authenticated connection to the server.

Deprecated Arguments

  • bridge_mode—Should this client be allowed to form bridges between brews. [Deprecated: 1.1.0, moved to config in constructor]

Once all the brews are added to the client, a call to start will initiate the client thread and begin connection to the Pubkeeper server. This is a blocking call and will timeout if unable to connect to a Pubkeeper server. Calls to add_brewer or add_patron will fail until the client is connected to a Pubkeeper server.

stop()

This will unregister all brewers and patrons that have been registered. The connection will be gracefully closed and the internal ioloop stopped. This is a blocking command, joining on the client thread to stop.

add_brew(brew)

brew—Brew object.

Add the brew object to the internal set of known brews able to be used for communication.

remove_brew(brew)

brew—Brew object.

Remove the brew object from the internal set of known brews able to be used for communication.

add_brewer(topic, crypto=True, brewer_id=None)

topic—Topic to be published.
crypto—Should data brewed by this brewer be ciphered with AES-CBC. Defaults to True
brewer_id—ID of the brewer. If provided, it must be a 16 byte string. Defaults to uuid.uuid4().hex

This method will create and return a brewer object for the given topic. It will alert every brew of its existence and create and send a Brewer Register Packet to the Pubkeeper server.

remove_brewer(brewer)

brewer—Brewer object.

Inverse of the above. This will remove the brewer from our set of brewers. It will alert every brew of its removal and create and send a Brewer Unregister Packet to the Pubkeeper server.

add_patron(topic, callback, crypto=True, patron_id=None)

topic—Topic to subscribe.
callback—Function to call when data is received.
crypto—Should data consumed by this patron be allowed to be ciphered with AES-CBC. Defaults to True
patron_id—ID of the brewer. If provided, it must be a 16 byte string. Defaults to uuid.uuid4().hex

This method will create and return a patron object. It will alert every brew of its existence and create and send a Patron Register Packet to the Pubkeeper server.

remove_patron(patron)

patron—Patron object

Inverse of the above. This will remove the patron from our set of patrons. It will alert every brew of its removal and create and send a Patron Unregister Packet to the Pubkeeper server.

results matching ""

    No results matching ""