class Document(object):

    def __init__(self, name):
        self.name = name
self.otherstuff = 'blah'

def __getstate__(self):
    d = OrderedDict()
d['name'] = self.name
d['otherstuff'] = self.otherstuff
return d
dump_anydict_as_map(Document)
doc = Document('obj-20111227')
print(yaml.dump(doc, indent=4))
Controlling Yaml Serialization Order in Python