HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
crdoconnor
strictyaml
Python2016–2025
crdoconnor / strictyaml

strictyaml

Type-safe YAML parser and validator.

25Distinct people
41Mentions
1Explicit recommenders
1.6KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Type-safe YAML parser and validator.

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

I love the example at https://github.com/crdoconnor/strictyaml/blob/master/FAQ.rst.... Convinced in 2 seconds that full YAML is idiotic.

akkartik used a recommendation phrase. One indexed comment matches. This is a phrase match, not a verdict.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 8–Nov 15 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/15/2026, 4:01:40 AM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year41 dated mentions

Observed mentions: 2016-08-01 10:26:16 UTC to 2025-08-09 14:14:43 UTC.

02462016-01-01 00:00:00 UTC to 2017-01-01 00:00:00 UTC (exclusive): 7 mentions; 0 submissions, 7 comments20162017-01-01 00:00:00 UTC to 2018-01-01 00:00:00 UTC (exclusive): 7 mentions; 1 submissions, 6 comments2018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 7 mentions; 1 submissions, 6 comments2019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments2020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments20202021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 4 mentions; 0 submissions, 4 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 5 mentions; 0 submissions, 5 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2025

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20162016-01-01 00:00:00 UTC2017-01-01 00:00:00 UTC707
20172017-01-01 00:00:00 UTC2018-01-01 00:00:00 UTC716
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC716
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC303
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC303
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC202
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC404
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC505
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC101
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC202

From the project README

An excerpt from the repository, fetched Nov 13, 2026.

Read the project’s introduction
StrictYAML StrictYAML is a type-safe YAML parser that parses and validates a restricted subset of the YAML specification. Priorities: Beautiful API Refusing to parse the ugly, hard to read and insecure features of YAML like the Norway problem. Strict validation of markup and straightforward type casting. Clear, readable exceptions with code snippets and line numbers. Acting as a near-drop in replacement for pyyaml, ruamel.yaml or poyo. Ability to read in YAML, make changes and write it out again with comments preserved. Not speed, currently. Simple example: # All about the character name: Ford Prefect age: 42 possessions: - Towel from strictyaml import load, Map, Str, Int, Seq, YAMLError Default parse result: >>> load(yaml_snippet) YAML({'name': 'Ford Prefect', 'age': '42', 'possessions': ['Towel']}) All data is string, list or OrderedDict: >>> load(yaml_snippet).data {'name': 'Ford Prefect', 'age': '42', 'possessions': ['Towel']} Quickstart with schema: from strictyaml import load, Map, Str, Int, Seq, YAMLError schema = Map({"name": Str(), "age": Int(), "possessions": Seq(Str())}) 42 is now parsed as an integer: >>> person = load(yaml_snippet, schema) >>> person.data {'name': 'Ford Prefect', 'age': 42, 'possessions': ['Towel']} A YAMLError will be raised if there are syntactic problems, violations of your schema or use of disallowed YAML features: # All about the character name: Ford Prefect age: 42 For example, a schema violation: try: person = load(yaml_snippet, schema) except YAMLError as error: print(error) while parsing a mapping in "<unicode string>", line 1, column 1: # All about the character ^ (line: 1) required key(s) 'possessions' not found in "<unicode string>", line 3, column 1: age: '42' ^ (line: 3) If parsed correctly: from strictyaml import load, Map, Str, Int, Seq, YAMLError, as_document schema = Map({"name": Str(), "age": Int(), "possessions": Seq(Str())}) You can modify values and write out the YAML with comments preserved: person = load(yaml_snippet, schema) person['age'] = 43 print(person.as_yaml()) # All about the character name: Ford Prefect age: 43 possessions: - Towel As well as look up line numbers: >>> person = load(yaml_snippet, schema) >>> person['possessions'][0].start_line 5 And construct YAML documents from dicts or lists: print(as_document({"x": 1}).as_yaml()) x: 1 Install $ pip install strictyaml Why StrictYAML? There are a number of formats and approaches that can achieve more or less the same purpose as StrictYAML. I've tried to make it the best one. Below is a series of documented justifications: Why avoid using environment variables as configuration? Why not use HJSON? Why not HOCON? Why not use INI files? Why not use JSON Schema for validation? Why not JSON for simple configuration files? Why not JSON5? Why not use the YAML 1.2 standard? - we don't need a new standard! Why not use kwalify with standard YAML to validate my YAML? Why not use Python's schema library (or similar) for validation? Why not use SDLang? What is wrong with TOML? Why shouldn't I just use Python code for configuration? Why not use XML for configuration or DSLs? Using StrictYAML How to: Build a YAML document from scratch in code Either/or schema validation of different, equally valid different kinds of YAML Labeling exceptions Merge YAML documents Revalidate an already validated document Reading in YAML, editing it and writing it back out Get line numbers of YAML elements Parsing YAML without a schema Compound validators: Fixed length sequences (FixedSeq) Mappings combining defined and undefined keys (MapCombined) Mappings with arbitrary key names (MapPattern) Mapping with defined keys and a custom key validator (Map) Using a YAML object of a parsed mapping Mappings with defined keys (Map) Optional keys with defaults (Map/Optional) Validating optional keys in mappings (Map) Sequences of unique items (UniqueSeq) Sequence/list validator (Seq) Updating document with a schema Scalar validators: Boolean (Bool) Parsing comma separated items (CommaSeparated) Datetimes (Datetime) Decimal numbers (Decimal) Email and URL validators Empty key validation Enumerated scalars (Enum) Floating point numbers (Float) Hexadecimal Integers (HexInt) Integers (Int) Validating strings with regexes (Regex) Parsing strings (Str) Restrictions: Disallowed YAML Duplicate keys Dirty load Design justifications There are some design decisions in StrictYAML which are controversial and/or not obvious. Those are documented here: What is wrong with duplicate keys? What is wrong with explicit tags? What is wrong with flow-style YAML? The Norway Problem - why StrictYAML refuses to do implicit typing and so should you What is wrong with node anchors and references? Why does StrictYAML not parse direct representations of Python objects? Why does StrictYAML only parse from strings and not files? Why is parsing speed not a high priority for StrictYAML? What is syntax typing? Why does StrictYAML make you define a schema in Python - a Turing-complete language? Star Contributors @wwoods @chrisburr @jnichols0 Other Contributors @eulores @WaltWoods @ChristopherGS @gvx @AlexandreDecan @lots0logs @tobbez @jaredsampson @BoboTIG StrictYAML also includes code from ruamel.yaml, Copyright Anthon van der Neut. Contributing Before writing any code, please read the tutorial on contributing to hitchdev libraries. Before writing any code, if you're proposing a new feature, please raise it on github. If it's an existing feature / bug, please comment and briefly describe how you're going to implement it. All code needs to come accompanied with a story that exercises it or a modification to an existing story. This is used both to test the code and build the documentation.
Read the full README on GitHub

