pickle.dumps()
pickle.dumps() is a Python function in the Pickle Module category. Serializes a Python object to bytes (instead of file). The syntax is pickle.dumps(obj, protocol=None, *, fix_imports=True). Parameters: obj — Python object. Returns: Bytes. A typical example: data = pickle.dumps({"key": [1,2,3]})
type(data) # bytes. A close sibling is pickle.dump(), which serializes a Python object and writes it to a file. A close sibling is pickle.load(), which deserializes a Python object from a pickle file. A close sibling is pickle.loads(), which deserializes a Python object from bytes (instead of file). A close sibling is pickle.HIGHEST_PROTOCOL, which an integer representing the highest available pickle protocol version. More about this category: Python object serialization — dump, load, dumps, loads, protocols. For a broader walkthrough, read the Pickle Module guide. Related Pickle Module entries: pickle.dump(), pickle.load(), pickle.loads(), pickle.HIGHEST_PROTOCOL. This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.