PYnative

Python Programming

  • Learn Python
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Exercises
    • Python Exercises
    • C Programming Exercises
    • C++ Exercises
  • Quizzes
  • Code Editor
    • Online Python Code Editor
    • Online C Compiler
    • Online C++ Compiler
Home » Python » Python YAML

Python YAML

Updated on: April 5, 2021 | 4 Comments

This tutorial will teach how to work with YMAL data in Python using a PyYAML Module.

After reading this tutorial, you will learn:

  • The YAML data format
  • How to read and write YAML files in Python using a PyYAML Module.
  • How to work with Python’s PyPYML module to serialize the data in your programs into YAML format.
  • Deserialize YAML stream and convert it into Python objects
  • Convert a YAML file to the other commonly used formats like JSON and XML.

Table of contents

  • What is YAML?
    • YAML File
    • Advantages of YAML
  • PyYAML Module
    • Installing PyYAML
  • Python YAML Load – Read YAML File
    • Loading Multiple YAML Documents Using load_all()
    • Loading a YAML Document Safely Using safe_load()
  • Python YAML Dump – Write into YAML File
    • Dump Multiple YAML Documents
    • Python YAML sorting keys
    • Pretty Print YAML File
  • Make Custom Python Class YAML Serializable
  • Simple Application using PyYAML
  • Custom Tags with PyYAML
  • YAML Errors
  • Tokens
  • Python YAML to JSON
  • Python YAML to XML

What is YAML?

YAML acronym for Ain’t Markup Language. YAML is a human-friendly data serialization standard for all programming languages. I.e., It is widely used to store data in a serialized format.

It is in simple human-readable format makes which makes it suitable for the Configuration files.

The YAML data format is a superset of one more widely used Markup language called JSON (JavaScript Object Notation).