YAML: Python's Missing Battery (Overview)
Python is often marketed as a batteries-included language because it comes with almost everything you’d ever expect from a programming language. This statement is mostly true, as the standard library and the external modules cover a broad spectrum of programming needs. However, Python lacks built-in support for the YAML data format, commonly used for configuration and serialization.
In this video course, you’ll learn how to work with YAML in Python using the available third-party libraries, with a focus on PyYAML. If you’re new to YAML or haven’t used it in a while, then you’ll have a chance to take a quick crash course before diving deeper into the topic.
In this video course, you’ll learn 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
Notably, you’ll learn about YAML’s advanced, potentially dangerous features and how to protect yourself from them.
00:00 Welcome to YAML: Python’s Missing Battery. My name is Christopher, and I will be your guide. In this course, you’ll learn all about YAML, including its format and content, the PyYAML third-party Python library, details on reading YAML into your program as well as spitting it out, abd why YAML may cause you to pull out your hair.
00:24 Code in this course was tested using Python 3.11.1 and PyYAML 6. Note that there are two common versions of the YAML spec, and PyYAML still works with the older version, 1.1.
00:36 YAML and PyYAML have been around forever, so as long as you get your version of Python to work with your version of PyYAML, you shouldn’t have a problem with anything you see in this course.
00:47 YAML is a common text-based data format that is used for similar things that XML and JSON might be used for. It’s human-readable and, like Python, uses white space and indentation to demark groups of things.
01:01 It supports a wide variety of data types and has reuse mechanisms built in. YAML is quite common in the DevOps space, used to specify access rules and configurations for containers and cloud things.
01:15 Handling YAML is somewhat surprisingly not included as part of the Python standard library, but there are third-party libraries out there for dealing with it, the most popular of which, I’ll be covering in this course, is PyYAML.
01:30 Next up, I’ll dive into YAML and get you started with reading some simple YAML in Python.
Become a Member to join the conversation.