class C(object):

    def __init__(self, i):
        self.i = i

def __getstate__(self):
    return {'i': self.i}
assert pickle.loads(pickle.dumps(C(1), -1)).i == 1
Simple example of use of __setstate__ and __getstate__