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"example.yaml", yaml_config):
    print(p.desc, p.line, p.rule)
class yamllint.linter.LintProblem(line, column, desc='<no description>', rule=None)

Represents a linting problem found by yamllint.

column = None

Column on which the problem was found (starting at 1)

desc = None

Human-readable description of the problem

line = None

Line on which the problem was found (starting at 1)

rule = None

Identifier of the rule that detected the problem, 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