oyaml is a drop-in replacement for PyYAML which preserves dict ordering. Both Python 2 and Python 3 are supported. Just pip install oyaml, and import as shown below:
import oyaml as yamlYou'll no longer be annoyed by screwed-up mappings when dumping/loading.