Skip to main content

SQLite SQL tools — parser, formatter, validator, and MCP server

Project description

syntaqlite

Parse, format, and validate SQLite SQL from Python using SQLite's own grammar and tokenizer. No approximations: if SQLite accepts it, syntaqlite parses it.

Docs · Playground · GitHub

pip install syntaqlite

Requires Python 3.10+. Wheels for Linux (x86_64, aarch64), macOS (x86_64, arm64), and Windows (x86_64).

Library

Everything goes through a Syntaqlite instance. Create one and reuse it across many calls:

import syntaqlite

with syntaqlite.Syntaqlite() as sq:
    print(sq.format_sql("select 1"))

Formatting

sql = "select u.id, u.name, p.title from users u join posts p on u.id = p.user_id where u.active = 1 and p.published = true order by p.created_at desc limit 10"
print(sq.format_sql(sql))
SELECT u.id, u.name, p.title
FROM users AS u
JOIN posts AS p ON u.id = p.user_id
WHERE
  u.active = 1
  AND p.published = true
ORDER BY
  p.created_at DESC
LIMIT 10;

Raises syntaqlite.FormatError on invalid input.

Parsing

sq.parse() returns a full AST as typed Python objects, one per statement:

stmts = sq.parse("SELECT 1 + 2 FROM foo")
stmt = stmts[0]  # SelectStmt

print(type(stmt).__name__)       # SelectStmt
print(stmt.columns[0].expr)      # BinaryExpr(...)
print(stmt.from_clause)          # TableRef(...)
print(stmt.where_clause)         # None

Every node type is a __slots__ class with typed attributes, so you get IDE autocomplete and isinstance checks:

from syntaqlite.nodes import SelectStmt, BinaryExpr

assert isinstance(stmt, SelectStmt)
assert isinstance(stmt.columns[0].expr, BinaryExpr)

Enum and flag fields are IntEnum/IntFlag from syntaqlite.enums:

from syntaqlite.enums import BinaryOp

expr = stmt.columns[0].expr
print(expr.op)  # BinaryOp.PLUS

For performance-sensitive code, use sq.parse_raw() to get plain dicts instead of typed objects.

Tokenizing

for tok in sq.tokenize("SELECT 1 + 2"):
    print(tok["text"], tok["category"])
SELECT keyword
  other
1 number
  other
+ operator
  other
2 number

Each token is a dict with text, offset, length, type, and category fields.

Analysis

Check SQL against a schema without touching a database. Catches unknown tables, columns, functions, CTE column mismatches, and more.

schema = syntaqlite.Schema(
    tables=[syntaqlite.Table("users", columns=["id", "name", "email"])],
)
result = sq.analyze("SELECT nme FROM users", schema)
for d in result.diagnostics:
    print(f"{d.severity}: {d.message}")
error: unknown column 'nme'

Switch output to get formatted diagnostics with source locations and suggestions:

print(sq.analyze(
    "SELECT nme FROM users", schema,
    output=syntaqlite.AnalysisOutput.TEXT,
))
error: unknown column 'nme'
 --> <input>:1:8
  |
1 | SELECT nme FROM users
  |        ^~~
  = help: did you mean 'name'?

Schema also accepts raw DDL:

schema = syntaqlite.Schema(ddl="CREATE TABLE orders (id INTEGER, total REAL);")
result = sq.analyze("SELECT * FROM orders", schema)

Column lineage

For query-bearing statements, the result includes column lineage:

schema = syntaqlite.Schema(
    tables=[syntaqlite.Table("users", columns=["id", "name", "email"])],
)
result = sq.analyze("SELECT id, name FROM users", schema)
for col in result.lineage.columns:
    print(f"{col.name} <- {col.origin}")
id <- users.id
name <- users.name

CLI

The pip package also bundles the syntaqlite binary:

syntaqlite fmt -e "select 1, 2, 3"
syntaqlite analyze query.sql
syntaqlite parse -e "SELECT * FROM users"

The CLI supports pinning to a specific SQLite version or enabling compile-time flags to match your target environment:

syntaqlite --sqlite-version 3.32.0 validate query.sql
syntaqlite --sqlite-cflag SQLITE_ENABLE_MATH_FUNCTIONS validate query.sql

See the CLI reference for all commands and flags.

License

Apache 2.0. SQLite components are public domain under the SQLite blessing.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

syntaqlite-0.6.0-py3-none-win_amd64.whl (2.6 MB view details)

Uploaded Python 3Windows x86-64

