python-sqlparse v0.1.3 documentation

sqlparse – Parse SQL statements

The sqlparse module provides the following functions on module-level.

sqlparse.split(sql)

Split sql into single statements.

Returns a list of strings.

sqlparse.format(sql, **options)

Format sql according to options.

Available options are documented in Formatting of SQL Statements.

Returns the formatted SQL statement as string.

sqlparse.parse(sql)

Parse sql and return a list of statements.

sql is a single string containting one or more SQL statements.

Returns a tuple of Statement instances.

Formatting of SQL Statements

The format() function accepts the following keyword arguments.

keyword_case
Changes how keywords are formatted. Allowed values are “upper”, “lower” and “capitalize”.
identifier_case
Changes how identifiers are formatted. Allowed values are “upper”, “lower”, and “capitalize”.
strip_comments
If True comments are removed from the statements.
reindent
If True the indentations of the statements are changed.
indent_tabs
If True tabs instead of spaces are used for indentation.
indent_width
The width of the indentation, defaults to 2.
output_format
If given the output is additionally formatted to be used as a variable in a programming language. Allowed values are “python” and “php”.