Skip to main content

pickle / unpickle variables

Project description

pickle / unpickle variables

Tested against Windows 10 / Python 3.10 / Anaconda

pip install varpickler

decode_var(obj: Any, pickle_or_dill: str = 'dill', base: str = 'base64', str_decode: str | None = None) -> Any
    Decode a Python object that was encoded using either the 'pickle' or 'dill' library,
    and then decode the baseXX encoded result.
    
    Parameters:
        obj (str or bytes): The encoded object to be decoded.
        pickle_or_dill (str, optional): The library to be used for decoding.
            Valid options are 'pickle' or 'dill'. Defaults to 'dill'.
        base (str, optional): The base encoding used in the encoded object.
            Defaults to 'base64'.
        str_decode (str, optional): The string encoding used after baseXX encoding.
            If None, no additional string decoding is performed. Defaults to None.
    
    Returns:
        object: The decoded object.
    
    Example:
        import numpy as np
        obj = np.array([23, 34, 4])
        a1 = encode_var(obj, pickle_or_dill="dill", base="base64", str_encode=None)
        a2 = encode_var(obj, pickle_or_dill="dill", base="base64", str_encode="utf-8")
        a3 = decode_var(a1, pickle_or_dill="dill", base="base64", str_decode=None)
        print(a3)
        a4 = decode_var(a2, pickle_or_dill="dill", base="base64", str_decode="utf-8")
        print(a4)
    
        [23 34  4]
        [23 34  4]
encode_var(obj: Any, pickle_or_dill: str = 'dill', base: str = 'base64', str_encode: str | None = None) -> str | bytes
        Encode a Python object using either the 'pickle' or 'dill' library, and then encode the result using baseXX encoding.
    
        Parameters:
            obj (object): The object to be encoded.
            pickle_or_dill (str, optional): The library to be used for encoding.
                Valid options are 'pickle' or 'dill'. Defaults to 'dill'.
            base (str, optional): The base encoding to be used.
                Defaults to 'base64'.
            str_encode (str, optional): The string encoding to be used after baseXX encoding.
                If None, no additional string encoding is performed. Defaults to None.
    
        Returns:
            str or bytes: The encoded object. If 'str_encode' is None, a bytes object is returned.
                Otherwise, a string object is returned.
    
        Example:
            obj = np.array([23, 34, 4])
            >>> a1 = encode_var(obj, pickle_or_dill="dill", base="base64", str_encode=None)
            >>> print(a1)
            b'gAWVtgAAAAAAAACMCmRpbGwuX2RpbGyUjA1fY3JlYXRlX2FycmF5lJOUKIwVbnVtcHkuY29yZS5t
    dWx0aWFycmF5lIwMX3JlY29uc3RydWN0lJOUjAVudW1weZSMB25kYXJyYXmUk5RLAIWUQwFilIeU
    KEsBSwOFlGgGjAVkdHlwZZSTlIwCaTSUiYiHlFKUKEsDjAE8lE5OTkr/////Sv////9LAHSUYolD
    DBcAAAAiAAAABAAAAJR0lE50lFKULg==
    '
    
            >>> a2 = encode_var(obj, pickle_or_dill="dill", base="base64", str_encode="utf-8")
            >>> print(a2)
            'gAWVtgAAAAAAAACMCmRpbGwuX2RpbGyUjA1fY3JlYXRlX2FycmF5lJOUKIwVbnVtcHkuY29yZS5t
            dWx0aWFycmF5lIwMX3JlY29uc3RydWN0lJOUjAVudW1weZSMB25kYXJyYXmUk5RLAIWUQwFilIeU
            KEsBSwOFlGgGjAVkdHlwZZSTlIwCaTSUiYiHlFKUKEsDjAE8lE5OTkr/////Sv////9LAHSUYolD
            DBcAAAAiAAAABAAAAJR0lE50lFKULg=='

	

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

varpickler-0.10.tar.gz (5.0 kB view hashes)

Uploaded Source

Built Distribution

varpickler-0.10-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page