0

I'm using django and django-rest-framework.

I have a YAML file that represents a database. Every object has an id and data.

I want to be able to use the data as a resource in drf. I don't need to create new objects and save them, I just need to read it.

Am I supposed to use fixtures for this? Or is there a better way.

vstumpf
  • 7
  • 2
  • 4

1 Answers1

0

Link here but I'll post the answer for laziness. How can I parse a YAML file in Python

The easiest and purest method without relying on C headers is PyYaml (documentation):

#!/usr/bin/env python

import yaml

with open("example.yaml", 'r') as stream:
    try:
        print(yaml.safe_load(stream))
    except yaml.YAMLError as exc:
        print(exc)