{"id":452,"library":"sqlparse","title":"sqlparse: A Non-Validating SQL Parser for Python","description":"sqlparse is a non-validating SQL parser for Python, providing support for parsing, splitting, and formatting SQL statements. The current version is 0.5.5, released on March 28, 2026, with a release cadence of approximately every 6 months.","status":"active","version":"0.5.5","language":"python","source_language":"en","source_url":"https://github.com/andialbrecht/sqlparse","tags":["SQL","Parser","Python","Library"],"install":[{"cmd":"pip install sqlparse","lang":"bash","label":"Install sqlparse"}],"dependencies":[{"reason":"Requires Python 3.8 or higher","package":"python","optional":false}],"imports":[{"note":"Ensure the module is installed in your environment","symbol":"sqlparse","correct":"import sqlparse"}],"quickstart":{"code":"import sqlparse\n\n# Split a string containing two SQL statements:\nraw = 'SELECT * FROM foo; SELECT * FROM bar;'\nstatements = sqlparse.split(raw)\n\n# Format the first statement and print it out:\nfirst = statements[0]\nprint(sqlparse.format(first, reindent=True, keyword_case='upper'))\n\n# Parsing a SQL statement:\nparsed = sqlparse.parse('SELECT * FROM foo')[0]\nprint(parsed.tokens)","lang":"python","description":"A quickstart guide demonstrating how to split, format, and parse SQL statements using sqlparse."},"warnings":[{"fix":"Install sqlparse using pip: pip install sqlparse","message":"Ensure that sqlparse is installed in your environment to avoid ImportError.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.5.5':33 '2026':38 '28':37 '6':46 'approxim':44 'cadenc':42 'current':30 'everi':45 'format':26 'librari':51 'march':36 'month':47 'non':4,14 'non-valid':3,13 'pars':23 'parser':7,17,49 'provid':20 'python':9,19,50 'releas':34,41 'split':24 'sql':6,16,27,48 'sqlpars':1,10 'statement':28 'support':21 'valid':5,15 'version':31","created_at":"2026-03-28T12:03:12.123718+00:00","updated_at":"2026-04-16T22:16:46.024475+00:00","problems":[{"fix":"pip install sqlparse","cause":"The 'sqlparse' library has not been installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'sqlparse'"},{"fix":"Pass formatting options directly as keyword arguments, for example: `sqlparse.format(sql_string, reindent=True, keyword_case='upper')`.","cause":"The `sqlparse.format` function expects formatting options as direct keyword arguments, not as a dictionary passed via an 'options' parameter.","error":"TypeError: format() got an unexpected keyword argument 'options'"},{"fix":"Check if a token is a group using `token.is_group` before attempting to access its `tokens` attribute or iterating over it. For example:\n```python\nimport sqlparse\nsql = 'SELECT * FROM foo;'\nparsed = sqlparse.parse(sql)[0]\nfor token in parsed.tokens:\n    if token.is_group:\n        print(f\"Group: {token.normalized}\")\n        for subtoken in token.tokens:\n            print(f\"  Subtoken: {subtoken.normalized}\")\n    else:\n        print(f\"Token: {token.normalized}\")\n```","cause":"When iterating through the tokens of a parsed SQL statement, not all tokens are `TokenList` (group) objects; simple `Token` objects do not have a `tokens` attribute.","error":"AttributeError: 'Token' object has no attribute 'tokens'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"0.6.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/andialbrecht/sqlparse","docs":"https://sqlparse.readthedocs.io/","changelog":"https://sqlparse.readthedocs.io/en/latest/changes.html","pypi":"https://pypi.org/project/sqlparse/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-08-27","next_check":"2026-07-29","install_tag":"verified"}}