What Hacker News says

7 sources
This is kind of what I have been doing with this testing framework: https://github.com/hitchdev/hitchstory It's designed so that you can write tests that are the basis of the "how to" documentation - with a small script and some jinja2 you can generate readable documentation in the form of markdown from the test: Original test (behavioral example) : https://github.com/crdoconnor/strictyaml/blob/master/hitch/s... Example docs generated from that test : https://hitchdev.com/strictyaml/using/alpha/scalar/email-and... It's also designed so that the testing framework can be programmed to rewrite the test automatically for simple code changes (e.g. changing the wording of that exception). This makes building tests much quicker and much, much less tedious and perfectly in sync docs almost becomes a side effect. Essentially "how to" documentation
Read the rest
and example driven behavioral tests are the same thing for all projects. It's just that most people don't realize and don't treat them as such.
In Etsy’s experiment with immutable documentation
>YAML is complex and could use a hair cut. Out of curiosity, did you see the parser linked to at the end of the article? ( https://github.com/crdoconnor/strictyaml ) That was my attempt at giving YAML a haircut. I'd be curious to know what you thought. Thank you for creating YAML, by the way. Even though part of that rant was quoted from me, I'm not negative on it like the author - I think the core was brilliantly designed. If you put two hierarchical documents side by side - one in TOML and another in YAML the YAML one is much, much clearer and cleaner.
In YAML: probably not so great after all (2017)
I actually wrote a YAML parser that closed this loophole by raising an exception on YAML files that have inconsistent indents. Somebody reported exactly that as an issue on my issue tracker: https://github.com/crdoconnor/strictyaml/issues/23 I'm aware that there are a bunch of annoyances like that, but I'm still convinced the core is good and making a new standard which is stricter solves most of these issues. FWIW, I haven't run into this problem personally but it's pretty obvious that it is a problem.
In S-Expressions (1997)
Since you're using python and you're trying to store configuration style data in something that you might want a non-programmer to maintain, might I suggest storing the data as YAML and parsing with my library? https://github.com/crdoconnor/strictyaml I wrote it partly to make it easier for non-programmers to maintain structured data - which seems to be your use case. YAML is cleaner and easier to maintain than python dicts/lists/etc, and with a strictly validated schema you can trigger failures caused by accidental insertion of invalid data at an earlier stage.
In How and why we teach non-engineers to use GitHub at Thread

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.