Skip to main content

10 posts tagged with "YAML"

YAML Syntax for Settings and Configuration Files, and How Python Reads It

View All Tags

How to Validate a YAML Settings File in Python with pydantic

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

A settings file is only as good as the values in it. A port typed as 80800 or a setting written as maybe should stop the program when it starts, with a message that names the setting, not crash it later somewhere else. Loading the YAML with PyYAML and checking it with pydantic models does exactly that. This guide builds it with pydantic 2.14.4 and PyYAML 6.0.4 on Python 3.15.2.

How to Write a Number in YAML

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Numbers in YAML need no quotes: gears: 7 is a whole number and price: 449.99 a decimal. A few forms surprise people, though, because PyYAML follows the older YAML 1.1 rules: a leading zero makes a number octal, and 1e3 without a dot stays text. This guide writes numbers and checks each one with Python.

How to Write true and false in YAML

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

A YAML setting that's on or off is written true or false. In PyYAML, which follows YAML 1.1, a whole list of other words count too: yes, no, on, off. So a country code NO, for Norway, quietly becomes False. This guide writes booleans and checks them with Python.

How to Write a Date in YAML

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

A date written as 2026-03-14 in a YAML file isn't just text: PyYAML loads it as a real Python date, ready to compare and calculate with. Add a time and it becomes a date and time. This guide writes both, checks them with Python, and shows the forms that don't become dates.

How to Write a Key and a Value in YAML

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

YAML files are made of key-value pairs: a name, a colon, a space and the value, such as city: Leeds. A set of them is called a mapping, and programs read it as a dictionary. This guide writes two pairs, checks them with Python, and shows what four small mistakes really do.

How to Nest Settings Inside Other Settings in YAML

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Settings that belong together go under one parent key in YAML, indented below it: a store's name and its address, and inside the address, the city and the postcode. The indentation is the structure, so it has to be even. This guide nests two levels deep and checks the result with Python.

How to Write a Comment in YAML

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

A comment explains a setting to the next person who reads the file, and programs ignore it. In YAML, a comment starts with #, either on its own line or after a value. The same # catches people out when a value starts with it, such as a colour code. This guide writes both kinds and checks them with Python.

How to Write a String in YAML

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Most YAML text needs no quotes: name: Bike shop is already a string. But some words and numbers mean something else to YAML, so yes becomes true and 3.10 becomes a number. This guide writes strings three ways, then shows which values need quotes, checked with Python.