File: _pickle_api.py

package info (click to toggle)
python-srsly 2.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,256 kB
  • sloc: python: 17,567; ansic: 1,434; sh: 12; makefile: 6
file content (23 lines) | stat: -rw-r--r-- 624 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from typing import Optional

import cloudpickle
from .util import JSONInput, JSONOutput


def pickle_dumps(data: JSONInput, protocol: Optional[int] = None) -> bytes:
    """Serialize a Python object with pickle.

    data: The object to serialize.
    protocol (int): Protocol to use. -1 for highest.
    RETURNS (bytes): The serialized object.
    """
    return cloudpickle.dumps(data, protocol=protocol)


def pickle_loads(data: bytes) -> JSONOutput:
    """Deserialize bytes with pickle.

    data (bytes): The data to deserialize.
    RETURNS: The deserialized Python object.
    """
    return cloudpickle.loads(data)