syntaqlite-0.6.0-py3-none-pyemscripten_2026_0_wasm32.whl (256.8 kB view details)

Uploaded PyEmscripten 2026.0 wasm32Python 3

syntaqlite-0.6.0-py3-none-manylinux_2_28_x86_64.whl (3.2 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

syntaqlite-0.6.0-py3-none-manylinux_2_28_aarch64.whl (3.1 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

syntaqlite-0.6.0-py3-none-macosx_11_0_universal2.whl (2.8 MB view details)

Uploaded Python 3macOS 11.0+ universal2 (ARM64, x86-64)

syntaqlite-0.6.0-py3-none-macosx_10_13_universal2.whl (3.0 MB view details)

Uploaded Python 3macOS 10.13+ universal2 (ARM64, x86-64)

File details

Details for the file syntaqlite-0.6.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: syntaqlite-0.6.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for syntaqlite-0.6.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 36127e95cd24ef75a0b85e6bf9c008aa27675ef0aa929ce26a43fc898f292506
MD5 aa7ec00006c019c79e5cabdd63dbe819
BLAKE2b-256 2b472b2d5dbc50cd6d2c266c3870a191a625771dfe08b33ddd7eae0d34361bf8

See more details on using hashes here.

Provenance

The following attestation bundles were made for syntaqlite-0.6.0-py3-none-win_amd64.whl:

Publisher: release.yml on LalitMaganti/syntaqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file syntaqlite-0.6.0-py3-none-pyemscripten_2026_0_wasm32.whl.

File metadata

File hashes

Hashes for syntaqlite-0.6.0-py3-none-pyemscripten_2026_0_wasm32.whl
Algorithm Hash digest
SHA256 7b47e0633b828d314905e0a6fcdd0f46d5359c9cfcbc2c721e097d1acf0bb797
MD5 4bcabf740e397b93f1bf6aa0d2455a36
BLAKE2b-256 5962ee7974cbda71c482da732b701971566e3d829cb971eab53e93d798ddb708

See more details on using hashes here.

Provenance

The following attestation bundles were made for syntaqlite-0.6.0-py3-none-pyemscripten_2026_0_wasm32.whl:

Publisher: release.yml on LalitMaganti/syntaqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file syntaqlite-0.6.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for syntaqlite-0.6.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d1903f211a6107096f4d732a9b38c37f2a0038c542e6c3f6a236769ab1a05b5c
MD5 ab0bed54295c883e5944e3bd62fbd34a
BLAKE2b-256 26cbd79547180f988eb968d7648f66e0c99c5ee6e90d135cb8b665da019e5c93

See more details on using hashes here.

Provenance

The following attestation bundles were made for syntaqlite-0.6.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: release.yml on LalitMaganti/syntaqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file syntaqlite-0.6.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for syntaqlite-0.6.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 97ff39603869ad1a5199023d8913d29c95046acc1b1c47368b1b68df5b23a43a
MD5 de586049fab0fa833cd411e52d6b2397
BLAKE2b-256 fc0cf68de2468798d096b3725b643978a04e64163276f310810548ce9afb8d07

See more details on using hashes here.

Provenance

The following attestation bundles were made for syntaqlite-0.6.0-py3-none-manylinux_2_28_aarch64.whl:

Publisher: release.yml on LalitMaganti/syntaqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file syntaqlite-0.6.0-py3-none-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for syntaqlite-0.6.0-py3-none-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 07889af80a39ba5aa086713df02af6863141ce7edf081ee39061b8bea034b707
MD5 d91ee1ea6ebf6a5d0e6008e9aedb5745
BLAKE2b-256 b0520c9053907ab878729b7c52b42ec6a631acb30074c07deb1efc465e3b4f7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for syntaqlite-0.6.0-py3-none-macosx_11_0_universal2.whl:

Publisher: release.yml on LalitMaganti/syntaqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file syntaqlite-0.6.0-py3-none-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for syntaqlite-0.6.0-py3-none-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 da365ef07031ffe2d7b2712fee0badc3ff0d0abfd0c7ddb9904c755cc4a94cb5
MD5 9eff15746c02a9fcc806bc37dfb14f10
BLAKE2b-256 c96d9c442919e5bcbe4a4d8530712536681e68a4d9bb8107df1e72cf8abdc106

See more details on using hashes here.

Provenance

The following attestation bundles were made for syntaqlite-0.6.0-py3-none-macosx_10_13_universal2.whl:

Publisher: release.yml on LalitMaganti/syntaqlite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page