{"id":13510678,"url":"https://github.com/crdoconnor/strictyaml","last_synced_at":"2025-05-14T04:09:17.876Z","repository":{"id":37706390,"uuid":"61367476","full_name":"crdoconnor/strictyaml","owner":"crdoconnor","description":"Type-safe YAML parser and validator.","archived":false,"fork":false,"pushed_at":"2024-03-13T10:53:10.000Z","size":1146,"stargazers_count":1531,"open_issues_count":96,"forks_count":61,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-05-10T04:47:05.711Z","etag":null,"topics":["config","configuration","configuration-file","configuration-management","parser","python","python3","roundtrip","roundtripping","schema","serialization","strict","strict-types","strongly-typed","typesafe","validation","yaml","yaml-emitter","yaml-parser","yml"],"latest_commit_sha":null,"homepage":"https://hitchdev.com/strictyaml/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crdoconnor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-17T10:56:18.000Z","updated_at":"2025-05-08T08:08:37.000Z","dependencies_parsed_at":"2022-07-08T01:31:02.122Z","dependency_job_id":"7249b382-a07d-4ea8-ae5e-46e2062a9fe1","html_url":"https://github.com/crdoconnor/strictyaml","commit_stats":{"total_commits":781,"total_committers":21,"mean_commits":37.19047619047619,"dds":0.0653008962868118,"last_synced_commit":"dfd93f9740ebd5e7150029bc3d89ea102bcddf00"},"previous_names":[],"tags_count":77,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crdoconnor%2Fstrictyaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crdoconnor%2Fstrictyaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crdoconnor%2Fstrictyaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crdoconnor%2Fstrictyaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crdoconnor","download_url":"https://codeload.github.com/crdoconnor/strictyaml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254070089,"owners_count":22009559,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config","configuration","configuration-file","configuration-management","parser","python","python3","roundtrip","roundtripping","schema","serialization","strict","strict-types","strongly-typed","typesafe","validation","yaml","yaml-emitter","yaml-parser","yml"],"created_at":"2024-08-01T02:01:49.437Z","updated_at":"2025-05-14T04:09:12.857Z","avatar_url":"https://github.com/crdoconnor.png","language":"Python","funding_links":[],"categories":["Python","Libraries in Python","Data Format \u0026 I/O","yaml","Alternatives","Data validation"],"sub_categories":["For Python","YAML is a **supserset of JSON**"],"readme":"# StrictYAML\n\nStrictYAML is a [type-safe](https://en.wikipedia.org/wiki/Type_safety) YAML parser\nthat parses and validates a [restricted subset](https://hitchdev.com/strictyaml/features-removed) of the [YAML](https://hitchdev.com/strictyaml/what-is-yaml)\nspecification.\n\nPriorities:\n\n- Beautiful API\n- Refusing to parse [the ugly, hard to read and insecure features of YAML](https://hitchdev.com/strictyaml/features-removed) like [the Norway problem](https://hitchdev.com/strictyaml/why/implicit-typing-removed).\n- Strict validation of markup and straightforward type casting.\n- Clear, readable exceptions with **code snippets** and **line numbers**.\n- Acting as a near-drop in replacement for pyyaml, ruamel.yaml or poyo.\n- Ability to read in YAML, make changes and write it out again with comments preserved.\n- [Not speed](https://hitchdev.com/strictyaml/why/speed-not-a-priority), currently.\n\n\nSimple example:\n\n```yaml\n# All about the character\nname: Ford Prefect\nage: 42\npossessions:\n- Towel\n\n```\n\n\n```python\nfrom strictyaml import load, Map, Str, Int, Seq, YAMLError\n\n```\n\n\n\n\n\nDefault parse result:\n\n\n```python\n\u003e\u003e\u003e load(yaml_snippet)\nYAML({'name': 'Ford Prefect', 'age': '42', 'possessions': ['Towel']})\n```\n\n\n\nAll data is string, list or OrderedDict:\n\n\n```python\n\u003e\u003e\u003e load(yaml_snippet).data\n{'name': 'Ford Prefect', 'age': '42', 'possessions': ['Towel']}\n```\n\n\n\nQuickstart with schema:\n\n\n```python\nfrom strictyaml import load, Map, Str, Int, Seq, YAMLError\n\nschema = Map({\"name\": Str(), \"age\": Int(), \"possessions\": Seq(Str())})\n\n```\n\n\n\n\n\n42 is now parsed as an integer:\n\n\n```python\n\u003e\u003e\u003e person = load(yaml_snippet, schema)\n\u003e\u003e\u003e person.data\n{'name': 'Ford Prefect', 'age': 42, 'possessions': ['Towel']}\n```\n\n\n\nA YAMLError will be raised if there are syntactic problems, violations of your schema or use of disallowed YAML features:\n\n```yaml\n# All about the character\nname: Ford Prefect\nage: 42\n\n```\n\n\n\n\n\n\nFor example, a schema violation:\n\n\n```python\ntry:\n    person = load(yaml_snippet, schema)\nexcept YAMLError as error:\n    print(error)\n\n```\n\n```yaml\nwhile parsing a mapping\n  in \"\u003cunicode string\u003e\", line 1, column 1:\n    # All about the character\n     ^ (line: 1)\nrequired key(s) 'possessions' not found\n  in \"\u003cunicode string\u003e\", line 3, column 1:\n    age: '42'\n    ^ (line: 3)\n```\n\n\n\n\n\nIf parsed correctly:\n\n\n```python\nfrom strictyaml import load, Map, Str, Int, Seq, YAMLError, as_document\n\nschema = Map({\"name\": Str(), \"age\": Int(), \"possessions\": Seq(Str())})\n\n```\n\n\n\n\n\nYou can modify values and write out the YAML with comments preserved:\n\n\n```python\nperson = load(yaml_snippet, schema)\nperson['age'] = 43\nprint(person.as_yaml())\n\n```\n\n```yaml\n# All about the character\nname: Ford Prefect\nage: 43\npossessions:\n- Towel\n```\n\n\n\n\n\nAs well as look up line numbers:\n\n\n```python\n\u003e\u003e\u003e person = load(yaml_snippet, schema)\n\u003e\u003e\u003e person['possessions'][0].start_line\n5\n```\n\n\n\nAnd construct YAML documents from dicts or lists:\n\n\n```python\nprint(as_document({\"x\": 1}).as_yaml())\n\n```\n\n```yaml\nx: 1\n```\n\n\n\n\n\n\n\n## Install\n\n```sh\n$ pip install strictyaml\n```\n\n\n## Why StrictYAML?\n\nThere are a number of formats and approaches that can achieve more or\nless the same purpose as StrictYAML. I've tried to make it the best one.\nBelow is a series of documented justifications:\n\n- [Why avoid using environment variables as configuration?](https://hitchdev.com/strictyaml/why-not/environment-variables-as-config)\n- [Why not use HJSON?](https://hitchdev.com/strictyaml/why-not/hjson)\n- [Why not HOCON?](https://hitchdev.com/strictyaml/why-not/hocon)\n- [Why not use INI files?](https://hitchdev.com/strictyaml/why-not/ini)\n- [Why not use JSON Schema for validation?](https://hitchdev.com/strictyaml/why-not/json-schema)\n- [Why not JSON for simple configuration files?](https://hitchdev.com/strictyaml/why-not/json)\n- [Why not JSON5?](https://hitchdev.com/strictyaml/why-not/json5)\n- [Why not use the YAML 1.2 standard? - we don't need a new standard!](https://hitchdev.com/strictyaml/why-not/ordinary-yaml)\n- [Why not use kwalify with standard YAML to validate my YAML?](https://hitchdev.com/strictyaml/why-not/pykwalify)\n- [Why not use Python's schema library (or similar) for validation?](https://hitchdev.com/strictyaml/why-not/python-schema)\n- [Why not use SDLang?](https://hitchdev.com/strictyaml/why-not/sdlang)\n- [What is wrong with TOML?](https://hitchdev.com/strictyaml/why-not/toml)\n- [Why shouldn't I just use Python code for configuration?](https://hitchdev.com/strictyaml/why-not/turing-complete-code)\n- [Why not use XML for configuration or DSLs?](https://hitchdev.com/strictyaml/why-not/xml)\n\n\n\n## Using StrictYAML\n\nHow to:\n\n- [Build a YAML document from scratch in code](https://hitchdev.com/strictyaml/using/alpha/howto/build-yaml-document)\n- [Either/or schema validation of different, equally valid different kinds of YAML](https://hitchdev.com/strictyaml/using/alpha/howto/either-or-validation)\n- [Labeling exceptions](https://hitchdev.com/strictyaml/using/alpha/howto/label-exceptions)\n- [Merge YAML documents](https://hitchdev.com/strictyaml/using/alpha/howto/merge-yaml-documents)\n- [Revalidate an already validated document](https://hitchdev.com/strictyaml/using/alpha/howto/revalidation)\n- [Reading in YAML, editing it and writing it back out](https://hitchdev.com/strictyaml/using/alpha/howto/roundtripping)\n- [Get line numbers of YAML elements](https://hitchdev.com/strictyaml/using/alpha/howto/what-line)\n- [Parsing YAML without a schema](https://hitchdev.com/strictyaml/using/alpha/howto/without-a-schema)\n\n\nCompound validators:\n\n- [Fixed length sequences (FixedSeq)](https://hitchdev.com/strictyaml/using/alpha/compound/fixed-length-sequences)\n- [Mappings combining defined and undefined keys (MapCombined)](https://hitchdev.com/strictyaml/using/alpha/compound/map-combined)\n- [Mappings with arbitrary key names (MapPattern)](https://hitchdev.com/strictyaml/using/alpha/compound/map-pattern)\n- [Mapping with defined keys and a custom key validator (Map)](https://hitchdev.com/strictyaml/using/alpha/compound/mapping-with-slug-keys)\n- [Using a YAML object of a parsed mapping](https://hitchdev.com/strictyaml/using/alpha/compound/mapping-yaml-object)\n- [Mappings with defined keys (Map)](https://hitchdev.com/strictyaml/using/alpha/compound/mapping)\n- [Optional keys with defaults (Map/Optional)](https://hitchdev.com/strictyaml/using/alpha/compound/optional-keys-with-defaults)\n- [Validating optional keys in mappings (Map)](https://hitchdev.com/strictyaml/using/alpha/compound/optional-keys)\n- [Sequences of unique items (UniqueSeq)](https://hitchdev.com/strictyaml/using/alpha/compound/sequences-of-unique-items)\n- [Sequence/list validator (Seq)](https://hitchdev.com/strictyaml/using/alpha/compound/sequences)\n- [Updating document with a schema](https://hitchdev.com/strictyaml/using/alpha/compound/update)\n\n\nScalar validators:\n\n- [Boolean (Bool)](https://hitchdev.com/strictyaml/using/alpha/scalar/boolean)\n- [Parsing comma separated items (CommaSeparated)](https://hitchdev.com/strictyaml/using/alpha/scalar/comma-separated)\n- [Datetimes (Datetime)](https://hitchdev.com/strictyaml/using/alpha/scalar/datetime)\n- [Decimal numbers (Decimal)](https://hitchdev.com/strictyaml/using/alpha/scalar/decimal)\n- [Email and URL validators](https://hitchdev.com/strictyaml/using/alpha/scalar/email-and-url)\n- [Empty key validation](https://hitchdev.com/strictyaml/using/alpha/scalar/empty)\n- [Enumerated scalars (Enum)](https://hitchdev.com/strictyaml/using/alpha/scalar/enum)\n- [Floating point numbers (Float)](https://hitchdev.com/strictyaml/using/alpha/scalar/float)\n- [Hexadecimal Integers (HexInt)](https://hitchdev.com/strictyaml/using/alpha/scalar/hexadecimal-integer)\n- [Integers (Int)](https://hitchdev.com/strictyaml/using/alpha/scalar/integer)\n- [Validating strings with regexes (Regex)](https://hitchdev.com/strictyaml/using/alpha/scalar/regular-expressions)\n- [Parsing strings (Str)](https://hitchdev.com/strictyaml/using/alpha/scalar/string)\n\n\nRestrictions:\n\n- [Disallowed YAML](https://hitchdev.com/strictyaml/using/alpha/restrictions/disallowed-yaml)\n- [Duplicate keys](https://hitchdev.com/strictyaml/using/alpha/restrictions/duplicate-keys)\n- [Dirty load](https://hitchdev.com/strictyaml/using/alpha/restrictions/loading-dirty-yaml)\n\n\n\n## Design justifications\n\nThere are some design decisions in StrictYAML which are controversial\nand/or not obvious. Those are documented here:\n\n- [What is wrong with duplicate keys?](https://hitchdev.com/strictyaml/why/duplicate-keys-disallowed)\n- [What is wrong with explicit tags?](https://hitchdev.com/strictyaml/why/explicit-tags-removed)\n- [What is wrong with flow-style YAML?](https://hitchdev.com/strictyaml/why/flow-style-removed)\n- [The Norway Problem - why StrictYAML refuses to do implicit typing and so should you](https://hitchdev.com/strictyaml/why/implicit-typing-removed)\n- [What is wrong with node anchors and references?](https://hitchdev.com/strictyaml/why/node-anchors-and-references-removed)\n- [Why does StrictYAML not parse direct representations of Python objects?](https://hitchdev.com/strictyaml/why/not-parse-direct-representations-of-python-objects)\n- [Why does StrictYAML only parse from strings and not files?](https://hitchdev.com/strictyaml/why/only-parse-strings-not-files)\n- [Why is parsing speed not a high priority for StrictYAML?](https://hitchdev.com/strictyaml/why/speed-not-a-priority)\n- [What is syntax typing?](https://hitchdev.com/strictyaml/why/syntax-typing-bad)\n- [Why does StrictYAML make you define a schema in Python - a Turing-complete language?](https://hitchdev.com/strictyaml/why/turing-complete-schema)\n\n\n\n## Star Contributors\n\n- @wwoods\n- @chrisburr\n- @jnichols0\n\n## Other Contributors\n\n- @eulores\n- @WaltWoods\n- @ChristopherGS\n- @gvx\n- @AlexandreDecan\n- @lots0logs\n- @tobbez\n- @jaredsampson\n- @BoboTIG\n\nStrictYAML also includes code from [ruamel.yaml](https://yaml.readthedocs.io/en/latest/), Copyright Anthon van der Neut.\n\n## Contributing\n\n- Before writing any code, please read the tutorial on [contributing to hitchdev libraries](https://hitchdev.com/approach/contributing-to-hitch-libraries/).\n- 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.\n- 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.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrdoconnor%2Fstrictyaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrdoconnor%2Fstrictyaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrdoconnor%2Fstrictyaml/lists"}