skillfed

tree-sitter-sql

Tree-sitter Grammar for SQL

tree-sitter-sql v0.3.11 2.2M downloads/30d#3,227 on PyPI243
Permissive license MIT Active released

What it is and what it does

tree-sitter-sql is a tree-sitter grammar module that enables parsing of SQL code into an abstract syntax tree. It provides a general, permissive SQL grammar designed to handle SQL syntax across multiple dialects, drawing from SQLite, PostgreSQL, and MariaDB references. The package is distributed as precompiled wheels for common platforms, reducing installation friction compared to building from source.

The grammar itself is maintained separately from the parser implementation; the package installs the compiled parser binary that tree-sitter tools can use to analyze SQL code. It's intended for developers building SQL analysis tools, linters, formatters, or any system that needs to programmatically understand SQL structure. The package requires Python 3.10+ and has no runtime dependencies beyond tree-sitter itself.

Use it for:

  • Build SQL linters or formatters that need to parse and understand SQL syntax structure.
  • Implement SQL code analysis tools that extract information about queries, tables, or columns.
  • Create IDE plugins or editor extensions that provide SQL syntax highlighting or error detection.
  • Develop database schema migration tools that parse and transform SQL DDL statements.
  • Analyze SQL query performance or security by examining the parsed syntax tree.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides a tree-sitter SQL grammar for parsing SQL code into an abstract syntax tree, enabling programmatic analysis and manipulation of SQL statements.

Yes, if you need to parse SQL code programmatically and are already using tree-sitter. The package is actively maintained, has no known vulnerabilities, and uses a permissive MIT license. Install friction is moderate due to the requirement for Python 3.10+ and the need to pair it with tree-sitter bindings, but prebuilt wheels are available for common platforms. Not worth installing if you don't need tree-sitter integration or are on Python versions below 3.10.

Install

tree-sitter-sql on PyPI

pip

pip install tree-sitter-sql

uv

uv add tree-sitter-sql

poetry

poetry add tree-sitter-sql

Installing tree-sitter-sql

Before you install

Medium install friction due to compiled wheels; prebuilt binaries available for common platforms (Linux x86_64/aarch64, macOS Intel/ARM, Windows x86_64/ARM) but requires Python 3.10+. Active maintenance with recent commits.

License in practice

MIT license is permissive; you can use, modify, and distribute this package freely with minimal restrictions, making it suitable for both open-source and commercial projects.

Quickstart

pip install tree-sitter-sql

import tree_sitter_sql
# Use with tree-sitter Python bindings to parse SQL

Requires Python 3.10 or later; tree-sitter Python bindings must be installed separately to actually parse SQL.

Verify before relying

  • Whether this package includes Python bindings or only provides the grammar for use with external tree-sitter tooling.
  • Whether the package works with all SQL dialects or has specific limitations beyond what the description references (SQLite, PostgreSQL, MariaDB).

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction medium — platform-specific wheel
Runtime dependencies none
Maintenance actively maintained — 317 days since the last release
Last repo commit
First released
Downloads 2,185,061/month — #3,227 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: tree_sitter_sql-0.3.11-cp310-abi3-macosx_10_9_x86_64.whl; tree_sitter_sql-0.3.11-cp310-abi3-macosx_11_0_arm64.whl; tree_sitter_sql-0.3.11-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; tree_sitter_sql-0.3.11-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; tree_sitter_sql-0.3.11-cp310-abi3-musllinux_1_2_aarch64.whl; tree_sitter_sql-0.3.11-cp310-abi3-musllinux_1_2_x86_64.whl; tree_sitter_sql-0.3.11-cp310-abi3-win_amd64.whl; tree_sitter_sql-0.3.11-cp310-abi3-win_arm64.whl

Keywords: incremental, parsing, tree-sitter, sql

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseTopic :: Software Development :: CompilersTopic :: Text Processing :: LinguisticTyping :: Typed

Tags

SQL parser tree-sitterparse SQL code ASTSQL syntax analysistree-sitter grammar SQLSQL code parsing libraryincremental SQL parsing
sql-parsingtree-sitterast-generation

More Linguistic packages