Skip to main content

libsyntaqlite for Python

libsyntaqlite is a fast, embeddable parser, formatter, and static analyzer for SQLite SQL. The syntaqlite package provides its Python API.

Docs · Playground · GitHub

pip install syntaqlite

The package requires Python 3.10 or later. Wheels are available for Linux (x86_64, aarch64), macOS (x86_64, arm64), and Windows (x86_64).

API

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, which supports IDE completion 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 analyze query.sql
syntaqlite --sqlite-cflag SQLITE_ENABLE_MATH_FUNCTIONS analyze query.sql

See the CLI reference for all commands and flags.

License

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

Metadata

Release files for syntaqlite 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for syntaqlite 0.12.0
File
syntaqlite-0.12.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
syntaqlite-0.12.0-py3-none-pyemscripten_2026_0_wasm32.whl Python 3 none PyEmscripten 2026.0+ WebAssembly Details
syntaqlite-0.12.0-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details
syntaqlite-0.12.0-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details
syntaqlite-0.12.0-py3-none-macosx_11_0_universal2.whl Python 3 none macOS 11.0+ universal2 (ARM64, x86-64) Details
syntaqlite-0.12.0-py3-none-macosx_10_13_universal2.whl Python 3 none macOS 10.13+ universal2 (ARM64, x86-64) Details

Total release size: 15.2 MB

Release files / syntaqlite-0.12.0-py3-none-win_amd64.whl

Download URL syntaqlite-0.12.0-py3-none-win_amd64.whl
Size 2.6 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
15dafecf098cc20d8f80d47dafc2875a0bf1ef289a51fd718afd6099e44d8223
BLAKE2b-256 checksum
How to use checksums
2c0dbeeed00f0881ad1db9edf0069f61d699400af09c07c42800f539afa9e401
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / syntaqlite-0.12.0-py3-none-pyemscripten_2026_0_wasm32.whl

Download URL syntaqlite-0.12.0-py3-none-pyemscripten_2026_0_wasm32.whl
Size 271.2 kB
Tags PyEmscripten 2026.0+ WebAssembly Python 3
SHA-256 checksum
How to use checksums
cec915629e8139cc01d82d209645409f17e44f7c7ff32d97f3aaaef812f2ce32
BLAKE2b-256 checksum
How to use checksums
a015f1ec42092eaeba7d2f25332499d7af3bd21139190d31930196ca04e158b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / syntaqlite-0.12.0-py3-none-manylinux_2_28_x86_64.whl

Download URL syntaqlite-0.12.0-py3-none-manylinux_2_28_x86_64.whl
Size 3.2 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
bc0e9fd1acfbdc6935761f62a90162cf68bfcc3be20d7a577a85f5979492fe42
BLAKE2b-256 checksum
How to use checksums
5942197ec4c19df9a3997e9a6f2ee5348f3bcee46bd25e902868a16ef70d6690
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / syntaqlite-0.12.0-py3-none-manylinux_2_28_aarch64.whl

Download URL syntaqlite-0.12.0-py3-none-manylinux_2_28_aarch64.whl
Size 3.2 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
62cb0f3cd9a714e47b7f10b509056b36d81c13ca2a912979821b7875536263d5
BLAKE2b-256 checksum
How to use checksums
78f7e8a725e2e9dbb6d4b4869f5e3e6dca5b0a957516a64d492c6c8b3fdbd5e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / syntaqlite-0.12.0-py3-none-macosx_11_0_universal2.whl

Download URL syntaqlite-0.12.0-py3-none-macosx_11_0_universal2.whl
Size 2.9 MB
Tags Python 3 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
beb66bf72c82866a91365f0d810cf0184563bd1a5d7a7977c6753175a42f449a
BLAKE2b-256 checksum
How to use checksums
777affc076f0770a76d683865dde0ecf5df4e36a56716cfd0e8d8770858628a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release files / syntaqlite-0.12.0-py3-none-macosx_10_13_universal2.whl

Download URL syntaqlite-0.12.0-py3-none-macosx_10_13_universal2.whl
Size 3.0 MB
Tags Python 3 macOS 10.13+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
fe4cdde8bc61355b90347400a300d7af2a6d842d901fd259929a61dfeb366d8f
BLAKE2b-256 checksum
How to use checksums
83a459873e78fdce8d9a2a7fb7e30ab2680bb92c27918fb6a3fe7f6b5be3313d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.

Transparency log

Release history Release notifications | RSS feed

0.13.0

6 release files

0.12.1

6 release files

This release

0.12.0 This release

6 release files

0.11.2

6 release files

0.11.1

6 release files

0.11.0

6 release files

0.10.2

6 release files

0.10.1

6 release files

0.10.0

6 release files

0.9.0

6 release files

0.8.0

6 release files

0.7.1

6 release files

0.7.0

6 release files

0.6.0

6 release files

0.5.10

5 release files

0.5.9

5 release files

0.5.8

5 release files

0.5.7

5 release files

0.5.6

5 release files

0.5.5

5 release files

0.5.4

5 release files

0.5.3

5 release files

0.5.2

5 release files

0.5.1

5 release files

0.4.2

30 release files

0.4.1

30 release files

0.4.0

30 release files

0.3.1

30 release files

0.2.9

21 release files

0.1.0

6 release files

0.0.36

6 release files

0.0.35

6 release files

0.0.34

6 release files

0.0.33

6 release files

0.0.31

6 release files

0.0.30

6 release files

0.0.29

6 release files

0.0.28

6 release files

0.0.27

6 release files

0.0.26

6 release files

0.0.25

6 release files

0.0.24

6 release files

0.0.23

6 release files

0.0.21

6 release files

0.0.19

6 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page