requests_cache.serializers package

class requests_cache.serializers.CattrStage(factory=None)[source]

Bases: requests_cache.serializers.pipeline.Stage

Base serializer class for CachedResponse that does pre/post-processing with cattrs. This does the majority of the work needed for any other serialization format, breaking down objects into python builtin types.

This can be used as a stage within a SerializerPipeline. Requires python 3.7+.

dumps(value)[source]
Return type

Dict

loads(value)[source]
Return type

CachedResponse

class requests_cache.serializers.SerializerPipeline(steps)[source]

Bases: object

A sequence of steps used to serialize and deserialize response objects

dumps(value)[source]
Return type

Union[str, bytes]

loads(value)[source]
Return type

CachedResponse

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

Bases: object

Generic class to wrap serialization steps with consistent dumps() and loads() methods

requests_cache.serializers.init_serializer(serializer=None, **kwargs)[source]

Initialize a serializer from a name, class, or instance

requests_cache.serializers.safe_pickle_serializer(secret_key=None, salt='requests-cache', **kwargs)[source]

Create a serializer that uses itsdangerous to add a signature to responses during writes, and validate that signature with a secret key during reads.

Submodules

requests_cache.serializers.cattrs module

class requests_cache.serializers.cattrs.CattrStage(factory=None)[source]

Bases: requests_cache.serializers.pipeline.Stage

Base serializer class for CachedResponse that does pre/post-processing with cattrs. This does the majority of the work needed for any other serialization format, breaking down objects into python builtin types.

This can be used as a stage within a SerializerPipeline. Requires python 3.7+.

dumps(value)[source]
Return type

Dict

loads(value)[source]
Return type

CachedResponse

requests_cache.serializers.cattrs.init_converter(factory=None)[source]

Make a converter to structure and unstructure nested objects within a CachedResponse

requests_cache.serializers.cattrs.to_datetime(obj, cls)[source]
Return type

datetime

requests_cache.serializers.cattrs.to_timedelta(obj, cls)[source]
Return type

timedelta

requests_cache.serializers.pipeline module

class requests_cache.serializers.pipeline.SerializerPipeline(steps)[source]

Bases: object

A sequence of steps used to serialize and deserialize response objects

dumps(value)[source]
Return type

Union[str, bytes]

loads(value)[source]
Return type

CachedResponse

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

Bases: object

Generic class to wrap serialization steps with consistent dumps() and loads() methods

requests_cache.serializers.preconf module

The cattrs library includes a number of pre-configured converters that perform some additional steps required for specific serialization formats.

This module wraps those converters as serializer Stage objects. These are then used as a stage in a SerializerPipeline, which runs after the base converter and before the format’s dumps() (or equivalent) method.

For any optional libraries that aren’t installed, the corresponding serializer will be a placeholder class that raises an ImportError at initialization time instead of at import time.

Requires python 3.7+.

requests_cache.serializers.preconf.safe_pickle_serializer(secret_key=None, salt='requests-cache', **kwargs)[source]

Create a serializer that uses itsdangerous to add a signature to responses during writes, and validate that signature with a secret key during reads.

requests_cache.serializers.preconf.signer_stage(secret_key=None, salt='requests-cache')[source]