Skip to content

Simple API ​

The simple API provides high-level functions for linting, fixing, and parsing SQL strings.

Classes ​

APIParsingError ​

An exception which holds a set of violations.

Parameters:

ParameterTypeDefaultDescription
violationslist[SQLBaseError]—
argsAny—

Functions ​

fix ​

python
fix(
    sql,
    dialect=None,
    rules=None,
    exclude_rules=None,
    config=None,
    config_path=None,
    fix_even_unparsable=None
) → str

Fix a SQL string.

Parameters:

ParameterTypeDefaultDescription
sqlstr—The SQL to be fixed.
dialect`strNone`None
rules`list[str]None`None
exclude_rules`list[str]None`None
config`fluffconfig.FluffConfigNone`None
config_path`strNone`None
fix_even_unparsable`boolNone`None

Returns:

str — str for the fixed SQL if possible.

get_simple_config ​

python
get_simple_config(
    dialect=None,
    rules=None,
    exclude_rules=None,
    config_path=None
) → fluffconfig.FluffConfig

Get a config object from simple API arguments.

Parameters:

ParameterTypeDefaultDescription
dialect`strNone`None
rules`list[str]None`None
exclude_rules`list[str]None`None
config_path`strNone`None

Returns:

fluffconfig.FluffConfig — See return type above

lint ​

python
lint(
    sql,
    dialect=None,
    rules=None,
    exclude_rules=None,
    config=None,
    config_path=None
) → list[dict[str, Any]]

Lint a SQL string.

Parameters:

ParameterTypeDefaultDescription
sqlstr—The SQL to be linted.
dialect`strNone`None
rules`list[str]None`None
exclude_rules`list[str]None`None
config`fluffconfig.FluffConfigNone`None
config_path`strNone`None

Returns:

list[dict[str, Any]] — list[dict[str, Any]] for each violation found.

parse ​

python
parse(
    sql,
    dialect=None,
    config=None,
    config_path=None
) → dict[str, Any]

Parse a SQL string.

Parameters:

ParameterTypeDefaultDescription
sqlstr—The SQL to be parsed.
dialect`strNone`None
config`fluffconfig.FluffConfigNone`None
config_path`strNone`None

Returns:

dict[str, Any] — Dict[str, Any] JSON containing the parsed structure.

Note: In the case of multiple potential variants from the raw source file only the first variant is returned by the simple API. For access to the other variants, use the underlying main API directly.

Released under the MIT License.