yamllint provides both a script and a Python module. The latter can be used to write your own linting tools.
Basic example of running the linter from Python:
import yamllint yaml_config = yamllint.config.YamlLintConfig("extends: default") for p in yamllint.linter.run("example.yaml", yaml_config): print(p.desc, p.line, p.rule)
LintProblem(line, column, desc='<no description>', rule=None)¶
Represents a linting problem found by yamllint.
Column on which the problem was found (starting at 1)
Human-readable description of the problem
Line on which the problem was found (starting at 1)
Identifier of the rule that detected the problem
run(input, conf, filepath=None)¶
Lints a YAML source.
Returns a generator of LintProblem objects.
- input – buffer, string or stream to read from
- conf – yamllint configuration object