Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

YAML: Python's Missing Battery (Summary)

You now know where to find the missing battery in Python to read and write YAML documents. Along the way, you learned about the powerful and dangerous features found in this popular data format and how to take advantage of them with Python.

In this video course, you learned how to:

  • Read and write YAML documents in Python
  • Serialize Python’s built-in and custom data types to YAML
  • Safely read YAML documents from untrusted sources
  • Take control of parsing YAML documents at a lower-level

You also played around with The yaml document from hell by Ruud van Asseldonk.

If you’d like to continue learning, then check out:

Looking for more YAML-related libraries? Here you go:

You might also want to check out these online tools:

Download

Sample Code (ZIP)

9.3 KB
Download

Course Slides (PDF)

1.2 MB

00:00 In the previous lesson, I spoke of YAML tools besides PyYAML and probably made half the Internet angry. In this lesson, I’ll summarize the course and point you at other content you might find interesting. This course has been all about YAML, the text-based data format.

00:16 Python doesn’t have YAML parsing built into the standard library, so you’ll need a third-party library, the most popular of which is PyYAML, warts and all. The YAML format supports text, arrays, hashes, dates, integers, floats, Booleans, and is quite flexible when it comes to text.

00:34 There are multiple ways of specifying strings, including several variations on multiline formats. YAML allows reuse through inheritance style structures, including anchors, aliases, and attribute merging.

00:47 And the spec allows you to cast explicitly to certain data types using tags. And the PyYAML library has implemented custom tags that allow you to do crazy things directly to Python objects.

01:01 I mentioned that TOML thing as an alternative. If you’re interested, there is an article that you may find helpful. If you’d prefer to learn more about JSON, there’s content for that too.

01:12 Or if you want to learn how YAML is used in the DevOps world, this article shows you how to do Django deployments using Fabric and Ansible. Even if you’re not keen on Django, Fabric, or Ansible, it might be worthwhile to skim the last half of this article to see some examples of how YAML gets used in the DevOps space.

01:32 Well, that’s all I have to say about YAML. Thanks for your attention. I’ll leave you with one last tuber pun: this spud’s for you. Been a while since those commercials were on. That might be a dated reference.

01:45 I should say something clever about French fries instead. Something clever about French fries.

Become a Member to join the conversation.