Pipeline#

Classes for building complex serializers from a sequence of stages.

SerializerPipeline

A pipeline of stages chained together to serialize and deserialize response objects.

Stage

A single stage in a serializer pipeline.

class requests_cache.serializers.pipeline.SerializerPipeline(stages, name=None, is_binary=False)[source]#

Bases: object

A pipeline of stages chained together to serialize and deserialize response objects.

Note: Typically, the first stage should be a CattrStage, since this does the majority of the non-format-specific work to unstructure a response object into a dict (and vice versa).

Parameters:
  • stages (Sequence) – A sequence of Stage objects, or any objects with dumps() and loads() methods

  • is_binary (bool) – Indicates whether the serialized content is binary

  • name (Optional[str]) –

dumps(value)[source]#
Return type:

Union[str, bytes]

loads(value)[source]#
Return type:

CachedResponse

set_decode_content(decode_content)[source]#

Set decode_content, if the pipeline contains a CattrStage or compatible object

Parameters:

decode_content (bool) –

class requests_cache.serializers.pipeline.Stage(obj=None, dumps='dumps', loads='loads')[source]#

Bases: object

A single stage in a serializer pipeline. This wraps serialization steps with consistent dumps() and loads() methods

Parameters:
  • obj (Any) – Serializer object or module, if applicable

  • dumps (Union[str, Callable]) – Serialization function, or name of method on obj

  • loads (Union[str, Callable]) – Deserialization function, or name of method on obj