import pickle myobj = MyObj() # save obj to file with open('myfile.pkl', 'wb') as f: pickle.dump(myobj, f) # read obj from file with open('myfile.pkl', 'wb') as f: obj = pickle.load(f)