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
sqlstrThe SQL to be fixed.
dialectstr | NoneNoneA reference to the dialect of the SQL to be fixed. Defaults to ansi.
ruleslist[str] | NoneNoneA subset of rule references to fix for. Defaults to None.
exclude_ruleslist[str] | NoneNoneA subset of rule references to avoid fixing for. Defaults to None.
configFluffConfig | NoneNoneA configuration object to use for the operation. Defaults to None.
config_pathstr | NoneNoneA path to a .sqlfluff config, which is only used if a config is not already provided. Defaults to None.
fix_even_unparsablebool | NoneNoneOptional override for the corresponding SQLFluff configuration value.

Returns:

strstr for the fixed SQL if possible.

get_simple_config

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

Get a config object from simple API arguments.

Parameters:

ParameterTypeDefaultDescription
dialectstr | NoneNone
ruleslist[str] | NoneNone
exclude_ruleslist[str] | NoneNone
config_pathstr | NoneNone

Returns:

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
sqlstrThe SQL to be linted.
dialectstr | NoneNoneA reference to the dialect of the SQL to be linted. Defaults to ansi.
ruleslist[str] | NoneNoneA list of rule references to lint for. Defaults to None.
exclude_ruleslist[str] | NoneNoneA list of rule references to avoid linting for. Defaults to None.
configFluffConfig | NoneNoneA configuration object to use for the operation. Defaults to None.
config_pathstr | NoneNoneA path to a .sqlfluff config, which is only used if a config is not already provided. Defaults to 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
sqlstrThe SQL to be parsed.
dialectstr | NoneNoneA reference to the dialect of the SQL to be parsed. Defaults to ansi.
configFluffConfig | NoneNoneA configuration object to use for the operation. Defaults to None.
config_pathstr | NoneNoneA path to a .sqlfluff config, which is only used if a config is not already provided. Defaults to 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.