This release is a pre-release and may not be stable for production use.
sqlite-ast
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
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqlite_ast-0.1a0.tar.gz | 20.7 kB | With provenance | Details for sqlite_ast-0.1a0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqlite_ast-0.1a0-py3-none-any.whl | Python 3 | none | any | Details for sqlite_ast-0.1a0-py3-none-any.whl |
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 logRelease 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 logSecurity for sqlite-ast 0.1a0
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
Both files in this release have been uploaded with provenance metadata.
Attestation for sqlite_ast-0.1a0.tar.gz
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 logA 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.