pipecat.utility module¶
Convenience functions for working with data sources.
-
pipecat.utility.
add_field
(source, key, value)¶ Adds a key-value pair to every record returned from a source.
Parameters: - source (Record generator, required)
- key (Record key, required)
- value (any value.)
Yields: record (dict) – Input records containing an additional field key with value value.
-
pipecat.utility.
add_timestamp
(source, key='timestamp')¶ Add a timestamp to every record returned from a source.
Parameters: - source (Record generator, required)
- key (Record key, optional)
Yields: record (dict) – Input records containing an additional field key with a
arrow.arrow.Arrow
UTC timestamp value.
-
pipecat.utility.
extract_quantities
(source, value='value', units='units')¶ Convert values with separate magnitude / units data into
pipecat.quantity
instances.If a field value is a dict containing value and units keys, it will be replaced with a matching
pipecat.quantity
.Parameters: - source (Record generator, required)
- value (Record key, optional)
- units (Record key, optional)
Yields: record (dict) – Input records with field values converted to
pipecat.quantity
instances.
-
pipecat.utility.
promote_field
(source, key)¶ Promote key-value pairs from one field into their own fields.
The field key must exist and contain a dict or dict-like object.
Parameters: - source (Record generator, required)
- key (Record key, required)
Yields: record (dict) – Input records containing additional fields promoted from the value stored in key.
-
pipecat.utility.
readline
(fobj, encoding='utf-8')¶ Extract lines from a file or file-like object.
Parameters: fobj (file-like object, required) – This could be an open file, instance of io.StringIO
, a serial connection, or any other object from which lines of text can be read.Yields: record (dict) – Records containing a “string” field that stores one line of text.
-
pipecat.utility.
remove_field
(source, key)¶ Removes a key-value pair from every record returned by a source.
Records that don’t contain key are returned unmodified (this is not an error condition).
Parameters: - source (Record generator, required)
- key (Record key, required) – The field to be removed.
Yields: record (dict) – Input records with the key field removed.
-
pipecat.utility.
split_keys
(source, delimiter)¶ Convert flat keys into hierarchical keys using a delimiter.
This is useful working with data such as JSON that can’t represent hierarchical keys explicitly.
Parameters: - source (Record generator, required)
- delimiter (str, required)
Yields: record (dict) – Input records with keys containing the delimiter converted into hierarchical keys.
-
pipecat.utility.
trace
(source, name=None)¶ Log the behavior of a source for debugging.
Use
pipecat.utility.trace()
to log the behavior of another record generator, including the records it generates, any exceptions thrown, and notifications when it starts and finishes. Records are passed through this function unmodified, so it can be inserted into an existing pipe without altering its behavior.Parameters: source (Record generator, required) Yields: record (dict) – Unmodified input records.