Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

sqlite-ast

PyPI Tests Changelog License

Python library for parsing SQLite SELECT queries into an AST

Installation

Install this library using pip:

pip install sqlite-ast

Usage

The main entry point is parse(sql), which returns a nested Python dictionary:

from sqlite_ast import parse

ast = parse("select 1")
print(ast)
{'type': 'select', 'distinct': False, 'all': False, 'columns': [{'expr': {'type': 'integer', 'value': 1}, 'alias': None}], 'from': None, 'where': None, 'group_by': None, 'having': None, 'order_by': None, 'limit': None}

You can pretty-print that dictionary as JSON:

import json
from sqlite_ast import parse

ast = parse("select 1")
print(json.dumps(ast, indent=2))
{
  "type": "select",
  "distinct": false,
  "all": false,
  "columns": [
    {
      "expr": {
        "type": "integer",
        "value": 1
      },
      "alias": null
    }
  ],
  "from": null,
  "where": null,
  "group_by": null,
  "having": null,
  "order_by": null,
  "limit": null
}

If you want structured dataclass nodes instead of dictionaries, use parse_ast(sql):

from pprint import pprint
from sqlite_ast import parse_ast

node = parse_ast("select 1")
pprint(node)
Select(distinct=False,
       all=False,
       with_ctes=None,
       columns=[ResultColumn(expr=IntegerLiteral(value=1), alias=None)],
       from_clause=None,
       where=None,
       group_by=None,
       having=None,
       window_definitions=None,
       order_by=None,
       limit=None,
       offset=None,
       _has_limit=False,
       _compound_member=False)

Parse failures raise ParseError:

from pprint import pprint
from sqlite_ast import parse, ParseError

try:
    parse("select 1 union select")
except ParseError as e:
    print(e)
    print("\nPartial AST:")
    pprint(e.partial_ast)
Parse error at position 21: Unexpected token in expression: EOF ('')

Partial AST:
Select(distinct=False,
       all=False,
       with_ctes=None,
       columns=[ResultColumn(expr=IntegerLiteral(value=1), alias=None)],
       from_clause=None,
       where=None,
       group_by=None,
       having=None,
       window_definitions=None,
       order_by=None,
       limit=None,
       offset=None,
       _has_limit=False,
       _compound_member=True)

Development

To contribute to this library, first checkout the code. Then run the tests with uv:

cd sqlite-ast
uv run pytest

Release files for sqlite-ast 0.1a0

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

Source distribution (sdist)

Source distribution for sqlite-ast 0.1a0
File Size Uploaded
sqlite_ast-0.1a0.tar.gz 20.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlite-ast 0.1a0
File Interpreter ABI Platform
sqlite_ast-0.1a0-py3-none-any.whl Python 3 none any Details

Total release size: 41.3 kB

Release files / sqlite_ast-0.1a0.tar.gz

Download URL sqlite_ast-0.1a0.tar.gz
Size 20.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d7de663c956b7beec8381d1d896a7a4270235df233740c6584c4a65e35bc409b
BLAKE2b-256 checksum
How to use checksums
1a95c8b0eb07b2124e9f2589ae4519034a379fc001a4d175ae12757a2bb1172c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Jan 30, 2026.

Transparency log

Release files / sqlite_ast-0.1a0-py3-none-any.whl

Download URL sqlite_ast-0.1a0-py3-none-any.whl
Size 20.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32aefdec5e019125607a67364bf80f69c57b789ccbaba266d025fdfb45309325
BLAKE2b-256 checksum
How to use checksums
603d11dcaa1a02e02856612b01e29af3097d2fbf6d7eb91d5a214c22361d688b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Jan 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1a0 This release

2 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