types
Types shared across Pipecat, independent of any provider SDK.
The NOT_GIVEN sentinel lives here so that settings, contexts and anything
else needing “this value was not provided” share one meaning. Provider SDKs
ship their own equivalents; those belong to the SDK and are translated at the
adapter boundary rather than used inside Pipecat.
- class pipecat.utils.types.NotGiven[source]
Bases:
objectSentinel type meaning “this value was not provided”.
Distinct from
None, which is a meaningful value in most of the places this is used (typically “this service doesn’t support this field”).NOT_GIVENis the singleton instance; test for it withis_given()rather than comparing directly.Falsy, so
value or defaulttreats a missing value as absent.
- pipecat.utils.types.NOT_GIVEN: NotGiven = NOT_GIVEN
Singleton sentinel meaning “this value was not provided”.
- pipecat.utils.types.is_given(value: _T | NotGiven) TypeGuard[_T][source]
Check whether a value was explicitly provided.
Also acts as a type guard: inside a true branch, the value is narrowed to exclude
NotGiven(e.g.str | None | NotGivenbecomesstr | None):if is_given(delta.voice): # caller wants to change the voice ...
- Parameters:
value – The value to check.
- Returns:
Trueif value is anything other thanNOT_GIVEN.
- pipecat.utils.types.assert_given(value: _T | NotGiven) _T[source]
Extract a value that must have been provided.
Intended for reads where
NOT_GIVENshould never appear, such as a store-mode settings object (seepipecat.services.settings). Narrows awayNotGivenat the type level and raises at runtime if that invariant is violated:resolved_model = assert_given(self._settings.model) # narrowed str | None
- Parameters:
value – The value to extract.
- Returns:
The value, narrowed to exclude
NotGiven.- Raises:
RuntimeError – If value is
NOT_GIVEN.
- pipecat.utils.types.require_given(value: _T | None | NotGiven, what: str) _T[source]
Extract a value that must have been provided and must not be empty.
Like
assert_given(), but also rejectsNoneand the empty string, which is what an unset or blank environment variable produces. Use it for settings a service cannot work without, such as a local model or voice that no provider will validate on its behalf:voice = require_given(self._settings.voice, "Piper TTS voice") # narrowed str
- Parameters:
value – The value to extract.
what – How to name the value in the error, e.g.
"Piper TTS voice".
- Returns:
The value, narrowed to exclude
NotGivenandNone.- Raises:
RuntimeError – If value is
NOT_GIVEN.ValueError – If value is
Noneor an empty string.