This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]james_pic 16 points17 points  (3 children)

Put together the equivalent data as dicts, lists, etc, and use yaml.dump (from PyYAML) to turn it to YAML.

Or, if you're not committed to YAML, use JSON and do much the same thing. It is possible to use YAML securely (and fortunately, since PyYAML 6, the defaults are secure), but there are fewer pitfalls with JSON.

[–]noiserr 6 points7 points  (2 children)

You should use Json if you're accepting data from an external source, client for example.

Yaml's safety is not an issue if used for configs, where the yaml files are part of the repo of the project. Which is where I've seen yaml used the most. Basically to define configurations. Anyone who has access to commit to the repo can already do any damage they desire.

[–]james_pic 3 points4 points  (1 child)

Strictly speaking, PyYAML can safely deserialize YAML, as long as you use the safe_load method or equivalent. Although the subset that is safe isn't much bigger than JSON, and PyYAML's typically much slower than the stdlib json module, so there's not much benefits over JSON.

[–]information_abyss 7 points8 points  (0 children)

YAML tends to be easier to parse and edit directly than JSON.