Skip to main content

dumps

Return URL-safe, hmac signed base64 compressed JSON string. If key is None, use settings.SECRET_KEY instead. The hmac algorithm is the default Signer algorithm.

If compress is True (not the default), check if compressing using zlib can
save some space. Prepend a '.' to signify compression. This is included
in the signature, to protect against zip bombs.

Salt can be used to namespace the hash, so that a signed string is
only valid for a given namespace. Leaving this at the default
value or re-using a salt value across different parts of your
application without good cause is a security risk.

The serializer is expected to return a bytestring.
def dumps(
obj: Any,
key: string = None,
salt: string = django.core.signing,
serializer: class = JSONSerializer,
compress: boolean = False
) - > string

Return URL-safe, hmac signed base64 compressed JSON string. If key is None, use settings.SECRET_KEY instead. The hmac algorithm is the default Signer algorithm.

Parameters

NameTypeDescription
objAnyThe Python object to be serialized and signed.
keystring = NoneThe secret key used to generate the HMAC signature; defaults to settings.SECRET_KEY if not provided.
saltstring = django.core.signingA string used to namespace the hash, ensuring the signed string is only valid within a specific context to prevent signature reuse.
serializerclass = JSONSerializerA serializer class responsible for converting the object into a bytestring before signing.
compressboolean = FalseIf True, attempts to reduce the output size using zlib compression and prepends a '.' to the result.

Returns

TypeDescription
stringA URL-safe, signed, and optionally compressed base64 string representing the serialized object.