API References

pypickle is to save and load variables in/from pickle files.

pypickle.pypickle.clean(filename: str) str

Clean the filename to make sure the file can be saved on disk.

Description

The following characters are replaced from the filename: ‘&’, ‘,’, ‘?’, ‘$’, ‘!’ ‘/’, ‘’ with character: ‘_’

param filename

Filename.

type filename

str

returns

TYPE – filename

rtype

str

Example

>>> import pypickle
>>> filename = 't/st.pkl'
>>> data = [1,2,3,4,5]
>>> filename = pypickle.clean(filename)
>>> # Save
>>> status = pypickle.save(filename, data)
>>> # Load file
>>> data = pypickle.load(filepath)
pypickle.pypickle.load(filepath: str, fix_imports: bool = True, encoding: str = 'ASCII', errors: str = 'strict', verbose: int = 3)

Load pickle files for input variables.

Parameters
  • filepath (str) – Pathname to store pickle files.

  • fix_imports (bool, (default=True)) – fix_imports are used for compatibility support for pickle stream generated by Python 2. If fix_imports is true, pickle will try to map the old Python 2 names to the new names used in Python 3.

  • encoding (str, (default: "ASCII")) – encoding tell pickle how to decode 8-bit string instances pickled by Python 2. The encoding can be “bytes” to read these 8-bit string instances as bytes objects. Using encoding=”latin1” is required for unpickling NumPy arrays and instances of datetime, date and time pickled by Python 2.

  • errors (str, (default: "strict")) – errors tell pickle how to decode 8-bit string instances pickled by Python 2.

  • verbose (int, optional) – Show message. A higher number gives more informatie. The default is 3.

Returns

Status of succes

Return type

bool [True,False].

Example

>>> import pypickle
>>> filepath = 'test.pkl'
>>> data = [1,2,3,4,5]
>>> status = pypickle.save(filepath, data)
>>> # Load file
>>> data = pypickle.load(filepath)
pypickle.pypickle.save(filepath: str, var, overwrite: bool = False, fix_imports: bool = True, verbose: int = 3)

Save pickle file for input variables.

Parameters
  • filepath (str) – Pathname to store pickle files.

  • var ({list, object, dataframe, etc}) – Name of list or dict or anything else that needs to be stored.

  • fix_imports (bool, (default=True)) – fix_imports are used for compatibility support for pickle stream generated by Python 2. If fix_imports is true, pickle will try to map the old Python 2 names to the new names used in Python 3.

  • overwrite (bool, (default=False)) – Overwite file if exists.

  • verbose (int, optional) – Show message. A higher number gives more informatie. The default is 3.

Returns

Status of succes

Return type

bool [True,False].

Example

>>> import pypickle
>>> filepath = './temp/test.pkl'
>>> data = [1,2,3,4,5]
>>> status = pypickle.save(filepath, data)