qbss_client module

class qbss.proxy.qbss_client.QbssBlockState(value)

Bases: Enum

Enums for the ‘block_state’ field in qbss_get_block().

AVAILABLE = 'AVAILABLE'
ERROR_FETCHING_TIMEOUT = 'ERROR_FETCHING_TIMEOUT'
ERROR_MAX_RETRIES = 'ERROR_MAX_RETRIES'
ERROR_NONEXISTENT = 'ERROR_NONEXISTENT'
ERROR_STREAM = 'ERROR_STREAM '
ERROR_UNKNOWN = 'ERROR_UNKNOWN'
FETCHING = 'FETCHING'
PUBLISHING = 'PUBLISHING'
UNAVAIALBLE = 'UNAVAIALBLE'
WAITING = 'WAITING'
class qbss.proxy.qbss_client.QbssClient(hostname, port)

Bases: object

Python API client to wrap the QBSS WebSocket interface. You must connect to the server before you can start using the client:

python
  client = QbssClient('localhost', 8011)
  await client.connect()
  # ... do stuff ...
  await client.close()

You can use a client as a context to automatically connect/close:

python
  async with QbssClient('localhost', 8011) as client:
      # ... do stuff ...

Note that several client functions can take or return some of the enum class types also included in this file.

Parameters:
  • hostname (str) – The string address of the host to connect the client to.

  • port (int) – The port to connect the client to.

async close()

Close the client, if it is connected.

async connect()

Connect the client to the remote.

Returns:

self

async get_block(stream_id, block_id)

Gets a block from the server. Fails if the block doesn’t exist.

Parameters:
  • stream_id (str) – A string containing the hex UUID of the stream

  • block_id (int) – The ID, or number, of the block

Returns:

A tuple containing the block’s data (or [0] if no data was returned), the block’s state, and the status of the operation

Return type:

tuple(bytes, QbssBlockState, QbssStatus)

async get_dsp()

Gets the DSP (dom, sn, pipe) value of the server this client is connected to.

Returns:

A tuple of (dom, sn, pipe)

Return type:

tuple(int, int, int)

async manage_stream(stream_id, stream_action, note='')

Manage QBSS stream information, using the provided stream_action, for the given stream_id.

The stream actions do the following:

  • QbssStreamAction.CREATE: Create a new stream with the given stream_id. If no ID is given, a random UUID will be returned.

  • QbssStreamAction.FINISH: Mark a stream as completed, with no new blocks to be published.

  • QbssStreamAction.DELETE: Delete a stream and purge all blocks related to it from the cache.

  • QbssStreamAction.SUBSCRIBE: Have the server subscribe to a stream, receiving updates on its status.

  • QbssStreamAction.SET_NOTE: Set the note, in text, for a stream. The note kwarg must be set.

  • QbssStreamAction.GET_NOTE: Get the note, in text, for a stream. This will be in the ripc return value as "note".

  • QbssStreamAction.GET_INFO: Get the info for a stream. The ripc value returned for this action will contain many different values about the stream. For more info, see _ipc_structs.h.

  • QbssStreamAction.INFO_ALL: Get the info for all streams the server knows about. This will be in the ripc return value as "stream_info".

Parameters:
  • stream_id (str) – A string containing the hex UUID of the stream

  • stream_action (QbssStreamAction) – The action to perform on the stream.

  • note (str, optional) – The note to set on a string for SET_NOTE.

Returns:

A tuple containing the status of the operation, and the raw ripc dict returned by the server. The ripc will either contain the stream ID, action, status on what was performed, and any additional values, or it will contain information on a stream in the case of GET_INFO.

Return type:

tuple(QbssStatus, dict)

async ping(misc_value=123)

Pings the server with a value. The same value is (or should be) returned back.

Parameters:

misc_value (int, optional) – The value to send to the server.

Returns:

The value sent back by the server.

Return type:

int

async publish_block(stream_id, block_id, block_data)

Publishes a block to the server. Fails if the block already exists at the server.

Parameters:
  • stream_id (str) – A string containing the hex UUID of the stream

  • block_id (int) – The ID, or number, of the block

  • block_data (bytes) – The block’s raw data

Returns:

A QbssStatus enum indicating the result of the publish operation

Return type:

QbssStatus

async set_storage_limit(storage_limit_mb)

Sets the storage limit of the block cache at the server, in megabytes.

Parameters:

storage_limit_mb – The desired storage limit, in megabytes.

Rtype storage_limit_mb:

int

Returns:

The status indicating the result of the operation.

Return type:

QbssStatus

class qbss.proxy.qbss_client.QbssStatus(value)

Bases: Enum

Enums for ‘status’ fields in QBSS IPCs. These are returned by relevant client functions.

ALREADY_EXISTS = 'ALREADY_EXISTS'
CONTROLLER_ERR = 'CONTROLLER_ERR'
MALFORMED_ERR = 'MALFORMED_ERR'
MISC_ERR = 'MISC_ERR'
OKAY = 'OKAY'
TOO_LARGE = 'TOO_LARGE'
UNKNOWN_KEY = 'UNKNOWN_KEY'
class qbss.proxy.qbss_client.QbssStreamAction(value)

Bases: Enum

Enums for the ‘stream_action’ field in qbss_manage_stream().

CREATE = 'CREATE'
DELETE = 'DELETE'
FINISH = 'FINISH'
GET_INFO = 'GET_INFO'
GET_NOTE = 'GET_NOTE'
INFO_ALL = 'INFO_ALL'
SET_NOTE = 'SET_NOTE'
SUBSCRIBE = 'SUBSCRIBE'