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 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;

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.name)  # 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}")
warning: 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,
    render_options=syntaqlite.RenderOptions(source_name="query.sql"),
))
warning: unknown column 'nme'
 --> query.sql: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.14.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.14.0
File Actions
syntaqlite-0.14.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for syntaqlite-0.14.0-py3-none-win_amd64.whl
syntaqlite-0.14.0-py3-none-pyemscripten_2026_0_wasm32.whl Python 3 none PyEmscripten 2026.0+ WebAssembly Details for syntaqlite-0.14.0-py3-none-pyemscripten_2026_0_wasm32.whl
syntaqlite-0.14.0-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for syntaqlite-0.14.0-py3-none-manylinux_2_28_x86_64.whl
syntaqlite-0.14.0-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details for syntaqlite-0.14.0-py3-none-manylinux_2_28_aarch64.whl
syntaqlite-0.14.0-py3-none-macosx_11_0_universal2.whl Python 3 none macOS 11.0+ universal2 (ARM64, x86-64) Details for syntaqlite-0.14.0-py3-none-macosx_11_0_universal2.whl
syntaqlite-0.14.0-py3-none-macosx_10_13_universal2.whl Python 3 none macOS 10.13+ universal2 (ARM64, x86-64) Details for syntaqlite-0.14.0-py3-none-macosx_10_13_universal2.whl

Total release size: 16.1 MB

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

Download URL syntaqlite-0.14.0-py3-none-win_amd64.whl
Size 2.8 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
b35110bc0b4710d5296b53e7cac66e050d0ca93841539d7f43f3f83b82e4be2c
BLAKE2b-256 checksum
How to use checksums
730692bf9da350340129a54d5c6de75fcf993a74db12c36b848287ae44a6d958
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 5, 2026.

Transparency log

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

Download URL syntaqlite-0.14.0-py3-none-pyemscripten_2026_0_wasm32.whl
Size 313.2 kB
Tags PyEmscripten 2026.0+ WebAssembly Python 3
SHA-256 checksum
How to use checksums
6d82e2289b77f030cd29442308f26b95a95e336c2bbfe034556a538cdcd806ef
BLAKE2b-256 checksum
How to use checksums
fec8c316aa773ca755acd241229d103bd14dfef8d2678cf0a37ca94f6db5ba3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 5, 2026.

Transparency log

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

Download URL syntaqlite-0.14.0-py3-none-manylinux_2_28_x86_64.whl
Size 3.4 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
a5c21484346d23f1bf954138cf27fc5801e4e62ea647b9501cc5088ccf6ea80e
BLAKE2b-256 checksum
How to use checksums
9325d35830df74c3ac9f7e534fd9d8885a47f82d7657a6424dd42d128f1b9c13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 5, 2026.

Transparency log

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

Download URL syntaqlite-0.14.0-py3-none-manylinux_2_28_aarch64.whl
Size 3.3 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
26c95d10324be41a5c539ccfce8b9d639c9f524a8f889f6e3c35b1c70841d13c
BLAKE2b-256 checksum
How to use checksums
e0d0a0d4cb7b984510955163658bc0a2fd27426b9d360d8bc6c643e33b385cf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 5, 2026.

Transparency log

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

Download URL syntaqlite-0.14.0-py3-none-macosx_11_0_universal2.whl
Size 3.1 MB
Tags Python 3 macOS 11.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
75eaa3b49d4dd42b6ec4a80db433e4590ce4993c416394788515b7e05df0de87
BLAKE2b-256 checksum
How to use checksums
4726c23f5e2a2fad9552f60fa948c3f8750b985838d4d50ffcf889d46b9615d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 5, 2026.

Transparency log

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

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

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 Nov 5, 2026.

Transparency log

Security for syntaqlite 0.14.0

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.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for syntaqlite-0.14.0-py3-none-win_amd64.whl

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 Nov 5, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.14.0 This release

6 release files Full provenance

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