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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for varpickler-0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a886bc308179cc1247f9c66e86bcc135fde539b57d302ea56f63e1326e736506 |
|
MD5 | 73f1c28641a5b85a9ad8c89f82a197aa |
|
BLAKE2b-256 | 6058f4211776b1bf47c90ea8c10f838fee5dbd2eb85130bf2adcf526a790d777 |